2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-09-05 17:10:35 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package testsuite
|
|
|
|
|
|
|
|
import (
|
2018-09-07 10:00:00 +01:00
|
|
|
"strconv"
|
2019-05-06 21:47:12 +01:00
|
|
|
"sync"
|
2018-09-05 17:10:35 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"storj.io/storj/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RunTests runs common storage.KeyValueStore tests
|
|
|
|
func RunTests(t *testing.T, store storage.KeyValueStore) {
|
|
|
|
// store = storelogger.NewTest(t, store)
|
|
|
|
|
|
|
|
t.Run("CRUD", func(t *testing.T) { testCRUD(t, store) })
|
|
|
|
t.Run("Constraints", func(t *testing.T) { testConstraints(t, store) })
|
|
|
|
t.Run("Iterate", func(t *testing.T) { testIterate(t, store) })
|
|
|
|
t.Run("IterateAll", func(t *testing.T) { testIterateAll(t, store) })
|
|
|
|
t.Run("Prefix", func(t *testing.T) { testPrefix(t, store) })
|
|
|
|
|
|
|
|
t.Run("List", func(t *testing.T) { testList(t, store) })
|
|
|
|
t.Run("ListV2", func(t *testing.T) { testListV2(t, store) })
|
2018-11-20 15:26:20 +00:00
|
|
|
|
|
|
|
t.Run("Parallel", func(t *testing.T) { testParallel(t, store) })
|
2018-09-05 17:10:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func testConstraints(t *testing.T, store storage.KeyValueStore) {
|
2018-09-07 10:00:00 +01:00
|
|
|
var items storage.Items
|
|
|
|
for i := 0; i < storage.LookupLimit+5; i++ {
|
|
|
|
items = append(items, storage.ListItem{
|
|
|
|
Key: storage.Key("test-" + strconv.Itoa(i)),
|
|
|
|
Value: storage.Value("xyz"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-05-06 21:47:12 +01:00
|
|
|
var wg sync.WaitGroup
|
2018-09-07 10:00:00 +01:00
|
|
|
for _, item := range items {
|
2019-05-06 21:47:12 +01:00
|
|
|
key := item.Key
|
|
|
|
value := item.Value
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
2019-06-05 15:23:10 +01:00
|
|
|
err := store.Put(ctx, key, value)
|
2019-05-06 21:47:12 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("store.Put err:", err)
|
|
|
|
}
|
|
|
|
}()
|
2018-09-07 10:00:00 +01:00
|
|
|
}
|
2019-05-06 21:47:12 +01:00
|
|
|
wg.Wait()
|
2018-09-07 10:00:00 +01:00
|
|
|
defer cleanupItems(store, items)
|
|
|
|
|
2018-09-05 17:10:35 +01:00
|
|
|
t.Run("Put Empty", func(t *testing.T) {
|
|
|
|
var key storage.Key
|
|
|
|
var val storage.Value
|
2019-06-05 15:23:10 +01:00
|
|
|
defer func() { _ = store.Delete(ctx, key) }()
|
2018-09-05 17:10:35 +01:00
|
|
|
|
2019-06-05 15:23:10 +01:00
|
|
|
err := store.Put(ctx, key, val)
|
2018-09-05 17:10:35 +01:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("putting empty key should fail")
|
|
|
|
}
|
|
|
|
})
|
2018-09-07 10:00:00 +01:00
|
|
|
|
|
|
|
t.Run("GetAll limit", func(t *testing.T) {
|
2019-06-05 15:23:10 +01:00
|
|
|
_, err := store.GetAll(ctx, items[:storage.LookupLimit].GetKeys())
|
2018-09-07 10:00:00 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("GetAll LookupLimit should succeed: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-06-05 15:23:10 +01:00
|
|
|
_, err = store.GetAll(ctx, items[:storage.LookupLimit+1].GetKeys())
|
2018-09-07 10:00:00 +01:00
|
|
|
if err == nil && err == storage.ErrLimitExceeded {
|
|
|
|
t.Fatalf("GetAll LookupLimit+1 should fail: %v", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("List limit", func(t *testing.T) {
|
2019-06-05 15:23:10 +01:00
|
|
|
keys, err := store.List(ctx, nil, storage.LookupLimit)
|
2018-09-07 10:00:00 +01:00
|
|
|
if err != nil || len(keys) != storage.LookupLimit {
|
|
|
|
t.Fatalf("List LookupLimit should succeed: %v / got %d", err, len(keys))
|
|
|
|
}
|
2019-06-05 15:23:10 +01:00
|
|
|
_, err = store.List(ctx, nil, storage.LookupLimit+1)
|
2018-09-07 10:00:00 +01:00
|
|
|
if err != nil || len(keys) != storage.LookupLimit {
|
|
|
|
t.Fatalf("List LookupLimit+1 shouldn't fail: %v / got %d", err, len(keys))
|
|
|
|
}
|
|
|
|
})
|
2018-09-05 17:10:35 +01:00
|
|
|
}
|