adds segment store tests (#198)

* starts adding segmentStore tests

* adds mocked interfaces for segmentStore tests

* adds tests for put, get, delete, and list

* regenerates pointerdb mock and updates calls to accommodate new changes
This commit is contained in:
Natalie Villasana 2018-08-07 11:52:11 -04:00 committed by GitHub
parent 4c6d359473
commit 9ad4949825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 807 additions and 0 deletions

View File

@ -0,0 +1,106 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: storj.io/storj/pkg/eestream (interfaces: ErasureScheme)
// Package mock_eestream is a generated GoMock package.
package mock_eestream
import (
gomock "github.com/golang/mock/gomock"
reflect "reflect"
)
// MockErasureScheme is a mock of ErasureScheme interface
type MockErasureScheme struct {
ctrl *gomock.Controller
recorder *MockErasureSchemeMockRecorder
}
// MockErasureSchemeMockRecorder is the mock recorder for MockErasureScheme
type MockErasureSchemeMockRecorder struct {
mock *MockErasureScheme
}
// NewMockErasureScheme creates a new mock instance
func NewMockErasureScheme(ctrl *gomock.Controller) *MockErasureScheme {
mock := &MockErasureScheme{ctrl: ctrl}
mock.recorder = &MockErasureSchemeMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockErasureScheme) EXPECT() *MockErasureSchemeMockRecorder {
return m.recorder
}
// Decode mocks base method
func (m *MockErasureScheme) Decode(arg0 []byte, arg1 map[int][]byte) ([]byte, error) {
ret := m.ctrl.Call(m, "Decode", arg0, arg1)
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Decode indicates an expected call of Decode
func (mr *MockErasureSchemeMockRecorder) Decode(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Decode", reflect.TypeOf((*MockErasureScheme)(nil).Decode), arg0, arg1)
}
// DecodedBlockSize mocks base method
func (m *MockErasureScheme) DecodedBlockSize() int {
ret := m.ctrl.Call(m, "DecodedBlockSize")
ret0, _ := ret[0].(int)
return ret0
}
// DecodedBlockSize indicates an expected call of DecodedBlockSize
func (mr *MockErasureSchemeMockRecorder) DecodedBlockSize() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DecodedBlockSize", reflect.TypeOf((*MockErasureScheme)(nil).DecodedBlockSize))
}
// Encode mocks base method
func (m *MockErasureScheme) Encode(arg0 []byte, arg1 func(int, []byte)) error {
ret := m.ctrl.Call(m, "Encode", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Encode indicates an expected call of Encode
func (mr *MockErasureSchemeMockRecorder) Encode(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Encode", reflect.TypeOf((*MockErasureScheme)(nil).Encode), arg0, arg1)
}
// EncodedBlockSize mocks base method
func (m *MockErasureScheme) EncodedBlockSize() int {
ret := m.ctrl.Call(m, "EncodedBlockSize")
ret0, _ := ret[0].(int)
return ret0
}
// EncodedBlockSize indicates an expected call of EncodedBlockSize
func (mr *MockErasureSchemeMockRecorder) EncodedBlockSize() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "EncodedBlockSize", reflect.TypeOf((*MockErasureScheme)(nil).EncodedBlockSize))
}
// RequiredCount mocks base method
func (m *MockErasureScheme) RequiredCount() int {
ret := m.ctrl.Call(m, "RequiredCount")
ret0, _ := ret[0].(int)
return ret0
}
// RequiredCount indicates an expected call of RequiredCount
func (mr *MockErasureSchemeMockRecorder) RequiredCount() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RequiredCount", reflect.TypeOf((*MockErasureScheme)(nil).RequiredCount))
}
// TotalCount mocks base method
func (m *MockErasureScheme) TotalCount() int {
ret := m.ctrl.Call(m, "TotalCount")
ret0, _ := ret[0].(int)
return ret0
}
// TotalCount indicates an expected call of TotalCount
func (mr *MockErasureSchemeMockRecorder) TotalCount() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TotalCount", reflect.TypeOf((*MockErasureScheme)(nil).TotalCount))
}

