Ejemplo n.º 1
0
func TestPutGet(t *testing.T) {
	hostport := "127.0.0.1:9090"

	srvDir := path.Join(util.GetTestPath(), "server")
	util.TryMkdir(srvDir)

	_, err := NewServer(hostport, srvDir)
	if err != nil {
		t.Fatal(err)
	}

	cli, err := NewClient(hostport)
	if err != nil {
		t.Fatal(err)
	}

	paths, err := util.GenRandFiles([]util.FileSpec{
		{5, 10 * util.MB},
	})
	if err != nil {
		t.Fatal(err)
	}

	log.Println(paths)
	for _, fname := range paths {
		err := cli.Put(fname, path.Join(util.GetTestPath(), fname))
		if err != nil {
			t.Fatal(err)
		}
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()

	if err := util.TryMkdir(*localdir); err != nil {
		fmt.Println("Error ensuring directory was created:", err)
		return
	}

	storage, err := remote.NewInMemoryStorage()
	if err != nil {
		fmt.Println("Error starting remote storage:", err)
		return
	}

	b := bytes.NewBufferString("hi there")
	if err := storage.Put("test", b); err != nil {
		fmt.Println("Error putting test file:", err)
		return
	}

	cli, err := local.New(*localdir, 10*GB, storage)
	if err != nil {
		fmt.Println("Error starting client:", err)
		return
	}

	events := []ui.EventInfo{
		{"get", 1},
		{"put", 1},
		{"delete", 1},
	}
	ui, err := ui.New(cli, events)
	if err != nil {
		fmt.Println("Error starting ui:", err)
		return
	}

	select {
	case err := <-ui.Fatal():
		fmt.Println("Unexpected UI shutdown:", err)
	case err := <-cli.Fatal():
		fmt.Println("Unexpected client shutdown:", err)
	}
}
Ejemplo n.º 3
0
func TestClient(t *testing.T) {
	srvHostport := "localhost:8000"

	dirs := []string{testClidir, testSrvdir}
	for _, d := range dirs {
		err := os.RemoveAll(d)
		if err != nil {
			t.Fatal(err)
		}

		err = util.TryMkdir(d)
		if err != nil {
			t.Fatal(err)
		}
	}

	writeStringFile := func(fpath, contents string) error {
		f, err := os.Create(fpath)
		if err != nil {
			return err
		}
		defer f.Close()

		n, err := f.Write([]byte(contents))
		if err != nil {
			return err
		}
		if n != len(contents) {
			return fmt.Errorf("didn't write complete string")
		}

		return nil
	}

	cmds := []interface{}{}

	cliFiles := []testFile{
		{"test1", "qpwoeifjqoreighln;nv;qh[g"},
	}
	for _, testf := range cliFiles {
		err := writeStringFile(
			path.Join(testClidir, testf.name),
			testf.contents,
		)
		if err != nil {
			t.Fatal(err)
		}

		cmds = append(cmds, common.PutMsg{testf.name})
	}

	srvFiles := []testFile{
		{"test2", "qpwoeifjwogvbndfa;sdfqh[g"},
	}
	for _, testf := range srvFiles {
		err := writeStringFile(
			path.Join(testSrvdir, testf.name),
			testf.contents,
		)
		if err != nil {
			t.Fatal(err)
		}

		cmds = append(cmds, common.GetMsg{testf.name})
	}

	_, err := server.New(srvHostport, testSrvdir)
	if err != nil {
		t.Fatal(err)
	}

	cli, err := client.New(srvHostport, testClidir)
	if err != nil {
		t.Fatal(err)
	}

	runCommands(t, cli, cmds)
}