示例#1
0
func TestPartialDeduplicateBlocks(t *testing.T) {
	storage_engine.Reset()

	a := storage_engine.File{"a.txt", make([]byte, 0)}
	b := storage_engine.File{"b.txt", make([]byte, 0)}
	temp := make([]byte, 0)
	for i := 0; i < storage_engine.BLOCKSIZE*5; i++ {
		temp = append(temp, byte(rand.Int()))
	}
	a.Data = temp
	for i := 0; i < storage_engine.BLOCKSIZE*5; i++ {
		temp = append(temp, byte(rand.Int()))
	}
	b.Data = temp
	fmt.Println(len(a.Data))
	fmt.Println(len(b.Data))

	storage_engine.Put(a)
	previous := storage_engine.NumBlocks()
	storage_engine.Put(b)

	if !sameFile(storage_engine.Get("a.txt"), a) {
		t.Errorf("TestPartialDeduplicateBlocks %v != %v", storage_engine.Get("a.txt"), a)
	}
	if !sameFile(storage_engine.Get("b.txt"), b) {
		t.Errorf("TestPartialDeduplicateBlocks %v != %v", storage_engine.Get("b.txt"), b)
	}
	if previous*2 != storage_engine.NumBlocks() {

		t.Errorf("TestPartialDeduplicateBlocks %v != %v", previous*2, storage_engine.NumBlocks())
	}

}
示例#2
0
func TestDeduplicateBlocks(t *testing.T) {
	storage_engine.Reset()
	a := storage_engine.File{"a.txt", make([]byte, 0)}
	b := storage_engine.File{"b.txt", make([]byte, 0)}

	for i := 0; i < 99999999; i++ {
		a.Data = append(a.Data, byte(i))
		b.Data = append(b.Data, byte(i))
	}

	storage_engine.Put(a)
	previous := storage_engine.NumBlocks()
	storage_engine.Put(b)

	if !sameFile(storage_engine.Get("a.txt"), a) {
		t.Errorf("TestDeduplicateBlocks %v != %v", storage_engine.Get("a.txt"), a)
	}
	if !sameFile(storage_engine.Get("b.txt"), b) {
		t.Errorf("TestDeduplicateBlocks %v != %v", storage_engine.Get("b.txt"), b)
	}
	if previous != storage_engine.NumBlocks() {
		t.Errorf("TestDeduplicateBlocks %v != %v", previous, storage_engine.NumBlocks())
	}

}
示例#3
0
func TestBasicPutAndGetSameFile(t *testing.T) {
	storage_engine.Reset()
	a := storage_engine.File{"myfile.txt", []byte{0, 1, 2, 3, 4, 5}}
	storage_engine.Put(a)
	if !sameFile(storage_engine.Get("myfile.txt"), a) {
		t.Errorf("TestBasicAddAndGetSameFile %v != %v", storage_engine.Get("myfile.txt"), a)
	}
}
示例#4
0
func TestLargePutAndGetSameFile(t *testing.T) {
	storage_engine.Reset()
	a := storage_engine.File{"myfile.txt", make([]byte, 0)}
	for i := 0; i < 99999999; i++ {
		a.Data = append(a.Data, byte(i))
	}
	storage_engine.Put(a)
	if !sameFile(storage_engine.Get("myfile.txt"), a) {
		t.Errorf("TestLargeAddAndGetSameFile %v != %v", storage_engine.Get("myfile.txt"), a)
	}
}