2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-13 07:12:36 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package segments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/teststorj"
|
|
|
|
mock_overlay "storj.io/storj/pkg/overlay/mocks"
|
|
|
|
"storj.io/storj/pkg/pb"
|
2019-01-10 11:41:57 +00:00
|
|
|
mock_pointerdb "storj.io/storj/pkg/pointerdb/pdbclient/mocks"
|
2018-12-13 07:12:36 +00:00
|
|
|
"storj.io/storj/pkg/ranger"
|
2019-01-10 11:41:57 +00:00
|
|
|
mock_ecclient "storj.io/storj/pkg/storage/ec/mocks"
|
2018-12-13 07:12:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewSegmentRepairer(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)
|
|
|
|
|
2018-12-17 21:05:05 +00:00
|
|
|
ss := NewSegmentRepairer(mockOC, mockEC, mockPDB)
|
2018-12-13 07:12:36 +00:00
|
|
|
assert.NotNil(t, ss)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSegmentStoreRepairRemote(t *testing.T) {
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
ti := time.Unix(0, 0).UTC()
|
|
|
|
someTime, err := ptypes.TimestampProto(ti)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
for _, tt := range []struct {
|
|
|
|
pathInput string
|
|
|
|
thresholdSize int
|
|
|
|
pointerType pb.Pointer_DataType
|
|
|
|
size int64
|
|
|
|
metadata []byte
|
|
|
|
lostPieces []int32
|
|
|
|
newNodes []*pb.Node
|
|
|
|
data string
|
|
|
|
strsize, offset, length int64
|
|
|
|
substr string
|
|
|
|
meta Meta
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"path/1/2/3",
|
|
|
|
10,
|
|
|
|
pb.Pointer_REMOTE,
|
|
|
|
int64(3),
|
|
|
|
[]byte("metadata"),
|
|
|
|
[]int32{},
|
|
|
|
[]*pb.Node{
|
|
|
|
teststorj.MockNode("1"),
|
|
|
|
teststorj.MockNode("2"),
|
|
|
|
},
|
|
|
|
"abcdefghijkl",
|
|
|
|
12,
|
|
|
|
1,
|
|
|
|
4,
|
|
|
|
"bcde",
|
|
|
|
Meta{},
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
mockOC := mock_overlay.NewMockClient(ctrl)
|
|
|
|
mockEC := mock_ecclient.NewMockClient(ctrl)
|
|
|
|
mockPDB := mock_pointerdb.NewMockClient(ctrl)
|
|
|
|
|
|
|
|
sr := Repairer{mockOC, mockEC, mockPDB, &pb.NodeStats{}}
|
|
|
|
assert.NotNil(t, sr)
|
|
|
|
|
|
|
|
calls := []*gomock.Call{
|
|
|
|
mockPDB.EXPECT().Get(
|
|
|
|
gomock.Any(), gomock.Any(),
|
|
|
|
).Return(&pb.Pointer{
|
|
|
|
Type: tt.pointerType,
|
|
|
|
Remote: &pb.RemoteSegment{
|
|
|
|
Redundancy: &pb.RedundancyScheme{
|
|
|
|
Type: pb.RedundancyScheme_RS,
|
|
|
|
MinReq: 1,
|
|
|
|
Total: 2,
|
|
|
|
RepairThreshold: 1,
|
|
|
|
SuccessThreshold: 2,
|
|
|
|
},
|
|
|
|
PieceId: "here's my piece id",
|
|
|
|
RemotePieces: []*pb.RemotePiece{},
|
|
|
|
},
|
|
|
|
CreationDate: someTime,
|
|
|
|
ExpirationDate: someTime,
|
|
|
|
SegmentSize: tt.size,
|
|
|
|
Metadata: tt.metadata,
|
|
|
|
}, nil, nil, nil),
|
|
|
|
mockOC.EXPECT().BulkLookup(gomock.Any(), gomock.Any()),
|
|
|
|
mockOC.EXPECT().Choose(gomock.Any(), gomock.Any()).Return(tt.newNodes, nil),
|
2019-01-10 11:41:57 +00:00
|
|
|
mockPDB.EXPECT().PayerBandwidthAllocation(gomock.Any(), gomock.Any()),
|
2018-12-13 07:12:36 +00: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-12-13 07:12:36 +00:00
|
|
|
).Return(ranger.ByteRanger([]byte(tt.data)), nil),
|
2019-01-10 11:41:57 +00:00
|
|
|
mockPDB.EXPECT().PayerBandwidthAllocation(gomock.Any(), gomock.Any()),
|
2018-12-13 07:12:36 +00: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(),
|
2019-02-25 15:57:54 +00:00
|
|
|
).Return(tt.newNodes, nil, nil),
|
2018-12-13 07:12:36 +00:00
|
|
|
mockPDB.EXPECT().Put(
|
|
|
|
gomock.Any(), gomock.Any(), gomock.Any(),
|
|
|
|
).Return(nil),
|
|
|
|
}
|
|
|
|
gomock.InOrder(calls...)
|
|
|
|
|
|
|
|
err := sr.Repair(ctx, tt.pathInput, tt.lostPieces)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|