2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-08-01 21:25:06 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package segments
|
2018-08-07 16:52:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-12-11 16:05:14 +00:00
|
|
|
"fmt"
|
2018-08-07 16:52:11 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
2018-10-16 12:43:44 +01:00
|
|
|
"github.com/golang/protobuf/ptypes"
|
2018-08-07 16:52:11 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-11-26 18:21:44 +00:00
|
|
|
|
2018-11-29 18:39:27 +00:00
|
|
|
"storj.io/storj/internal/teststorj"
|
2018-08-07 16:52:11 +01:00
|
|
|
"storj.io/storj/pkg/eestream"
|
2019-01-02 18:47:34 +00:00
|
|
|
mock_eestream "storj.io/storj/pkg/eestream/mocks"
|
2018-08-07 16:52:11 +01:00
|
|
|
mock_overlay "storj.io/storj/pkg/overlay/mocks"
|
2019-01-02 18:47:34 +00:00
|
|
|
mock_pointerdb "storj.io/storj/pkg/pointerdb/pdbclient/mocks"
|
|
|
|
mock_ecclient "storj.io/storj/pkg/storage/ec/mocks"
|
|
|
|
|
2018-09-18 05:39:06 +01:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-08-22 16:07:00 +01:00
|
|
|
pdb "storj.io/storj/pkg/pointerdb/pdbclient"
|
2018-10-25 21:28:16 +01:00
|
|
|
"storj.io/storj/pkg/storage/meta"
|
|
|
|
"storj.io/storj/pkg/storj"
|
2018-08-07 16:52:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewSegmentStore(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mock_eestream.NewMockErasureScheme(ctrl),
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := NewSegmentStore(mockOC, mockEC, mockPDB, rs, 10)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreMeta(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mock_eestream.NewMockErasureScheme(ctrl),
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, 10}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
var mExp time.Time
|
|
|
|
pExp, err := ptypes.TimestampProto(mExp)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
2018-09-18 05:39:06 +01:00
|
|
|
returnPointer *pb.Pointer
|
2018-08-07 16:52:11 +01:00
|
|
|
returnMeta Meta
|
|
|
|
}{
|
2018-09-18 05:39:06 +01:00
|
|
|
{"path/1/2/3", &pb.Pointer{CreationDate: pExp, ExpirationDate: pExp}, Meta{Modified: mExp, Expiration: mExp}},
|
2018-08-07 16:52:11 +01:00
|
|
|
} {
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
2018-11-26 18:21:44 +00:00
|
|
|
).Return(tt.returnPointer, nil, nil, nil),
|
2018-08-07 16:52:11 +01:00
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
m, err := ss.Meta(ctx, tt.pathInput)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, m, tt.returnMeta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStorePutRemote(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
name string
|
|
|
|
pathInput string
|
|
|
|
mdInput []byte
|
|
|
|
thresholdSize int
|
|
|
|
expiration time.Time
|
|
|
|
readerContent string
|
|
|
|
}{
|
|
|
|
{"test remote put", "path/1", []byte("abcdefghijklmnopqrstuvwxyz"), 2, time.Unix(0, 0).UTC(), "readerreaderreader"},
|
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
2018-12-11 17:30:14 +00:00
|
|
|
mockES.EXPECT().TotalCount().Return(1).AnyTimes(),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockOC.EXPECT().Choose(
|
2018-10-15 18:42:36 +01:00
|
|
|
gomock.Any(), gomock.Any(),
|
2018-09-18 05:39:06 +01:00
|
|
|
).Return([]*pb.Node{
|
2019-01-02 18:47:34 +00:00
|
|
|
{Id: teststorj.NodeIDFromString("im-a-node"),
|
|
|
|
Type: pb.NodeType_STORAGE,
|
|
|
|
},
|
2018-08-07 16:52:11 +01:00
|
|
|
}, nil),
|
2018-11-26 18:21:44 +00:00
|
|
|
mockPDB.EXPECT().PayerBandwidthAllocation(gomock.Any(), gomock.Any()),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockEC.EXPECT().Put(
|
2019-02-20 05:36:08 +00:00
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
|
2018-08-07 16:52:11 +01:00
|
|
|
),
|
|
|
|
mockES.EXPECT().RequiredCount().Return(1),
|
|
|
|
mockES.EXPECT().TotalCount().Return(1),
|
2018-09-27 12:52:18 +01:00
|
|
|
mockES.EXPECT().ErasureShareSize().Return(1),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockPDB.EXPECT().Put(
|
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(),
|
|
|
|
).Return(nil),
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
_, err := ss.Put(ctx, strings.NewReader(tt.readerContent), tt.expiration, func() (storj.Path, []byte, error) {
|
|
|
|
return tt.pathInput, tt.mdInput, nil
|
2018-10-03 14:05:40 +01:00
|
|
|
})
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err, tt.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStorePutInline(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
name string
|
|
|
|
pathInput string
|
|
|
|
mdInput []byte
|
|
|
|
thresholdSize int
|
|
|
|
expiration time.Time
|
|
|
|
readerContent string
|
|
|
|
}{
|
|
|
|
{"test inline put", "path/1", []byte("111"), 1000, time.Unix(0, 0).UTC(), "readerreaderreader"},
|
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Put(
|
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(),
|
|
|
|
).Return(nil),
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
_, err := ss.Put(ctx, strings.NewReader(tt.readerContent), tt.expiration, func() (storj.Path, []byte, error) {
|
|
|
|
return tt.pathInput, tt.mdInput, nil
|
2018-10-03 14:05:40 +01:00
|
|
|
})
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err, tt.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreGetInline(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
ti := time.Unix(0, 0).UTC()
|
2018-08-07 16:52:11 +01:00
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
|
|
|
thresholdSize int
|
2018-09-18 05:39:06 +01:00
|
|
|
pointerType pb.Pointer_DataType
|
2018-08-07 16:52:11 +01:00
|
|
|
inlineContent []byte
|
|
|
|
size int64
|
|
|
|
metadata []byte
|
|
|
|
}{
|
2018-09-18 05:39:06 +01:00
|
|
|
{"path/1/2/3", 10, pb.Pointer_INLINE, []byte("000"), int64(3), []byte("metadata")},
|
2018-08-07 16:52:11 +01:00
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
2018-09-18 05:39:06 +01:00
|
|
|
).Return(&pb.Pointer{
|
2018-08-07 16:52:11 +01:00
|
|
|
Type: tt.pointerType,
|
|
|
|
InlineSegment: tt.inlineContent,
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
2018-11-20 17:09:35 +00:00
|
|
|
SegmentSize: tt.size,
|
2018-08-07 16:52:11 +01:00
|
|
|
Metadata: tt.metadata,
|
2018-11-26 18:21:44 +00:00
|
|
|
}, nil, nil, nil),
|
2018-08-07 16:52:11 +01:00
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
_, _, err := ss.Get(ctx, tt.pathInput)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreGetRemote(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
ti := time.Unix(0, 0).UTC()
|
2018-08-07 16:52:11 +01:00
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
|
|
|
thresholdSize int
|
2018-09-18 05:39:06 +01:00
|
|
|
pointerType pb.Pointer_DataType
|
2018-08-07 16:52:11 +01:00
|
|
|
size int64
|
|
|
|
metadata []byte
|
|
|
|
}{
|
2018-09-18 05:39:06 +01:00
|
|
|
{"path/1/2/3", 10, pb.Pointer_REMOTE, int64(3), []byte("metadata")},
|
2018-08-07 16:52:11 +01:00
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
2018-09-18 05:39:06 +01:00
|
|
|
).Return(&pb.Pointer{
|
2018-08-07 16:52:11 +01:00
|
|
|
Type: tt.pointerType,
|
2018-09-18 05:39:06 +01:00
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
Type: pb.RedundancyScheme_RS,
|
2018-08-07 16:52:11 +01:00
|
|
|
MinReq: 1,
|
|
|
|
Total: 2,
|
|
|
|
RepairThreshold: 1,
|
|
|
|
SuccessThreshold: 2,
|
|
|
|
},
|
|
|
|
PieceId: "here's my piece id",
|
2018-09-18 05:39:06 +01:00
|
|
|
RemotePieces: []*pb.RemotePiece{},
|
2018-08-07 16:52:11 +01:00
|
|
|
},
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
2018-11-20 17:09:35 +00:00
|
|
|
SegmentSize: tt.size,
|
2018-08-07 16:52:11 +01:00
|
|
|
Metadata: tt.metadata,
|
2018-11-26 18:21:44 +00:00
|
|
|
}, nil, nil, nil),
|
2018-09-11 05:52:14 +01:00
|
|
|
mockOC.EXPECT().BulkLookup(gomock.Any(), gomock.Any()),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockEC.EXPECT().Get(
|
2019-02-20 05:36:08 +00:00
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
|
2018-08-07 16:52:11 +01:00
|
|
|
),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
_, _, err := ss.Get(ctx, tt.pathInput)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreDeleteInline(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
ti := time.Unix(0, 0).UTC()
|
2018-08-07 16:52:11 +01:00
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
|
|
|
thresholdSize int
|
2018-09-18 05:39:06 +01:00
|
|
|
pointerType pb.Pointer_DataType
|
2018-08-07 16:52:11 +01:00
|
|
|
inlineContent []byte
|
|
|
|
size int64
|
|
|
|
metadata []byte
|
|
|
|
}{
|
2018-09-18 05:39:06 +01:00
|
|
|
{"path/1/2/3", 10, pb.Pointer_INLINE, []byte("000"), int64(3), []byte("metadata")},
|
2018-08-07 16:52:11 +01:00
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
2018-09-18 05:39:06 +01:00
|
|
|
).Return(&pb.Pointer{
|
2018-08-07 16:52:11 +01:00
|
|
|
Type: tt.pointerType,
|
|
|
|
InlineSegment: tt.inlineContent,
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
2018-11-20 17:09:35 +00:00
|
|
|
SegmentSize: tt.size,
|
2018-08-07 16:52:11 +01:00
|
|
|
Metadata: tt.metadata,
|
2018-11-26 18:21:44 +00:00
|
|
|
}, nil, nil, nil),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockPDB.EXPECT().Delete(
|
|
|
|
gomock.Any(), gomock.Any(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
err := ss.Delete(ctx, tt.pathInput)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreDeleteRemote(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
ti := time.Unix(0, 0).UTC()
|
2018-08-07 16:52:11 +01:00
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
|
|
|
thresholdSize int
|
2018-09-18 05:39:06 +01:00
|
|
|
pointerType pb.Pointer_DataType
|
2018-08-07 16:52:11 +01:00
|
|
|
size int64
|
|
|
|
metadata []byte
|
|
|
|
}{
|
2018-09-18 05:39:06 +01:00
|
|
|
{"path/1/2/3", 10, pb.Pointer_REMOTE, int64(3), []byte("metadata")},
|
2018-08-07 16:52:11 +01:00
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
2018-09-18 05:39:06 +01:00
|
|
|
).Return(&pb.Pointer{
|
2018-08-07 16:52:11 +01:00
|
|
|
Type: tt.pointerType,
|
2018-09-18 05:39:06 +01:00
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
Type: pb.RedundancyScheme_RS,
|
2018-08-07 16:52:11 +01:00
|
|
|
MinReq: 1,
|
|
|
|
Total: 2,
|
|
|
|
RepairThreshold: 1,
|
|
|
|
SuccessThreshold: 2,
|
|
|
|
},
|
|
|
|
PieceId: "here's my piece id",
|
2018-09-18 05:39:06 +01:00
|
|
|
RemotePieces: []*pb.RemotePiece{},
|
2018-08-07 16:52:11 +01:00
|
|
|
},
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
2018-11-20 17:09:35 +00:00
|
|
|
SegmentSize: tt.size,
|
2018-08-07 16:52:11 +01:00
|
|
|
Metadata: tt.metadata,
|
2019-02-20 05:36:08 +00:00
|
|
|
}, nil, &pb.PayerBandwidthAllocation{}, nil),
|
2018-09-11 05:52:14 +01:00
|
|
|
mockOC.EXPECT().BulkLookup(gomock.Any(), gomock.Any()),
|
2018-08-07 16:52:11 +01:00
|
|
|
mockEC.EXPECT().Delete(
|
2018-10-17 12:40:11 +01:00
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
|
2018-08-07 16:52:11 +01:00
|
|
|
),
|
|
|
|
mockPDB.EXPECT().Delete(
|
|
|
|
gomock.Any(), gomock.Any(),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
err := ss.Delete(ctx, tt.pathInput)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreList(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
2018-10-25 21:28:16 +01:00
|
|
|
prefix string
|
|
|
|
startAfter string
|
|
|
|
thresholdSize int
|
|
|
|
itemPath string
|
|
|
|
inlineContent []byte
|
|
|
|
metadata []byte
|
2018-08-07 16:52:11 +01:00
|
|
|
}{
|
|
|
|
{"bucket1", "s0/path/1", 10, "s0/path/1", []byte("inline"), []byte("metadata")},
|
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
mockES := mock_eestream.NewMockErasureScheme(ctrl)
|
|
|
|
rs := eestream.RedundancyStrategy{
|
|
|
|
ErasureScheme: mockES,
|
|
|
|
}
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
|
2018-08-27 18:28:16 +01:00
|
|
|
ti := time.Unix(0, 0).UTC()
|
2018-08-07 16:52:11 +01:00
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().List(
|
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
|
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(),
|
|
|
|
).Return([]pdb.ListItem{
|
2018-08-27 18:28:16 +01:00
|
|
|
{
|
2018-10-25 21:28:16 +01:00
|
|
|
Path: tt.itemPath,
|
2018-09-18 05:39:06 +01:00
|
|
|
Pointer: &pb.Pointer{
|
|
|
|
Type: pb.Pointer_INLINE,
|
2018-08-07 16:52:11 +01:00
|
|
|
InlineSegment: tt.inlineContent,
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
2018-11-20 17:09:35 +00:00
|
|
|
SegmentSize: int64(4),
|
2018-08-07 16:52:11 +01:00
|
|
|
Metadata: tt.metadata,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, true, nil),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
2018-10-25 21:28:16 +01:00
|
|
|
_, _, err = ss.List(ctx, tt.prefix, tt.startAfter, "", false, 10, meta.Modified)
|
2018-08-07 16:52:11 +01:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
2018-12-11 16:05:14 +00:00
|
|
|
|
|
|
|
func TestCalcNeededNodes(t *testing.T) {
|
|
|
|
for i, tt := range []struct {
|
|
|
|
k, m, o, n int32
|
|
|
|
needed int32
|
|
|
|
}{
|
|
|
|
{k: 0, m: 0, o: 0, n: 0, needed: 0},
|
|
|
|
{k: 1, m: 1, o: 1, n: 1, needed: 1},
|
|
|
|
{k: 1, m: 1, o: 2, n: 2, needed: 2},
|
|
|
|
{k: 1, m: 2, o: 2, n: 2, needed: 2},
|
|
|
|
{k: 2, m: 3, o: 4, n: 4, needed: 3},
|
|
|
|
{k: 2, m: 4, o: 6, n: 8, needed: 3},
|
|
|
|
{k: 20, m: 30, o: 40, n: 50, needed: 25},
|
|
|
|
{k: 29, m: 35, o: 80, n: 95, needed: 34},
|
|
|
|
} {
|
|
|
|
tag := fmt.Sprintf("#%d. %+v", i, tt)
|
|
|
|
|
|
|
|
rs := pb.RedundancyScheme{
|
|
|
|
MinReq: tt.k,
|
|
|
|
RepairThreshold: tt.m,
|
|
|
|
SuccessThreshold: tt.o,
|
|
|
|
Total: tt.n,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Equal(t, tt.needed, calcNeededNodes(&rs), tag)
|
|
|
|
}
|
|
|
|
}
|