예제 #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)
	}
}
예제 #5
0
파일: transport.go 프로젝트: himanshuo/tftp
//todo: can remove all the extra stuff built on top of UDPAddr to keep client and server TID's
func NewReadTransport(p packet.ReadPacket, clientAddr *net.UDPAddr) Transport {
	//returns a transport that sets init vals

	ServerAddr, err := net.ResolveUDPAddr("udp", ":0")
	CheckError(err)

	//I am allowing the Golang implementation of UDP to handle choosing a random port that is available
	//serverTid := Tid(ServerAddr.Port)

	/* Now listen at selected port */
	ServerConn, err := net.ListenUDP("udp", ServerAddr)
	CheckError(err)

	file, err := storage_engine.Get(p.FileName)
	if err != nil {
		SendErrorPacket(uint16(1), ServerConn, clientAddr)
	}
	fmt.Println("file to retrieve has bytes:", len(file.Data))
	return ReadTransport{
		AbstractTransport{
			file:       file,
			clientAddr: clientAddr,
			conn:       ServerConn,
			blocknum:   uint16(0),
		},
	}
}