Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzyildirim committed Nov 10, 2023
1 parent 49c2932 commit 0f422f7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 100,003 deletions.
22 changes: 22 additions & 0 deletions batch_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ func Test_batchConsumer_process(t *testing.T) {
})
}

func Test_batchConsumer_process_ReprocessingFailedWithRetryEnabled(t *testing.T) {
// Given
mc := &mockCronsumer{wantErr: true}
bc := batchConsumer{
base: &base{metric: &ConsumerMetric{}, logger: NewZapLogger(LogLevelDebug), retryEnabled: true, nonTransactionalBatchRetryEnabled: true, cronsumer: mc},
consumeFn: func(messages []*Message) error {
return errors.New("error case")
},
}

// When
bc.process([]*Message{{IsFailed: true}, {IsFailed: true}, {}})

// Then
if bc.metric.TotalProcessedMessagesCounter != 0 {
t.Fatalf("Total Processed Message Counter must equal to 0")
}
if bc.metric.TotalUnprocessedMessagesCounter != 3 {
t.Fatalf("Total Unprocessed Message Counter must equal to 3")
}
}

type mockCronsumer struct {
wantErr bool
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/with-kafka-batch-consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
}

// In order to load topic with data, use:
// kafka-console-producer --broker-list localhost:29092 --topic standart-topic < examples/with-kafka-batch-consumer/load.txt
// kafka-console-producer --broker-list localhost:29092 --topic standart-topic < examples/load.txt
func batchConsumeFn(messages []*kafka.Message) error {
fmt.Printf("%d\n comes first %s", len(messages), messages[0].Value)
return nil
Expand Down
Loading

0 comments on commit 0f422f7

Please sign in to comment.