示例#1
0
func testGetBlock(block *proc.CatBlock, t *testing.T) {
	gbp := &proc.GetBlockParam{
		Block: block,
	}
	ds := pool.DataServer(0)
	bs := pool.DefaultClientPool.NewBlockClient(gbp.Block.Locations[0])
	var lease proc.CatLease
	ds.GetBlock(gbp, &lease)
	t.Logf("Get lease %s\n", lease.ID)
	c := make(chan []byte)
	go bs.GetBlock(c, lease.ID)
	for {
		b, ok := <-c
		if !ok {
			break
		}
		as("I am a test string\nI am the seond test string\n" == string(b), t)
	}
}
示例#2
0
func testSendBlock(block *proc.CatBlock, t *testing.T) {
	pbp := &proc.PrepareBlockParam{
		Block: block,
	}
	ds := pool.DataServer(0)
	bs := pool.DefaultClientPool.NewBlockClient(pbp.Block.Locations[0])
	var lease proc.CatLease
	ds.PrepareSendBlock(pbp, &lease)
	t.Logf("Get lease %s\n", lease.ID)

	c := make(chan []byte)
	go bs.SendBlock(c, lease.ID)
	go func() {
		c <- []byte("I am a test string\n")
		c <- []byte("I am the seond test string\n")
		close(c)
	}()
	sbp := &proc.SendingBlockParam{
		Lease: &lease,
	}
	var succ bool
	ds.SendingBlock(sbp, &succ)
	as(succ, t)
	t.Logf("sending end\n")

	id := pbp.Block.ID
	filename := getFilename(id)
	pathExists(filename)
	fi, err := os.Open(filename)
	ne(err, t)
	r := bufio.NewReader(fi)
	line, _, err := r.ReadLine()
	ne(err, t)
	as("I am a test string" == string(line), t)
	line, _, err = r.ReadLine()
	ne(err, t)
	as("I am the seond test string" == string(line), t)
	fi.Close()
}