View File

@ -0,0 +1,62 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: storj.io/storj/pkg/overlay (interfaces: Client)
// Package mock_overlay is a generated GoMock package.
package mock_overlay
import (
context "context"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
dht "storj.io/storj/pkg/dht"
overlay "storj.io/storj/protos/overlay"
)
// MockClient is a mock of Client interface
type MockClient struct {
ctrl *gomock.Controller
recorder *MockClientMockRecorder
}
// MockClientMockRecorder is the mock recorder for MockClient
type MockClientMockRecorder struct {
mock *MockClient
}
// NewMockClient creates a new mock instance
func NewMockClient(ctrl *gomock.Controller) *MockClient {
mock := &MockClient{ctrl: ctrl}
mock.recorder = &MockClientMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockClient) EXPECT() *MockClientMockRecorder {
return m.recorder
}
// Choose mocks base method
func (m *MockClient) Choose(arg0 context.Context, arg1 int, arg2 int64) ([]*overlay.Node, error) {
ret := m.ctrl.Call(m, "Choose", arg0, arg1, arg2)
ret0, _ := ret[0].([]*overlay.Node)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Choose indicates an expected call of Choose
func (mr *MockClientMockRecorder) Choose(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Choose", reflect.TypeOf((*MockClient)(nil).Choose), arg0, arg1, arg2)
}
// Lookup mocks base method
func (m *MockClient) Lookup(arg0 context.Context, arg1 dht.NodeID) (*overlay.Node, error) {
ret := m.ctrl.Call(m, "Lookup", arg0, arg1)
ret0, _ := ret[0].(*overlay.Node)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Lookup indicates an expected call of Lookup
func (mr *MockClientMockRecorder) Lookup(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Lookup", reflect.TypeOf((*MockClient)(nil).Lookup), arg0, arg1)
}

View File

@ -0,0 +1,88 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: storj.io/storj/pkg/pointerdb (interfaces: Client)
// Package mock_pointerdb is a generated GoMock package.
package mock_pointerdb
import (
context "context"
gomock "github.com/golang/mock/gomock"
reflect "reflect"
paths "storj.io/storj/pkg/paths"
pointerdb "storj.io/storj/pkg/pointerdb"
pointerdb0 "storj.io/storj/protos/pointerdb"
)
// MockClient is a mock of Client interface
type MockClient struct {
ctrl *gomock.Controller
recorder *MockClientMockRecorder
}
// MockClientMockRecorder is the mock recorder for MockClient
type MockClientMockRecorder struct {
mock *MockClient
}
// NewMockClient creates a new mock instance
func NewMockClient(ctrl *gomock.Controller) *MockClient {
mock := &MockClient{ctrl: ctrl}
mock.recorder = &MockClientMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockClient) EXPECT() *MockClientMockRecorder {
return m.recorder
}
// Delete mocks base method
func (m *MockClient) Delete(arg0 context.Context, arg1 paths.Path) error {
ret := m.ctrl.Call(m, "Delete", arg0, arg1)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete
func (mr *MockClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClient)(nil).Delete), arg0, arg1)
}
// Get mocks base method
func (m *MockClient) Get(arg0 context.Context, arg1 paths.Path) (*pointerdb0.Pointer, error) {
ret := m.ctrl.Call(m, "Get", arg0, arg1)
ret0, _ := ret[0].(*pointerdb0.Pointer)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Get indicates an expected call of Get
func (mr *MockClientMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClient)(nil).Get), arg0, arg1)
}
// List mocks base method
func (m *MockClient) List(arg0 context.Context, arg1, arg2, arg3 paths.Path, arg4 bool, arg5 int, arg6 uint32) ([]pointerdb.ListItem, bool, error) {
ret := m.ctrl.Call(m, "List", arg0, arg1, arg2, arg3, arg4, arg5, arg6)
ret0, _ := ret[0].([]pointerdb.ListItem)
ret1, _ := ret[1].(bool)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
// List indicates an expected call of List
func (mr *MockClientMockRecorder) List(arg0, arg1, arg2, arg3, arg4, arg5, arg6 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockClient)(nil).List), arg0, arg1, arg2, arg3, arg4, arg5, arg6)
}
// Put mocks base method
func (m *MockClient) Put(arg0 context.Context, arg1 paths.Path, arg2 *pointerdb0.Pointer) error {
ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Put indicates an expected call of Put
func (mr *MockClientMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockClient)(nil).Put), arg0, arg1, arg2)
}

