2020-10-28 15:28:06 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package metabase_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/storj"
|
|
|
|
"storj.io/common/testcontext"
|
2020-11-16 16:46:47 +00:00
|
|
|
"storj.io/common/testrand"
|
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"
|
2020-10-28 15:28:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetObjectExactVersion(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-10-28 15:28:06 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Version invalid", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 0,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Version invalid: 0",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get not existing version", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 11,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectExactVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
Version: 1,
|
|
|
|
},
|
|
|
|
Result: metabase.Object{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetObjectLatestVersion(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
location := obj.Location()
|
|
|
|
|
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-10-28 15:28:06 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetObjectLatestVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectLatestVersion{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectLatestVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectLatestVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectLatestVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectLatestVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
2020-11-02 10:51:36 +00:00
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: sql: no rows in result set",
|
2020-10-28 15:28:06 +00:00
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
2020-10-29 13:49:53 +00:00
|
|
|
|
2021-05-06 12:42:20 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2020-11-16 16:46:47 +00:00
|
|
|
encryptedMetadata := testrand.Bytes(1024)
|
|
|
|
encryptedMetadataNonce := testrand.Nonce()
|
|
|
|
encryptedMetadataKey := testrand.Bytes(265)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateTestObject{
|
2020-11-02 15:28:51 +00:00
|
|
|
CommitObject: &metabase.CommitObject{
|
2020-11-16 16:46:47 +00:00
|
|
|
ObjectStream: obj,
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
2020-11-02 15:28:51 +00:00
|
|
|
},
|
|
|
|
}.Run(ctx, t, db, obj, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectLatestVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectLatestVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
Result: metabase.Object{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-02 15:28:51 +00:00
|
|
|
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-02 15:28:51 +00:00
|
|
|
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedMetadataNonce: encryptedMetadataNonce[:],
|
2020-11-16 16:46:47 +00:00
|
|
|
EncryptedMetadata: encryptedMetadata,
|
|
|
|
EncryptedMetadataEncryptedKey: encryptedMetadataKey,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get latest object version from multiple", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
firstVersion := obj
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, firstVersion, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
secondVersion := metabase.ObjectStream{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Version: 2,
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
}
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, secondVersion, 0)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetObjectLatestVersion{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetObjectLatestVersion{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
Result: metabase.Object{
|
|
|
|
ObjectStream: secondVersion,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{Objects: []metabase.RawObject{
|
2020-10-28 15:28:06 +00:00
|
|
|
{
|
|
|
|
ObjectStream: firstVersion,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: secondVersion,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-01 18:02:15 +00:00
|
|
|
func TestGetSegmentByLocation(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2021-02-01 18:02:15 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
location := metabase.SegmentLocation{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidSegmentLocations(location) {
|
2021-02-01 18:02:15 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetSegmentByLocation{
|
2021-02-01 18:02:15 +00:00
|
|
|
Opts: metabase.GetSegmentByLocation{
|
|
|
|
SegmentLocation: test.SegmentLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-02-01 18:02:15 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Object missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-01 18:02:15 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByLocation{
|
2021-02-01 18:02:15 +00:00
|
|
|
Opts: metabase.GetSegmentByLocation{
|
|
|
|
SegmentLocation: location,
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2021-02-01 18:02:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2021-02-01 18:02:15 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
expectedExpiresAt := now.Add(6 * time.Hour)
|
|
|
|
metabasetest.CreateExpiredObject(ctx, t, db, obj, 1, expectedExpiresAt)
|
2021-02-01 18:02:15 +00:00
|
|
|
|
|
|
|
expectedSegment := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: &expectedExpiresAt,
|
2021-02-01 18:02:15 +00:00
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2021-02-01 18:02:15 +00:00
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2021-02-01 18:02:15 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByLocation{
|
2021-02-01 18:02:15 +00:00
|
|
|
Opts: metabase.GetSegmentByLocation{
|
|
|
|
SegmentLocation: location,
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
// check non existing segment in existing object
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByLocation{
|
2021-02-01 18:02:15 +00:00
|
|
|
Opts: metabase.GetSegmentByLocation{
|
|
|
|
SegmentLocation: metabase.SegmentLocation{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
ObjectKey: obj.ObjectKey,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2021-02-01 18:02:15 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: &expectedExpiresAt,
|
2021-02-01 18:02:15 +00:00
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2021-02-01 18:02:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegment),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-28 15:28:06 +00:00
|
|
|
func TestGetSegmentByPosition(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
|
|
|
|
t.Run("StreamID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "StreamID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Segment missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
},
|
2020-12-15 12:49:58 +00:00
|
|
|
ErrClass: &metabase.ErrSegmentNotFound,
|
2020-10-28 15:28:06 +00:00
|
|
|
ErrText: "segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
obj1 := metabasetest.CreateObject(ctx, t, db, metabasetest.RandObjectStream(), 1)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
expectedExpiresAt := now.Add(5 * time.Hour)
|
|
|
|
obj2 := metabasetest.CreateExpiredObject(ctx, t, db, metabasetest.RandObjectStream(), 1, expectedExpiresAt)
|
2020-10-28 15:28:06 +00:00
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
segments := make([]metabase.Segment, 0, 2)
|
|
|
|
for _, obj := range []metabase.Object{obj1, obj2} {
|
|
|
|
expectedSegment := metabase.Segment{
|
2020-10-28 15:28:06 +00:00
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 0,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: obj.CreatedAt,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: obj.ExpiresAt,
|
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-06-11 16:47:42 +01:00
|
|
|
EncryptedETag: []byte{5},
|
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
|
|
|
}
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByPosition{
|
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Result: expectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
|
|
|
segments = append(segments, expectedSegment)
|
|
|
|
}
|
2020-10-28 15:28:06 +00:00
|
|
|
|
|
|
|
// check non existing segment in existing object
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByPosition{
|
2020-10-28 15:28:06 +00:00
|
|
|
Opts: metabase.GetSegmentByPosition{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 1,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
2020-12-15 12:49:58 +00:00
|
|
|
ErrClass: &metabase.ErrSegmentNotFound,
|
2020-10-28 15:28:06 +00:00
|
|
|
ErrText: "segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-10-28 15:28:06 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
2021-06-11 16:47:42 +01:00
|
|
|
ObjectStream: obj1.ObjectStream,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 1,
|
|
|
|
|
|
|
|
TotalPlainSize: 512,
|
|
|
|
TotalEncryptedSize: 1024,
|
|
|
|
FixedSegmentSize: 512,
|
|
|
|
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ObjectStream: obj2.ObjectStream,
|
2020-10-28 15:28:06 +00:00
|
|
|
CreatedAt: now,
|
2021-06-11 16:47:42 +01:00
|
|
|
ExpiresAt: obj2.ExpiresAt,
|
2020-10-28 15:28:06 +00:00
|
|
|
Status: metabase.Committed,
|
2020-11-03 14:45:39 +00:00
|
|
|
SegmentCount: 1,
|
|
|
|
|
2020-11-24 12:29:16 +00:00
|
|
|
TotalPlainSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
TotalEncryptedSize: 1024,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
2021-06-11 16:47:42 +01:00
|
|
|
metabase.RawSegment(segments[0]),
|
|
|
|
metabase.RawSegment(segments[1]),
|
2020-10-28 15:28:06 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-11-03 15:03:20 +00:00
|
|
|
|
|
|
|
func TestGetLatestObjectLastSegment(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-03 15:03:20 +00:00
|
|
|
location := obj.Location()
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-11-03 15:03:20 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Object or segment missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get last segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateObject(ctx, t, db, obj, 2)
|
2020-11-03 15:03:20 +00:00
|
|
|
|
|
|
|
expectedSegmentSecond := metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
2021-01-25 11:23:43 +00:00
|
|
|
Index: 1,
|
2020-11-03 15:03:20 +00:00
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-11-03 15:03:20 +00:00
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2020-11-03 15:03:20 +00:00
|
|
|
EncryptedSize: 1024,
|
|
|
|
PlainSize: 512,
|
2021-03-30 10:44:43 +01:00
|
|
|
PlainOffset: 512,
|
2020-11-03 15:03:20 +00:00
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-11-03 15:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expectedSegmentFirst := expectedSegmentSecond
|
2021-01-25 11:23:43 +00:00
|
|
|
expectedSegmentFirst.Position.Index = 0
|
2021-03-30 10:44:43 +01:00
|
|
|
expectedSegmentFirst.PlainOffset = 0
|
2020-11-03 15:03:20 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetLatestObjectLastSegment{
|
2020-11-03 15:03:20 +00:00
|
|
|
Opts: metabase.GetLatestObjectLastSegment{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
Result: expectedSegmentSecond,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-03 15:03:20 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
2020-11-03 14:45:39 +00:00
|
|
|
SegmentCount: 2,
|
|
|
|
|
2020-11-24 12:29:16 +00:00
|
|
|
TotalPlainSize: 1024,
|
2020-11-03 14:45:39 +00:00
|
|
|
TotalEncryptedSize: 2048,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-11-03 14:45:39 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-03 15:03:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(expectedSegmentFirst),
|
|
|
|
metabase.RawSegment(expectedSegmentSecond),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-11-10 09:17:25 +00:00
|
|
|
|
|
|
|
func TestGetSegmentByOffset(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-10 09:17:25 +00:00
|
|
|
location := obj.Location()
|
|
|
|
now := time.Now()
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
for _, test := range metabasetest.InvalidObjectLocations(location) {
|
2020-11-10 09:17:25 +00:00
|
|
|
test := test
|
|
|
|
t.Run(test.Name, func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
|
|
|
metabasetest.GetSegmentByOffset{
|
2020-11-10 09:17:25 +00:00
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: test.ObjectLocation,
|
|
|
|
},
|
|
|
|
ErrClass: test.ErrClass,
|
|
|
|
ErrText: test.ErrText,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Invalid PlainOffset", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByOffset{
|
2020-11-10 09:17:25 +00:00
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: location,
|
|
|
|
PlainOffset: -1,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "Invalid PlainOffset: -1",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Object or segment missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByOffset{
|
2020-11-10 09:17:25 +00:00
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: location,
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Get segment", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-10 09:17:25 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.CreateTestObject{}.Run(ctx, t, db, obj, 4)
|
2020-11-10 09:17:25 +00:00
|
|
|
|
|
|
|
segments := make([]metabase.Segment, 4)
|
|
|
|
for i := range segments {
|
|
|
|
segments[i] = metabase.Segment{
|
|
|
|
StreamID: obj.StreamID,
|
|
|
|
Position: metabase.SegmentPosition{
|
|
|
|
Index: uint32(i),
|
|
|
|
},
|
2021-08-05 00:56:50 +01:00
|
|
|
CreatedAt: now,
|
2020-11-10 09:17:25 +00:00
|
|
|
RootPieceID: storj.PieceID{1},
|
|
|
|
EncryptedKey: []byte{3},
|
2021-10-12 14:37:12 +01:00
|
|
|
EncryptedKeyNonce: []byte{4},
|
2021-03-25 07:53:10 +00:00
|
|
|
EncryptedETag: []byte{5},
|
2020-11-10 09:17:25 +00:00
|
|
|
EncryptedSize: 1060,
|
|
|
|
PlainSize: 512,
|
|
|
|
PlainOffset: int64(i * 512),
|
|
|
|
Pieces: metabase.Pieces{{Number: 0, StorageNode: storj.NodeID{2}}},
|
2021-04-26 10:35:44 +01:00
|
|
|
Redundancy: metabasetest.DefaultRedundancy,
|
2020-11-10 09:17:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testCases = []struct {
|
|
|
|
Offset int64
|
|
|
|
ExpectedSegment metabase.Segment
|
|
|
|
}{
|
|
|
|
{0, segments[0]},
|
|
|
|
{100, segments[0]},
|
|
|
|
{1023, segments[1]},
|
|
|
|
{1024, segments[2]},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByOffset{
|
2020-11-10 09:17:25 +00:00
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: location,
|
|
|
|
PlainOffset: tc.Offset,
|
|
|
|
},
|
|
|
|
Result: tc.ExpectedSegment,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
}
|
|
|
|
|
2021-06-11 16:47:42 +01:00
|
|
|
objExp := metabasetest.CreateExpiredObject(ctx, t, db, metabasetest.RandObjectStream(), 1, now.Add(8*time.Hour))
|
|
|
|
segmentExpiresAt := metabase.Segment(metabasetest.DefaultRawSegment(objExp.ObjectStream, metabase.SegmentPosition{
|
|
|
|
Index: 0,
|
|
|
|
}))
|
|
|
|
segmentExpiresAt.ExpiresAt = objExp.ExpiresAt
|
|
|
|
|
|
|
|
metabasetest.GetSegmentByOffset{
|
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: objExp.Location(),
|
|
|
|
PlainOffset: 0,
|
|
|
|
},
|
|
|
|
Result: segmentExpiresAt,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.GetSegmentByOffset{
|
2020-11-10 09:17:25 +00:00
|
|
|
Opts: metabase.GetSegmentByOffset{
|
|
|
|
ObjectLocation: location,
|
|
|
|
PlainOffset: 2048,
|
|
|
|
},
|
|
|
|
ErrClass: &storj.ErrObjectNotFound,
|
|
|
|
ErrText: "metabase: object or segment missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-10 09:17:25 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Committed,
|
|
|
|
SegmentCount: 4,
|
|
|
|
|
2020-11-24 12:29:16 +00:00
|
|
|
TotalPlainSize: 2048,
|
2020-11-10 09:17:25 +00:00
|
|
|
TotalEncryptedSize: 4240,
|
2021-01-14 11:47:29 +00:00
|
|
|
FixedSegmentSize: 512,
|
2020-11-10 09:17:25 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-10 09:17:25 +00:00
|
|
|
},
|
2021-06-11 16:47:42 +01:00
|
|
|
metabase.RawObject(objExp),
|
2020-11-10 09:17:25 +00:00
|
|
|
},
|
|
|
|
Segments: []metabase.RawSegment{
|
|
|
|
metabase.RawSegment(segments[0]),
|
|
|
|
metabase.RawSegment(segments[1]),
|
|
|
|
metabase.RawSegment(segments[2]),
|
|
|
|
metabase.RawSegment(segments[3]),
|
2021-06-11 16:47:42 +01:00
|
|
|
metabase.RawSegment(segmentExpiresAt),
|
2020-11-10 09:17:25 +00:00
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-11-17 17:37:58 +00:00
|
|
|
|
|
|
|
func TestBucketEmpty(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Run(t, func(ctx *testcontext.Context, t *testing.T, db *metabase.DB) {
|
|
|
|
obj := metabasetest.RandObjectStream()
|
2020-11-17 17:37:58 +00:00
|
|
|
now := time.Now()
|
2021-05-06 12:42:20 +01:00
|
|
|
zombieDeadline := now.Add(24 * time.Hour)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
|
|
|
t.Run("ProjectID missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "ProjectID missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketName missing", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
},
|
|
|
|
ErrClass: &metabase.ErrInvalidRequest,
|
|
|
|
ErrText: "BucketName missing",
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty true", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: true,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty false with pending object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BeginObjectExactVersion{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BeginObjectExactVersion{
|
|
|
|
ObjectStream: obj,
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
2020-11-17 17:37:58 +00:00
|
|
|
},
|
|
|
|
Version: 1,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: false,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-17 17:37:58 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
{
|
2021-05-06 12:42:20 +01:00
|
|
|
ObjectStream: obj,
|
|
|
|
CreatedAt: now,
|
|
|
|
Status: metabase.Pending,
|
|
|
|
Encryption: metabasetest.DefaultEncryption,
|
|
|
|
ZombieDeletionDeadline: &zombieDeadline,
|
2020-11-17 17:37:58 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("BucketEmpty false with committed object", func(t *testing.T) {
|
2021-04-26 10:35:44 +01:00
|
|
|
defer metabasetest.DeleteAll{}.Check(ctx, t, db)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
object := metabasetest.CreateObject(ctx, t, db, obj, 0)
|
2020-11-17 17:37:58 +00:00
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.BucketEmpty{
|
2020-11-17 17:37:58 +00:00
|
|
|
Opts: metabase.BucketEmpty{
|
|
|
|
ProjectID: obj.ProjectID,
|
|
|
|
BucketName: obj.BucketName,
|
|
|
|
},
|
|
|
|
Result: false,
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
|
2021-04-26 10:35:44 +01:00
|
|
|
metabasetest.Verify{
|
2020-11-17 17:37:58 +00:00
|
|
|
Objects: []metabase.RawObject{
|
|
|
|
metabase.RawObject(object),
|
|
|
|
},
|
|
|
|
}.Check(ctx, t, db)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|