2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-10 19:08:45 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-12-12 15:39:16 +00:00
|
|
|
package irreparable_test
|
2018-12-10 19:08:45 +00:00
|
|
|
|
|
|
|
import (
|
2019-03-15 20:21:52 +00:00
|
|
|
"strconv"
|
2018-12-10 19:08:45 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
2019-03-15 20:21:52 +00:00
|
|
|
"storj.io/storj/pkg/pb"
|
2018-12-27 09:56:25 +00:00
|
|
|
"storj.io/storj/satellite"
|
2018-12-10 19:08:45 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb/satellitedbtest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIrreparable(t *testing.T) {
|
2018-12-27 09:56:25 +00:00
|
|
|
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
|
2018-12-10 19:08:45 +00:00
|
|
|
ctx := testcontext.New(t)
|
|
|
|
defer ctx.Cleanup()
|
|
|
|
|
2019-02-05 16:00:52 +00:00
|
|
|
irrdb := db.Irreparable()
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
// Create and insert test segment infos into DB
|
|
|
|
var segments []*pb.IrreparableSegment
|
|
|
|
for i := 0; i < 3; i++ {
|
|
|
|
segments = append(segments, &pb.IrreparableSegment{
|
|
|
|
Path: []byte(strconv.Itoa(i)),
|
|
|
|
SegmentDetail: &pb.Pointer{},
|
|
|
|
LostPieces: int32(i),
|
|
|
|
LastRepairAttempt: time.Now().Unix(),
|
|
|
|
RepairAttemptCount: int64(10),
|
|
|
|
})
|
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segments[i])
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // GetLimited limit 1, offset 0
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 1, 0)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(segs))
|
|
|
|
assert.Equal(t, segments[0], segs[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // GetLimited limit 1, offset 1
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 1, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(segs))
|
|
|
|
assert.Equal(t, segments[1], segs[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // GetLimited limit 2, offset 0
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 2, 0)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(segs))
|
|
|
|
assert.Equal(t, segments[0], segs[0])
|
|
|
|
assert.Equal(t, segments[1], segs[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // GetLimited limit 2, offset 1
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 2, 1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(segs))
|
|
|
|
assert.Equal(t, segments[1], segs[0])
|
|
|
|
assert.Equal(t, segments[2], segs[1])
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
{ // GetLimited limit 3, offset 1
|
|
|
|
segs, err := irrdb.GetLimited(ctx, 3, 1)
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.NoError(t, err)
|
2019-03-15 20:21:52 +00:00
|
|
|
assert.Equal(t, 2, len(segs))
|
|
|
|
assert.Equal(t, segments[1], segs[0])
|
|
|
|
assert.Equal(t, segments[2], segs[1])
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
{ // Test repair count incrementation
|
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segments[0])
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.NoError(t, err)
|
2019-03-15 20:21:52 +00:00
|
|
|
segments[0].RepairAttemptCount++
|
2019-02-05 16:00:52 +00:00
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
dbxInfo, err := irrdb.Get(ctx, segments[0].Path)
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.NoError(t, err)
|
2019-03-15 20:21:52 +00:00
|
|
|
assert.Equal(t, segments[0], dbxInfo)
|
2019-02-05 16:00:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ //Delete existing entry
|
2019-03-15 20:21:52 +00:00
|
|
|
err := irrdb.Delete(ctx, segments[0].Path)
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
_, err = irrdb.Get(ctx, segments[0].Path)
|
2019-02-05 16:00:52 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
2018-12-10 19:08:45 +00:00
|
|
|
})
|
|
|
|
}
|