View File

@ -0,0 +1,77 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: storj.io/storj/pkg/storage/ec (interfaces: Client)
// Package mock_ecclient is a generated GoMock package.
package mock_ecclient
import (
context "context"
gomock "github.com/golang/mock/gomock"
io "io"
reflect "reflect"
eestream "storj.io/storj/pkg/eestream"
client "storj.io/storj/pkg/piecestore/rpc/client"
ranger "storj.io/storj/pkg/ranger"
overlay "storj.io/storj/protos/overlay"
time "time"
)
// MockClient is a mock of Client interface
type MockClient struct {
ctrl *gomock.Controller
recorder *MockClientMockRecorder
}
// MockClientMockRecorder is the mock recorder for MockClient
type MockClientMockRecorder struct {
mock *MockClient
}
// NewMockClient creates a new mock instance
func NewMockClient(ctrl *gomock.Controller) *MockClient {
mock := &MockClient{ctrl: ctrl}
mock.recorder = &MockClientMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockClient) EXPECT() *MockClientMockRecorder {
return m.recorder
}
// Delete mocks base method
func (m *MockClient) Delete(arg0 context.Context, arg1 []*overlay.Node, arg2 client.PieceID) error {
ret := m.ctrl.Call(m, "Delete", arg0, arg1, arg2)
ret0, _ := ret[0].(error)
return ret0
}
// Delete indicates an expected call of Delete
func (mr *MockClientMockRecorder) Delete(arg0, arg1, arg2 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockClient)(nil).Delete), arg0, arg1, arg2)
}
// Get mocks base method
func (m *MockClient) Get(arg0 context.Context, arg1 []*overlay.Node, arg2 eestream.ErasureScheme, arg3 client.PieceID, arg4 int64) (ranger.RangeCloser, error) {
ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(ranger.RangeCloser)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Get indicates an expected call of Get
func (mr *MockClientMockRecorder) Get(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockClient)(nil).Get), arg0, arg1, arg2, arg3, arg4)
}
// Put mocks base method
func (m *MockClient) Put(arg0 context.Context, arg1 []*overlay.Node, arg2 eestream.RedundancyStrategy, arg3 client.PieceID, arg4 io.Reader, arg5 time.Time) error {
ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2, arg3, arg4, arg5)
ret0, _ := ret[0].(error)
return ret0
}
// Put indicates an expected call of Put
func (mr *MockClientMockRecorder) Put(arg0, arg1, arg2, arg3, arg4, arg5 interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockClient)(nil).Put), arg0, arg1, arg2, arg3, arg4, arg5)
}

View File

