Skip to content

Commit 260dd54

Browse files
authored
Fix config related stats for a default config (#1202)
1 parent 4eabe8b commit 260dd54

File tree

2 files changed

+93
-7
lines changed

2 files changed

+93
-7
lines changed

writer.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,13 +891,13 @@ func (w *Writer) Stats() WriterStats {
891891
Retries: stats.retries.snapshot(),
892892
BatchSize: stats.batchSize.snapshot(),
893893
BatchBytes: stats.batchSizeBytes.snapshot(),
894-
MaxAttempts: int64(w.MaxAttempts),
895-
WriteBackoffMin: w.WriteBackoffMin,
896-
WriteBackoffMax: w.WriteBackoffMax,
897-
MaxBatchSize: int64(w.BatchSize),
898-
BatchTimeout: w.BatchTimeout,
899-
ReadTimeout: w.ReadTimeout,
900-
WriteTimeout: w.WriteTimeout,
894+
MaxAttempts: int64(w.maxAttempts()),
895+
WriteBackoffMin: w.writeBackoffMin(),
896+
WriteBackoffMax: w.writeBackoffMax(),
897+
MaxBatchSize: int64(w.batchSize()),
898+
BatchTimeout: w.batchTimeout(),
899+
ReadTimeout: w.readTimeout(),
900+
WriteTimeout: w.writeTimeout(),
901901
RequiredAcks: int64(w.RequiredAcks),
902902
Async: w.Async,
903903
Topic: w.Topic,

writer_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ func TestWriter(t *testing.T) {
179179
scenario: "test default configuration values",
180180
function: testWriterDefaults,
181181
},
182+
{
183+
scenario: "test default stats values",
184+
function: testWriterDefaultStats,
185+
},
186+
{
187+
scenario: "test stats values with override config",
188+
function: testWriterOverrideConfigStats,
189+
},
182190
{
183191
scenario: "test write message with writer data",
184192
function: testWriteMessageWithWriterData,
@@ -944,6 +952,84 @@ func testWriterDefaults(t *testing.T) {
944952
}
945953
}
946954

955+
func testWriterDefaultStats(t *testing.T) {
956+
w := &Writer{}
957+
defer w.Close()
958+
959+
stats := w.Stats()
960+
961+
if stats.MaxAttempts == 0 {
962+
t.Error("Incorrect default MaxAttempts value")
963+
}
964+
965+
if stats.WriteBackoffMin == 0 {
966+
t.Error("Incorrect default WriteBackoffMin value")
967+
}
968+
969+
if stats.WriteBackoffMax == 0 {
970+
t.Error("Incorrect default WriteBackoffMax value")
971+
}
972+
973+
if stats.MaxBatchSize == 0 {
974+
t.Error("Incorrect default MaxBatchSize value")
975+
}
976+
977+
if stats.BatchTimeout == 0 {
978+
t.Error("Incorrect default BatchTimeout value")
979+
}
980+
981+
if stats.ReadTimeout == 0 {
982+
t.Error("Incorrect default ReadTimeout value")
983+
}
984+
985+
if stats.WriteTimeout == 0 {
986+
t.Error("Incorrect default WriteTimeout value")
987+
}
988+
}
989+
990+
func testWriterOverrideConfigStats(t *testing.T) {
991+
w := &Writer{
992+
MaxAttempts: 6,
993+
WriteBackoffMin: 2,
994+
WriteBackoffMax: 4,
995+
BatchSize: 1024,
996+
BatchTimeout: 16,
997+
ReadTimeout: 24,
998+
WriteTimeout: 32,
999+
}
1000+
defer w.Close()
1001+
1002+
stats := w.Stats()
1003+
1004+
if stats.MaxAttempts != 6 {
1005+
t.Error("Incorrect MaxAttempts value")
1006+
}
1007+
1008+
if stats.WriteBackoffMin != 2 {
1009+
t.Error("Incorrect WriteBackoffMin value")
1010+
}
1011+
1012+
if stats.WriteBackoffMax != 4 {
1013+
t.Error("Incorrect WriteBackoffMax value")
1014+
}
1015+
1016+
if stats.MaxBatchSize != 1024 {
1017+
t.Error("Incorrect MaxBatchSize value")
1018+
}
1019+
1020+
if stats.BatchTimeout != 16 {
1021+
t.Error("Incorrect BatchTimeout value")
1022+
}
1023+
1024+
if stats.ReadTimeout != 24 {
1025+
t.Error("Incorrect ReadTimeout value")
1026+
}
1027+
1028+
if stats.WriteTimeout != 32 {
1029+
t.Error("Incorrect WriteTimeout value")
1030+
}
1031+
}
1032+
9471033
type staticBalancer struct {
9481034
partition int
9491035
}

0 commit comments

Comments
 (0)