コード例 #1
0
ファイル: upload_test.go プロジェクト: pombredanne/bar
func Test_Storage_Upload_FinishUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("finish-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/finish-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/finish-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/finish-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)

	toUpload := mans.GetChunkLinkSlice(missing)

	for _, v := range toUpload {
		r, err := os.Open(tree.BlobFilename(v.Name))
		assert.NoError(t, err)
		defer r.Close()

		buf := make([]byte, v.Size)
		_, err = r.ReadAt(buf, v.Offset)

		err = stor.UploadChunk(*uID, v.Chunk.ID, bytes.NewReader(buf))
		assert.NoError(t, err)
	}

	err = stor.FinishUploadSession(*uID)
	assert.NoError(t, err)
}
コード例 #2
0
ファイル: server.go プロジェクト: pombredanne/bar
func NewFixtureServer(name string) (res *FixtureServer, err error) {
	logx.SetLevel(logx.DEBUG)

	wd, _ := os.Getwd()
	rt := filepath.Join(wd, "testdata", name+"-srv")
	os.RemoveAll(rt)

	p := storage.NewBlockStorage(&storage.BlockStorageOptions{rt, 2, 32, 64})
	ports, err := GetOpenPorts(2)
	if err != nil {
		return
	}

	ctx := context.Background()
	info := &proto.ServerInfo{
		HTTPEndpoint: fmt.Sprintf("http://localhost:%d/v1", ports[0]),
		RPCEndpoints: []string{fmt.Sprintf("localhost:%d", ports[1])},
		ChunkSize:    1024 * 1024 * 2,
		PoolSize:     16,
		BufferSize:   1024 * 1024 * 8,
	}

	tServer := thrift.NewServer(ctx,
		&thrift.Options{info, fmt.Sprintf(":%d", ports[1])}, p)
	hServer := front.NewServer(ctx,
		&front.Options{info, fmt.Sprintf(":%d", ports[0]), ""}, p)

	res = &FixtureServer{
		server.NewCompositeServer(ctx, tServer, hServer),
		info,
		rt,
	}
	go res.Start()
	time.Sleep(time.Millisecond * 00)
	return
}
コード例 #3
0
ファイル: upload_test.go プロジェクト: pombredanne/bar
func Test_Storage_Upload_CreateUpload(t *testing.T) {
	logx.SetLevel(logx.DEBUG)

	tree := fixtures.NewTree("create-upload", "")
	defer tree.Squash()
	assert.NoError(t, tree.Populate())

	m, err := model.New(tree.CWD, false, proto.CHUNK_SIZE, 16)
	assert.NoError(t, err)

	os.RemoveAll("testdata/create-upload-storage")
	stor := storage.NewBlockStorage(&storage.BlockStorageOptions{
		"testdata/create-upload-storage", 2, 16, 32,
	})
	defer os.RemoveAll("testdata/create-upload-storage")

	names := lists.NewFileList().ListDir(tree.CWD)
	mans, err := m.FeedManifests(true, false, true, names...)

	uID, _ := uuid.NewV4()
	missing, err := stor.CreateUploadSession(*uID, mans.GetManifestSlice(), time.Hour)
	assert.NoError(t, err)
	assert.Len(t, missing, 4)
}