Esempio n. 1
0
func TestSimpleSummary(t *testing.T) {
	rc := collection.MakeTestReadCollections([]collection.TestCollectionSpec{
		collection.TestCollectionSpec{ReplicationLevel: 1, Blocks: []int{1, 2}},
	})
	rc.Summarize(nil)
	cIndex := rc.CollectionIndicesForTesting()

	keepInfo := SpecifyReplication(map[int]int{1: 1, 2: 1})

	expectedSummary := ReplicationSummary{
		CollectionBlocksNotInKeep:  BlockSet{},
		UnderReplicatedBlocks:      BlockSet{},
		OverReplicatedBlocks:       BlockSet{},
		CorrectlyReplicatedBlocks:  BlockSetFromSlice([]int{1, 2}),
		KeepBlocksNotInCollections: BlockSet{},

		CollectionsNotFullyInKeep:      CollectionIndexSet{},
		UnderReplicatedCollections:     CollectionIndexSet{},
		OverReplicatedCollections:      CollectionIndexSet{},
		CorrectlyReplicatedCollections: CollectionIndexSetFromSlice([]int{cIndex[0]}),
	}

	returnedSummary := SummarizeReplication(rc, keepInfo)

	if !reflect.DeepEqual(returnedSummary, expectedSummary) {
		t.Fatalf("Expected returnedSummary to look like %+v but instead it is %+v", expectedSummary, returnedSummary)
	}
}
Esempio n. 2
0
func TestMixedReplication(t *testing.T) {
	rc := collection.MakeTestReadCollections([]collection.TestCollectionSpec{
		collection.TestCollectionSpec{ReplicationLevel: 1, Blocks: []int{1, 2}},
		collection.TestCollectionSpec{ReplicationLevel: 1, Blocks: []int{3, 4}},
		collection.TestCollectionSpec{ReplicationLevel: 2, Blocks: []int{5, 6}},
	})
	rc.Summarize(nil)
	cIndex := rc.CollectionIndicesForTesting()

	keepInfo := SpecifyReplication(map[int]int{1: 1, 2: 1, 3: 1, 5: 1, 6: 3, 7: 2})

	expectedSummary := ReplicationSummary{
		CollectionBlocksNotInKeep:  BlockSetFromSlice([]int{4}),
		UnderReplicatedBlocks:      BlockSetFromSlice([]int{5}),
		OverReplicatedBlocks:       BlockSetFromSlice([]int{6}),
		CorrectlyReplicatedBlocks:  BlockSetFromSlice([]int{1, 2, 3}),
		KeepBlocksNotInCollections: BlockSetFromSlice([]int{7}),

		CollectionsNotFullyInKeep:      CollectionIndexSetFromSlice([]int{cIndex[1]}),
		UnderReplicatedCollections:     CollectionIndexSetFromSlice([]int{cIndex[2]}),
		OverReplicatedCollections:      CollectionIndexSetFromSlice([]int{cIndex[2]}),
		CorrectlyReplicatedCollections: CollectionIndexSetFromSlice([]int{cIndex[0]}),
	}

	returnedSummary := SummarizeReplication(rc, keepInfo)

	if !reflect.DeepEqual(returnedSummary, expectedSummary) {
		t.Fatalf("Expected returnedSummary to look like: \n%+v but instead it is: \n%+v. Index to UUID is %v. BlockToCollectionIndices is %v.", expectedSummary, returnedSummary, rc.CollectionIndexToUUID, rc.BlockToCollectionIndices)
	}
}