Evan Huus 12 лет назад
Родитель
Сommit
9fc922b7ce
1 измененных файлов с 35 добавлено и 0 удалено
  1. 35 0
      kafka/partitioner_test.go

+ 35 - 0
kafka/partitioner_test.go

@@ -0,0 +1,35 @@
+package kafka
+
+import "testing"
+
+func TestRandomPartitioner(t *testing.T) {
+	partitioner := RandomPartitioner{}
+
+	choice := partitioner.Partition(nil, 1)
+	if choice != 0 {
+		t.Error("Returned non-zero partition when only one available.")
+	}
+
+	for i := 1; i < 50; i++ {
+		choice := partitioner.Partition(nil, 50)
+		if choice < 0 || choice >= 50 {
+			t.Fatal("Returned partition", choice, "outside of range.")
+		}
+	}
+}
+
+func TestRoundRobinPartitioner(t *testing.T) {
+	partitioner := RoundRobinPartitioner{}
+
+	choice := partitioner.Partition(nil, 1)
+	if choice != 0 {
+		t.Error("Returned non-zero partition when only one available.")
+	}
+
+	for i := 1; i < 50; i++ {
+		choice := partitioner.Partition(nil, 7)
+		if choice != i%7 {
+			t.Fatal("Returned partition", choice, "expecting", i%7)
+		}
+	}
+}