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 (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"storj.io/storj/internal/testcontext"
|
|
|
|
"storj.io/storj/pkg/datarepair/irreparable"
|
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()
|
|
|
|
|
|
|
|
testDatabase(ctx, t, db.Irreparable())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testDatabase(ctx context.Context, t *testing.T, irrdb irreparable.DB) {
|
|
|
|
//testing variables
|
|
|
|
segmentInfo := &irreparable.RemoteSegmentInfo{
|
|
|
|
EncryptedSegmentPath: []byte("IamSegmentkeyinfo"),
|
|
|
|
EncryptedSegmentDetail: []byte("IamSegmentdetailinfo"),
|
|
|
|
LostPiecesCount: int64(10),
|
|
|
|
RepairUnixSec: time.Now().Unix(),
|
|
|
|
RepairAttemptCount: int64(10),
|
|
|
|
}
|
|
|
|
|
|
|
|
{ // New entry
|
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segmentInfo)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
2018-12-20 18:29:05 +00:00
|
|
|
{ //Create the already existing entry
|
2018-12-10 19:08:45 +00:00
|
|
|
err := irrdb.IncrementRepairAttempts(ctx, segmentInfo)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
segmentInfo.RepairAttemptCount++
|
|
|
|
|
|
|
|
dbxInfo, err := irrdb.Get(ctx, segmentInfo.EncryptedSegmentPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, segmentInfo, dbxInfo)
|
|
|
|
}
|
|
|
|
|
|
|
|
{ //Delete existing entry
|
|
|
|
err := irrdb.Delete(ctx, segmentInfo.EncryptedSegmentPath)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = irrdb.Get(ctx, segmentInfo.EncryptedSegmentPath)
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
}
|