Exemplo n.º 1
0
func (s *TrashSuite) TestBuildTrashLists(c *C) {
	var sv0 = keep.ServerAddress{Host: "keep0.example.com", Port: 80}
	var sv1 = keep.ServerAddress{Host: "keep1.example.com", Port: 80}

	var block0 = blockdigest.MakeTestDigestWithSize(0xdeadbeef)
	var block1 = blockdigest.MakeTestDigestWithSize(0xfedbeef)

	var keepServerInfo = keep.ReadServers{
		KeepServerIndexToAddress: []keep.ServerAddress{sv0, sv1},
		BlockToServers: map[blockdigest.DigestWithSize][]keep.BlockServerInfo{
			block0: []keep.BlockServerInfo{
				keep.BlockServerInfo{0, 99},
				keep.BlockServerInfo{1, 101}},
			block1: []keep.BlockServerInfo{
				keep.BlockServerInfo{0, 99},
				keep.BlockServerInfo{1, 101}}}}

	// only block0 is in delete set
	var bs BlockSet = make(BlockSet)
	bs[block0] = struct{}{}

	// Test trash list where only sv0 is on writable list.
	c.Check(buildTrashListsInternal(
		map[string]struct{}{
			sv0.URL(): struct{}{}},
		&keepServerInfo,
		110,
		bs),
		DeepEquals,
		map[string]keep.TrashList{
			"http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}}})

	// Test trash list where both sv0 and sv1 are on writable list.
	c.Check(buildTrashListsInternal(
		map[string]struct{}{
			sv0.URL(): struct{}{},
			sv1.URL(): struct{}{}},
		&keepServerInfo,
		110,
		bs),
		DeepEquals,
		map[string]keep.TrashList{
			"http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}},
			"http://keep1.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 101}}})

	// Test trash list where only block on sv0 is expired
	c.Check(buildTrashListsInternal(
		map[string]struct{}{
			sv0.URL(): struct{}{},
			sv1.URL(): struct{}{}},
		&keepServerInfo,
		100,
		bs),
		DeepEquals,
		map[string]keep.TrashList{
			"http://keep0.example.com:80": keep.TrashList{keep.TrashRequest{"000000000000000000000000deadbeef", 99}}})

}
Exemplo n.º 2
0
// Verifies that
// blocks.ToCollectionIndexSet(rc.BlockToCollectionIndices) returns
// expectedCollections.
func VerifyToCollectionIndexSet(
	t *testing.T,
	blocks []int,
	blockToCollectionIndices map[int][]int,
	expectedCollections []int) {

	expected := CollectionIndexSetFromSlice(expectedCollections)

	rc := collection.ReadCollections{
		BlockToCollectionIndices: map[blockdigest.DigestWithSize][]int{},
	}
	for digest, indices := range blockToCollectionIndices {
		rc.BlockToCollectionIndices[blockdigest.MakeTestDigestWithSize(digest)] = indices
	}

	returned := make(CollectionIndexSet)
	BlockSetFromSlice(blocks).ToCollectionIndexSet(rc, &returned)

	if !reflect.DeepEqual(returned, expected) {
		t.Errorf("Expected %v.ToCollectionIndexSet(%v) to return \n %v \n but instead received \n %v",
			blocks,
			blockToCollectionIndices,
			expectedCollections,
			returned.ToSlice())
	}
}
Exemplo n.º 3
0
func BlockSetFromSlice(digests []int) (bs BlockSet) {
	bs = make(BlockSet)
	for _, digest := range digests {
		bs.Insert(blockdigest.MakeTestDigestWithSize(digest))
	}
	return
}
Exemplo n.º 4
0
// Takes a map from block digest to replication level and represents
// it in a keep.ReadServers structure.
func SpecifyReplication(digestToReplication map[int]int) (rs keep.ReadServers) {
	rs.BlockToServers = make(map[blockdigest.DigestWithSize][]keep.BlockServerInfo)
	for digest, replication := range digestToReplication {
		rs.BlockToServers[blockdigest.MakeTestDigestWithSize(digest)] =
			make([]keep.BlockServerInfo, replication)
	}
	return
}
Exemplo n.º 5
0
func (s *MySuite) TestSummarizeSimple(checker *C) {
	rc := MakeTestReadCollections([]TestCollectionSpec{TestCollectionSpec{
		ReplicationLevel: 5,
		Blocks:           []int{1, 2},
	}})

	rc.Summarize(nil)

	c := rc.UuidToCollection["col0"]

	blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
	blockDigest2 := blockdigest.MakeTestDigestWithSize(2)

	expected := ExpectedSummary{
		OwnerToCollectionSize:     map[string]int{c.OwnerUuid: c.TotalSize},
		BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{blockDigest1: 5, blockDigest2: 5},
		BlockToCollectionUuids:    map[blockdigest.DigestWithSize][]string{blockDigest1: []string{c.Uuid}, blockDigest2: []string{c.Uuid}},
	}

	CompareSummarizedReadCollections(checker, rc, expected)
}
Exemplo n.º 6
0
func (s *MySuite) TestSummarizeOverlapping(checker *C) {
	rc := MakeTestReadCollections([]TestCollectionSpec{
		TestCollectionSpec{
			ReplicationLevel: 5,
			Blocks:           []int{1, 2},
		},
		TestCollectionSpec{
			ReplicationLevel: 8,
			Blocks:           []int{2, 3},
		},
	})

	rc.Summarize(nil)

	c0 := rc.UuidToCollection["col0"]
	c1 := rc.UuidToCollection["col1"]

	blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
	blockDigest2 := blockdigest.MakeTestDigestWithSize(2)
	blockDigest3 := blockdigest.MakeTestDigestWithSize(3)

	expected := ExpectedSummary{
		OwnerToCollectionSize: map[string]int{
			c0.OwnerUuid: c0.TotalSize,
			c1.OwnerUuid: c1.TotalSize,
		},
		BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{
			blockDigest1: 5,
			blockDigest2: 8,
			blockDigest3: 8,
		},
		BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{
			blockDigest1: []string{c0.Uuid},
			blockDigest2: []string{c0.Uuid, c1.Uuid},
			blockDigest3: []string{c1.Uuid},
		},
	}

	CompareSummarizedReadCollections(checker, rc, expected)
}