示例#1
0
func uploadChunk(addr, dir, fileName string, ino, ckSz, off, size int64, dCh chan bool, eCh chan error) {
	buf := make([]byte, ckSz)
	f, err := os.Open(dir + "/" + fileName)
	if err != nil {
		fmt.Println("open error")
		dCh <- false
		eCh <- err
		return
	}

	readLen, err := f.ReadAt(buf, off)
	if err == io.EOF {
		buf = buf[:readLen]
	} else if err != nil {
		fmt.Println("ReadAt error")
		dCh <- false
		eCh <- err
		return
	}
	// fmt.Println("upload buf:", buf)

	var succ bool
	myclient := triblab.NewClient(addr)
	err = myclient.Set(&trib.KeyValue{Key: "__file_segment_" + strconv.FormatInt(ino, 10) + "_" + strconv.FormatInt(off, 10), Value: string(buf)}, &succ)
	if err != nil {
		fmt.Println("set error")
		dCh <- false
		eCh <- err
		return
	} else {
		dCh <- true
	}
}
示例#2
0
func main() {
	flag.Parse()
	args := flag.Args()
	if len(args) < 1 {
		fmt.Fprintln(os.Stderr, help)
		os.Exit(1)
	}

	addr := args[0]
	s := triblab.NewClient(addr)

	cmdArgs := args[1:]
	if len(cmdArgs) == 0 {
		runPrompt(s)
		fmt.Println()
	} else {
		runCmd(s, cmdArgs)
	}
}
示例#3
0
func TestRPC(t *testing.T) {
	addr := randaddr.Local()
	ready := make(chan bool)

	go func() {
		e := entries.ServeBackSingle(addr, store.NewStorage(), ready)
		if e != nil {
			t.Fatal(e)
		}
	}()

	r := <-ready
	if !r {
		t.Fatal("not ready")
	}

	c := triblab.NewClient(addr)

	tribtest.CheckStorage(t, c)
}