-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08a5082
commit 2e45e47
Showing
5 changed files
with
36 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
package check | ||
|
||
import ( | ||
"github.com/golang/mock/gomock" | ||
"testing" | ||
) | ||
|
||
func Test_parseZkPartitions_WhenDataParsable_ReturnsParsedPartitions(t *testing.T) { | ||
dataBytes := []byte(`{"version":1,"partitions":{"12":[2,3,1],"8":[1,2,3],"19":[3,1,2],"23":[1,3,2],"4":[3,2,1],"15":[2,1,3],"11":[1,3,2],"9":[2,1,3],"22":[3,2,1],"26":[1,2,3],"13":[3,1,2],"24":[2,3,1],"16":[3,2,1],"5":[1,3,2],"10":[3,2,1],"21":[2,1,3],"6":[2,3,1],"1":[3,1,2],"17":[1,3,2],"25":[3,1,2],"14":[1,2,3],"0":[2,3,1],"20":[1,2,3],"27":[2,1,3],"2":[1,2,3],"18":[2,3,1],"7":[3,1,2],"29":[1,3,2],"3":[2,1,3],"28":[3,2,1]}}`) | ||
func Test_zkPartitions_WhenDataParsable_ReturnsParsedPartitions(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
partitions, err := parseZkPartitions(dataBytes, "/path") | ||
zkConn := NewMockZkConnection(ctrl) | ||
|
||
data := `{"version":1,"partitions":{"12":[2,3,1],"8":[1,2,3],"19":[3,1,2],"23":[1,3,2],"4":[3,2,1],"15":[2,1,3],"11":[1,3,2],"9":[2,1,3],"22":[3,2,1],"26":[1,2,3],"13":[3,1,2],"24":[2,3,1],"16":[3,2,1],"5":[1,3,2],"10":[3,2,1],"21":[2,1,3],"6":[2,3,1],"1":[3,1,2],"17":[1,3,2],"25":[3,1,2],"14":[1,2,3],"0":[2,3,1],"20":[1,2,3],"27":[2,1,3],"2":[1,2,3],"18":[2,3,1],"7":[3,1,2],"29":[1,3,2],"3":[2,1,3],"28":[3,2,1]}}` | ||
zkConn.mockGet("/brokers/topics/test-topic", data) | ||
|
||
topic := ZkTopic{Name: "test-topic"} | ||
err := zkPartitions(&topic, zkConn, "test-topic", "") | ||
|
||
if err != nil { | ||
t.Errorf("Parsing produced error: %s", err) | ||
} | ||
|
||
if len(partitions) != 30 { | ||
t.Errorf("Parsing produced %d partitions, expected 30", len(partitions)) | ||
if len(topic.Partitions) != 30 { | ||
t.Errorf("Parsing produced %d partitions, expected 30", len(topic.Partitions)) | ||
} | ||
|
||
for _, partition := range partitions { | ||
if len(partition.Replicas) != 3 { | ||
t.Errorf("Partition %d has %d replicas, expected 3", partition.ID, len(partition.Replicas)) | ||
for id, replicas := range topic.Partitions { | ||
if len(replicas) != 3 { | ||
t.Errorf("Partition %d has %d replicas, expected 3", id, len(replicas)) | ||
} | ||
} | ||
} |