@ -2,3 +2,477 @@
// See LICENSE for copying information.
package segments
import (
"context"
"strings"
"testing"
"time"
"github.com/golang/protobuf/ptypes"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"storj.io/storj/pkg/eestream"
mock_eestream "storj.io/storj/pkg/eestream/mocks"
mock_overlay "storj.io/storj/pkg/overlay/mocks"
"storj.io/storj/pkg/paths"
pdb "storj.io/storj/pkg/pointerdb"
mock_pointerdb "storj.io/storj/pkg/pointerdb/mocks"
mock_ecclient "storj.io/storj/pkg/storage/ec/mocks"
opb "storj.io/storj/protos/overlay"
ppb "storj.io/storj/protos/pointerdb"
)
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),
}
ss := NewSegmentStore(mockOC, mockEC, mockPDB, rs, 10)
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),
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, 10}
assert.NotNil(t, ss)
var mExp time.Time
mExp = time.Unix(0, 0).UTC()
pExp, err := ptypes.TimestampProto(mExp)
assert.NoError(t, err)
mod, err := ptypes.Timestamp(pExp)
assert.NoError(t, err)
for _, tt := range []struct {
pathInput string
returnPointer *ppb.Pointer
returnMeta Meta
}{
{"path/1/2/3", &ppb.Pointer{ExpirationDate: pExp}, Meta{Modified: mod, Expiration: mExp}},
} {
p := paths.New(tt.pathInput)
calls := []*gomock.Call{
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
).Return(tt.returnPointer, nil),
}
gomock.InOrder(calls...)
m, err := ss.Meta(ctx, p)
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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
r := strings.NewReader(tt.readerContent)
calls := []*gomock.Call{
mockES.EXPECT().TotalCount().Return(1),
mockOC.EXPECT().Choose(
gomock.Any(), gomock.Any(), gomock.Any(),
).Return([]*opb.Node{
&opb.Node{Id: "im-a-node"},
}, nil),
mockEC.EXPECT().Put(
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
),
mockES.EXPECT().RequiredCount().Return(1),
mockES.EXPECT().TotalCount().Return(1),
mockPDB.EXPECT().Put(
gomock.Any(), gomock.Any(), gomock.Any(),
).Return(nil),
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
),
}
gomock.InOrder(calls...)
_, err := ss.Put(ctx, p, r, tt.mdInput, tt.expiration)
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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
r := strings.NewReader(tt.readerContent)
calls := []*gomock.Call{
mockPDB.EXPECT().Put(
gomock.Any(), gomock.Any(), gomock.Any(),
).Return(nil),
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
),
}
gomock.InOrder(calls...)
_, err := ss.Put(ctx, p, r, tt.mdInput, tt.expiration)
assert.NoError(t, err, tt.name)
}
}
func TestSegmentStoreGetInline(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
var ti time.Time
ti = time.Unix(0, 0).UTC()
someTime, err := ptypes.TimestampProto(ti)
assert.NoError(t, err)
for _, tt := range []struct {
pathInput string
thresholdSize int
pointerType ppb.Pointer_DataType
inlineContent []byte
size int64
metadata []byte
}{
{"path/1/2/3", 10, ppb.Pointer_INLINE, []byte("000"), int64(3), []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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
calls := []*gomock.Call{
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
).Return(&ppb.Pointer{
Type: tt.pointerType,
InlineSegment: tt.inlineContent,
CreationDate: someTime,
ExpirationDate: someTime,
Size: tt.size,
Metadata: tt.metadata,
}, nil),
}
gomock.InOrder(calls...)
_, _, err := ss.Get(ctx, p)
assert.NoError(t, err)
}
}
func TestSegmentStoreGetRemote(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
var ti time.Time
ti = time.Unix(0, 0).UTC()
someTime, err := ptypes.TimestampProto(ti)
assert.NoError(t, err)
for _, tt := range []struct {
pathInput string
thresholdSize int
pointerType ppb.Pointer_DataType
size int64
metadata []byte
}{
{"path/1/2/3", 10, ppb.Pointer_REMOTE, int64(3), []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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
calls := []*gomock.Call{
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
).Return(&ppb.Pointer{
Type: tt.pointerType,
Remote: &ppb.RemoteSegment{
Redundancy: &ppb.RedundancyScheme{
Type: ppb.RedundancyScheme_RS,
MinReq: 1,
Total: 2,
RepairThreshold: 1,
SuccessThreshold: 2,
},
PieceId: "here's my piece id",
RemotePieces: []*ppb.RemotePiece{},
},
CreationDate: someTime,
ExpirationDate: someTime,
Size: tt.size,
Metadata: tt.metadata,
}, nil),
mockEC.EXPECT().Get(
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
),
}
gomock.InOrder(calls...)
_, _, err := ss.Get(ctx, p)
assert.NoError(t, err)
}
}
func TestSegmentStoreDeleteInline(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
var ti time.Time
ti = time.Unix(0, 0).UTC()
someTime, err := ptypes.TimestampProto(ti)
assert.NoError(t, err)
for _, tt := range []struct {
pathInput string
thresholdSize int
pointerType ppb.Pointer_DataType
inlineContent []byte
size int64
metadata []byte
}{
{"path/1/2/3", 10, ppb.Pointer_INLINE, []byte("000"), int64(3), []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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
calls := []*gomock.Call{
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
).Return(&ppb.Pointer{
Type: tt.pointerType,
InlineSegment: tt.inlineContent,
CreationDate: someTime,
ExpirationDate: someTime,
Size: tt.size,
Metadata: tt.metadata,
}, nil),
mockPDB.EXPECT().Delete(
gomock.Any(), gomock.Any(),
),
}
gomock.InOrder(calls...)
err := ss.Delete(ctx, p)
assert.NoError(t, err)
}
}
func TestSegmentStoreDeleteRemote(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
var ti time.Time
ti = time.Unix(0, 0).UTC()
someTime, err := ptypes.TimestampProto(ti)
assert.NoError(t, err)
for _, tt := range []struct {
pathInput string
thresholdSize int
pointerType ppb.Pointer_DataType
size int64
metadata []byte
}{
{"path/1/2/3", 10, ppb.Pointer_REMOTE, int64(3), []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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
p := paths.New(tt.pathInput)
calls := []*gomock.Call{
mockPDB.EXPECT().Get(
gomock.Any(), gomock.Any(),
).Return(&ppb.Pointer{
Type: tt.pointerType,
Remote: &ppb.RemoteSegment{
Redundancy: &ppb.RedundancyScheme{
Type: ppb.RedundancyScheme_RS,
MinReq: 1,
Total: 2,
RepairThreshold: 1,
SuccessThreshold: 2,
},
PieceId: "here's my piece id",
RemotePieces: []*ppb.RemotePiece{},
},
CreationDate: someTime,
ExpirationDate: someTime,
Size: tt.size,
Metadata: tt.metadata,
}, nil),
mockEC.EXPECT().Delete(
gomock.Any(), gomock.Any(), gomock.Any(),
),
mockPDB.EXPECT().Delete(
gomock.Any(), gomock.Any(),
),
}
gomock.InOrder(calls...)
err := ss.Delete(ctx, p)
assert.NoError(t, err)
}
}
func TestSegmentStoreList(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
for _, tt := range []struct {
prefixInput string
startAfterInput string
thresholdSize int
itemPath string
inlineContent []byte
metadata []byte
}{
{"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,
}
ss := segmentStore{mockOC, mockEC, mockPDB, rs, tt.thresholdSize}
assert.NotNil(t, ss)
prefix := paths.New(tt.prefixInput)
startAfter := paths.New(tt.startAfterInput)
listedPath := paths.New(tt.itemPath)
var ti time.Time
ti = time.Unix(0, 0).UTC()
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{
pdb.ListItem{
Path: listedPath,
Pointer: &ppb.Pointer{
Type: ppb.Pointer_INLINE,
InlineSegment: tt.inlineContent,
CreationDate: someTime,
ExpirationDate: someTime,
Size: int64(4),
Metadata: tt.metadata,
},
},
}, true, nil),
}
gomock.InOrder(calls...)
_, _, err = ss.List(ctx, prefix, startAfter, nil, false, 10, uint32(1))
assert.NoError(t, err)
}
}