Skip to content

Commit

Permalink
Fix config related stats for a default config (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpyfox authored Oct 6, 2023
1 parent 4eabe8b commit 260dd54
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 7 deletions.
14 changes: 7 additions & 7 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,13 @@ func (w *Writer) Stats() WriterStats {
Retries: stats.retries.snapshot(),
BatchSize: stats.batchSize.snapshot(),
BatchBytes: stats.batchSizeBytes.snapshot(),
MaxAttempts: int64(w.MaxAttempts),
WriteBackoffMin: w.WriteBackoffMin,
WriteBackoffMax: w.WriteBackoffMax,
MaxBatchSize: int64(w.BatchSize),
BatchTimeout: w.BatchTimeout,
ReadTimeout: w.ReadTimeout,
WriteTimeout: w.WriteTimeout,
MaxAttempts: int64(w.maxAttempts()),
WriteBackoffMin: w.writeBackoffMin(),
WriteBackoffMax: w.writeBackoffMax(),
MaxBatchSize: int64(w.batchSize()),
BatchTimeout: w.batchTimeout(),
ReadTimeout: w.readTimeout(),
WriteTimeout: w.writeTimeout(),
RequiredAcks: int64(w.RequiredAcks),
Async: w.Async,
Topic: w.Topic,
Expand Down
86 changes: 86 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ func TestWriter(t *testing.T) {
scenario: "test default configuration values",
function: testWriterDefaults,
},
{
scenario: "test default stats values",
function: testWriterDefaultStats,
},
{
scenario: "test stats values with override config",
function: testWriterOverrideConfigStats,
},
{
scenario: "test write message with writer data",
function: testWriteMessageWithWriterData,
Expand Down Expand Up @@ -944,6 +952,84 @@ func testWriterDefaults(t *testing.T) {
}
}

func testWriterDefaultStats(t *testing.T) {
w := &Writer{}
defer w.Close()

stats := w.Stats()

if stats.MaxAttempts == 0 {
t.Error("Incorrect default MaxAttempts value")
}

if stats.WriteBackoffMin == 0 {
t.Error("Incorrect default WriteBackoffMin value")
}

if stats.WriteBackoffMax == 0 {
t.Error("Incorrect default WriteBackoffMax value")
}

if stats.MaxBatchSize == 0 {
t.Error("Incorrect default MaxBatchSize value")
}

if stats.BatchTimeout == 0 {
t.Error("Incorrect default BatchTimeout value")
}

if stats.ReadTimeout == 0 {
t.Error("Incorrect default ReadTimeout value")
}

if stats.WriteTimeout == 0 {
t.Error("Incorrect default WriteTimeout value")
}
}

func testWriterOverrideConfigStats(t *testing.T) {
w := &Writer{
MaxAttempts: 6,
WriteBackoffMin: 2,
WriteBackoffMax: 4,
BatchSize: 1024,
BatchTimeout: 16,
ReadTimeout: 24,
WriteTimeout: 32,
}
defer w.Close()

stats := w.Stats()

if stats.MaxAttempts != 6 {
t.Error("Incorrect MaxAttempts value")
}

if stats.WriteBackoffMin != 2 {
t.Error("Incorrect WriteBackoffMin value")
}

if stats.WriteBackoffMax != 4 {
t.Error("Incorrect WriteBackoffMax value")
}

if stats.MaxBatchSize != 1024 {
t.Error("Incorrect MaxBatchSize value")
}

if stats.BatchTimeout != 16 {
t.Error("Incorrect BatchTimeout value")
}

if stats.ReadTimeout != 24 {
t.Error("Incorrect ReadTimeout value")
}

if stats.WriteTimeout != 32 {
t.Error("Incorrect WriteTimeout value")
}
}

type staticBalancer struct {
partition int
}
Expand Down

0 comments on commit 260dd54

Please sign in to comment.