2021-02-18 12:54:09 +00:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
2021-03-02 12:20:02 +00:00
|
|
|
"bytes"
|
|
|
|
"sort"
|
2021-02-18 12:54:09 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2021-03-01 15:27:04 +00:00
|
|
|
"time"
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-03-02 12:20:02 +00:00
|
|
|
"storj.io/common/storj"
|
2021-02-18 12:54:09 +00:00
|
|
|
"storj.io/common/testcontext"
|
|
|
|
"storj.io/common/testrand"
|
|
|
|
"storj.io/common/uuid"
|
2021-04-21 13:42:57 +01:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2021-04-26 10:35:44 +01:00
|
|
|
"storj.io/storj/satellite/metabase/metabasetest"
|
2021-02-18 12:54:09 +00:00
|
|
|
)
|
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
func TestIterateLoopObjects(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
2021-02-18 12:54:09 +00:00
|
|
|
t.Run("Limit is negative", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "BatchSize is negative",
|
|
|
|
}.Check(ctx, t, db)
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("no data", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 0,
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 10,
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: 10,
|
|
|
|
AsOfSystemTime: time.Now(),
|
|
|
|
},
|
|
|
|
Result: nil,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("pending and committed", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
pending := metabasetest.RandObjectStream()
|
|
|
|
committed := metabasetest.RandObjectStream()
|
2021-02-18 12:54:09 +00:00
|
|
|
committed.ProjectID = pending.ProjectID
|
|
|
|
committed.BucketName = pending.BucketName + "z"
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-18 12:54:09 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: pending,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-18 12:54:09 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2021-02-18 12:54:09 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: committed,
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-18 12:54:09 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CommitObject{
|
2021-02-18 12:54:09 +00:00
|
|
|
Opts: metabase.CommitObject{
|
|
|
|
ObjectStream: committed,
|
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-03-19 13:06:13 +00:00
|
|
|
createdAt := time.Now()
|
2021-03-03 11:20:41 +00:00
|
|
|
expected := []metabase.LoopObjectEntry{
|
|
|
|
{
|
|
|
|
ObjectStream: pending,
|
2021-04-15 12:06:08 +01:00
|
|
|
Status: metabase.Pending,
|
2021-03-19 13:06:13 +00:00
|
|
|
CreatedAt: createdAt,
|
2021-03-03 11:20:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: committed,
|
2021-04-15 12:06:08 +01:00
|
|
|
Status: metabase.Committed,
|
2021-03-03 11:20:41 +00:00
|
|
|
EncryptedMetadataSize: len(encryptedMetadata),
|
2021-03-19 13:06:13 +00:00
|
|
|
CreatedAt: createdAt,
|
2021-03-03 11:20:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 1,
|
|
|
|
},
|
2021-03-03 11:20:41 +00:00
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: 1,
|
|
|
|
AsOfSystemTime: time.Now(),
|
2021-02-18 12:54:09 +00:00
|
|
|
},
|
2021-03-03 11:20:41 +00:00
|
|
|
Result: expected,
|
2021-02-18 12:54:09 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("less objects than limit", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
numberOfObjects := 3
|
|
|
|
limit := 10
|
2021-03-01 14:29:03 +00:00
|
|
|
expected := make([]metabase.LoopObjectEntry, numberOfObjects)
|
2021-02-18 12:54:09 +00:00
|
|
|
objects := createObjects(ctx, t, db, numberOfObjects, uuid.UUID{1}, "mybucket")
|
|
|
|
for i, obj := range objects {
|
2021-03-01 14:29:03 +00:00
|
|
|
expected[i] = loopObjectEntryFromRaw(obj)
|
2021-02-18 12:54:09 +00:00
|
|
|
}
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: limit,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: limit,
|
|
|
|
AsOfSystemTime: time.Now(),
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("more objects than limit", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
numberOfObjects := 10
|
|
|
|
limit := 3
|
2021-03-01 14:29:03 +00:00
|
|
|
expected := make([]metabase.LoopObjectEntry, numberOfObjects)
|
2021-02-18 12:54:09 +00:00
|
|
|
objects := createObjects(ctx, t, db, numberOfObjects, uuid.UUID{1}, "mybucket")
|
|
|
|
for i, obj := range objects {
|
2021-03-01 14:29:03 +00:00
|
|
|
expected[i] = loopObjectEntryFromRaw(obj)
|
2021-02-18 12:54:09 +00:00
|
|
|
}
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: limit,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: limit,
|
|
|
|
AsOfSystemTime: time.Now(),
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: objects}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("recursive", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
projectID, bucketName := uuid.UUID{1}, "bucky"
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
objects := metabasetest.CreateFullObjectsWithKeys(ctx, t, db, projectID, bucketName, []metabase.ObjectKey{
|
2021-02-18 12:54:09 +00:00
|
|
|
"a",
|
|
|
|
"b/1",
|
|
|
|
"b/2",
|
|
|
|
"b/3",
|
|
|
|
"c",
|
|
|
|
"c/",
|
|
|
|
"c//",
|
|
|
|
"c/1",
|
|
|
|
"g",
|
|
|
|
})
|
|
|
|
|
2021-03-03 11:20:41 +00:00
|
|
|
expected := []metabase.LoopObjectEntry{
|
|
|
|
objects["a"],
|
|
|
|
objects["b/1"],
|
|
|
|
objects["b/2"],
|
|
|
|
objects["b/3"],
|
|
|
|
objects["c"],
|
|
|
|
objects["c/"],
|
|
|
|
objects["c//"],
|
|
|
|
objects["c/1"],
|
|
|
|
objects["g"],
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 3,
|
|
|
|
},
|
2021-03-03 11:20:41 +00:00
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: 3,
|
|
|
|
AsOfSystemTime: time.Now(),
|
2021-02-18 12:54:09 +00:00
|
|
|
},
|
2021-03-03 11:20:41 +00:00
|
|
|
Result: expected,
|
2021-02-18 12:54:09 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("multiple projects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
|
|
|
|
projects := []uuid.UUID{}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
p := testrand.UUID()
|
|
|
|
p[0] = byte(i)
|
|
|
|
projects = append(projects, p)
|
|
|
|
}
|
|
|
|
bucketNames := strings.Split("abcde", "")
|
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
expected := make([]metabase.LoopObjectEntry, 0, len(projects)*len(bucketNames))
|
2021-02-18 12:54:09 +00:00
|
|
|
for _, projectID := range projects {
|
|
|
|
for _, bucketName := range bucketNames {
|
|
|
|
rawObjects := createObjects(ctx, t, db, 1, projectID, bucketName)
|
|
|
|
for _, obj := range rawObjects {
|
2021-03-01 14:29:03 +00:00
|
|
|
expected = append(expected, loopObjectEntryFromRaw(obj))
|
2021-02-18 12:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 3,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: 3,
|
|
|
|
AsOfSystemTime: time.Now(),
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("multiple projects", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
|
|
|
|
projects := []uuid.UUID{}
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
p := testrand.UUID()
|
|
|
|
p[0] = byte(i)
|
|
|
|
projects = append(projects, p)
|
|
|
|
}
|
|
|
|
bucketNames := strings.Split("abcde", "")
|
|
|
|
|
2021-03-01 14:29:03 +00:00
|
|
|
expected := make([]metabase.LoopObjectEntry, 0, len(projects)*len(bucketNames))
|
2021-02-18 12:54:09 +00:00
|
|
|
for _, projectID := range projects {
|
|
|
|
for _, bucketName := range bucketNames {
|
2021-04-26 10:35:44 +01:00
|
|
|
obj := metabasetest.RandObjectStream()
|
2021-02-18 12:54:09 +00:00
|
|
|
obj.ProjectID = projectID
|
|
|
|
obj.BucketName = bucketName
|
|
|
|
for version := 1; version < 4; version++ {
|
|
|
|
obj.Version = metabase.Version(version)
|
2021-04-26 10:35:44 +01:00
|
|
|
rawObject := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2021-03-01 14:29:03 +00:00
|
|
|
expected = append(expected, loopObjectEntryFromRaw(metabase.RawObject(rawObject)))
|
2021-02-18 12:54:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-01 14:29:03 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
2021-02-18 12:54:09 +00:00
|
|
|
BatchSize: 2,
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-03-03 11:20:41 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopObjects{
|
2021-03-03 11:20:41 +00:00
|
|
|
Opts: metabase.IterateLoopObjects{
|
|
|
|
BatchSize: 2,
|
|
|
|
AsOfSystemTime: time.Now(),
|
|
|
|
},
|
|
|
|
Result: expected,
|
|
|
|
}.Check(ctx, t, db)
|
2021-02-18 12:54:09 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-01 15:27:04 +00:00
|
|
|
func TestIterateLoopStreams(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
2021-03-02 12:20:02 +00:00
|
|
|
t.Run("StreamIDs list is empty", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-02 12:20:02 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopStreams{
|
2021-03-01 15:27:04 +00:00
|
|
|
Opts: metabase.IterateLoopStreams{},
|
|
|
|
Result: map[uuid.UUID][]metabase.LoopSegmentEntry{},
|
2021-03-02 12:20:02 +00:00
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "StreamIDs list is empty",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-03-02 12:20:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("StreamIDs list contains empty ID", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-02 12:20:02 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopStreams{
|
2021-03-01 15:27:04 +00:00
|
|
|
Opts: metabase.IterateLoopStreams{
|
2021-03-02 12:20:02 +00:00
|
|
|
StreamIDs: []uuid.UUID{{}},
|
|
|
|
},
|
2021-03-01 15:27:04 +00:00
|
|
|
Result: map[uuid.UUID][]metabase.LoopSegmentEntry{},
|
2021-03-02 12:20:02 +00:00
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "StreamID missing: index 0",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-03-02 12:20:02 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("List objects segments", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-03-02 12:20:02 +00:00
|
|
|
|
2021-03-12 17:43:30 +00:00
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
expectedObject00 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 0)
|
|
|
|
expectedObject01 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 1)
|
|
|
|
expectedObject02 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 5)
|
|
|
|
expectedObject03 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 3)
|
2021-03-02 12:20:02 +00:00
|
|
|
|
|
|
|
expectedRawSegments := []metabase.RawSegment{}
|
|
|
|
|
2021-03-01 15:27:04 +00:00
|
|
|
objects := []metabase.Object{
|
|
|
|
expectedObject00,
|
|
|
|
expectedObject01,
|
|
|
|
expectedObject02,
|
|
|
|
expectedObject03,
|
|
|
|
}
|
2021-03-02 12:20:02 +00:00
|
|
|
|
|
|
|
sort.Slice(objects, func(i, j int) bool {
|
|
|
|
return bytes.Compare(objects[i].StreamID[:], objects[j].StreamID[:]) < 0
|
|
|
|
})
|
|
|
|
|
2021-03-01 15:27:04 +00:00
|
|
|
expectedMap := make(map[uuid.UUID][]metabase.LoopSegmentEntry)
|
|
|
|
for _, object := range objects {
|
|
|
|
var expectedSegments []metabase.LoopSegmentEntry
|
2021-03-02 12:20:02 +00:00
|
|
|
for i := 0; i < int(object.SegmentCount); i++ {
|
|
|
|
segment := metabase.LoopSegmentEntry{
|
|
|
|
StreamID: object.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: uint32(i),
|
|
|
|
},
|
2021-03-31 15:08:10 +01:00
|
|
|
CreatedAt: &now,
|
2021-03-02 12:58:23 +00:00
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedSize: 1024,
|
2021-04-15 12:06:08 +01:00
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: int64(i * 512),
|
2021-03-02 12:58:23 +00:00
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-03-02 12:20:02 +00:00
|
|
|
}
|
|
|
|
expectedSegments = append(expectedSegments, segment)
|
2021-03-01 15:27:04 +00:00
|
|
|
|
2021-03-02 12:58:23 +00:00
|
|
|
expectedRawSegments = append(expectedRawSegments, metabase.RawSegment{
|
|
|
|
StreamID: segment.StreamID,
|
|
|
|
Position: segment.Position,
|
2021-03-12 17:43:30 +00:00
|
|
|
CreatedAt: &now,
|
2021-03-02 12:58:23 +00:00
|
|
|
EncryptedSize: segment.EncryptedSize,
|
|
|
|
Pieces: segment.Pieces,
|
|
|
|
Redundancy: segment.Redundancy,
|
|
|
|
RootPieceID: segment.RootPieceID,
|
|
|
|
PlainSize: 512,
|
2021-03-30 10:44:43 +01:00
|
|
|
PlainOffset: int64(i * 512),
|
2021-03-02 12:58:23 +00:00
|
|
|
EncryptedKey: []byte{3},
|
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2021-03-02 12:58:23 +00:00
|
|
|
})
|
2021-03-02 12:20:02 +00:00
|
|
|
}
|
2021-03-01 15:27:04 +00:00
|
|
|
expectedMap[object.StreamID] = expectedSegments
|
2021-03-02 12:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopStreams{
|
2021-03-01 15:27:04 +00:00
|
|
|
Opts: metabase.IterateLoopStreams{
|
2021-03-02 12:20:02 +00:00
|
|
|
StreamIDs: []uuid.UUID{
|
2021-03-01 15:27:04 +00:00
|
|
|
expectedObject00.StreamID,
|
2021-03-02 12:20:02 +00:00
|
|
|
expectedObject01.StreamID,
|
|
|
|
expectedObject02.StreamID,
|
|
|
|
expectedObject03.StreamID,
|
|
|
|
},
|
2021-03-01 15:27:04 +00:00
|
|
|
|
|
|
|
AsOfSystemTime: time.Now(),
|
2021-03-02 12:20:02 +00:00
|
|
|
},
|
2021-03-01 15:27:04 +00:00
|
|
|
Result: expectedMap,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.IterateLoopStreams{
|
2021-03-01 15:27:04 +00:00
|
|
|
Opts: metabase.IterateLoopStreams{
|
|
|
|
StreamIDs: []uuid.UUID{
|
|
|
|
expectedObject00.StreamID,
|
|
|
|
expectedObject01.StreamID,
|
|
|
|
expectedObject02.StreamID,
|
|
|
|
expectedObject03.StreamID,
|
|
|
|
},
|
2021-03-02 12:20:02 +00:00
|
|
|
},
|
2021-03-01 15:27:04 +00:00
|
|
|
Result: expectedMap,
|
2021-03-02 12:20:02 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-03-02 12:20:02 +00:00
|
|
|
Objects: []metabase.RawObject{
|
2021-03-01 15:27:04 +00:00
|
|
|
metabase.RawObject(expectedObject00),
|
2021-03-02 12:20:02 +00:00
|
|
|
metabase.RawObject(expectedObject01),
|
|
|
|
metabase.RawObject(expectedObject02),
|
|
|
|
metabase.RawObject(expectedObject03),
|
|
|
|
},
|
|
|
|
Segments: expectedRawSegments,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2021-03-01 15:27:04 +00:00
|
|
|
|
|
|
|
func loopObjectEntryFromRaw(m metabase.RawObject) metabase.LoopObjectEntry {
|
|
|
|
return metabase.LoopObjectEntry{
|
|
|
|
ObjectStream: m.ObjectStream,
|
2021-04-15 12:06:08 +01:00
|
|
|
Status: metabase.Committed,
|
|
|
|
CreatedAt: m.CreatedAt,
|
2021-03-01 15:27:04 +00:00
|
|
|
ExpiresAt: m.ExpiresAt,
|
|
|
|
SegmentCount: m.SegmentCount,
|
|
|
|
}
|
|
|
|
}
|