Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By implementing a simpler Range, we can get rid of many methods defined for storage.KeyValueStore. Initially KeyValueStore was used to manage objects, hence it required much more complex behaviour. However, we've moved away from this implementation, hence we can significantly simplify everything. Change-Id: Iaaa8c9c83d8601ad3c894767f17c0f5b356f7253
- Loading branch information
Showing
9 changed files
with
163 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2023 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
package testsuite | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"math/rand" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"storj.io/common/testcontext" | ||
"storj.io/storj/storage" | ||
) | ||
|
||
func testRange(t *testing.T, ctx *testcontext.Context, store storage.KeyValueStore) { | ||
err := store.Range(ctx, func(ctx context.Context, key storage.Key, value storage.Value) error { | ||
return errors.New("empty store") | ||
}) | ||
require.NoError(t, err) | ||
|
||
items := storage.Items{ | ||
newItem("a", "a", false), | ||
newItem("b/1", "b/1", false), | ||
newItem("b/2", "b/2", false), | ||
newItem("b/3", "b/3", false), | ||
newItem("c", "c", false), | ||
newItem("c/", "c/", false), | ||
newItem("c//", "c//", false), | ||
newItem("c/1", "c/1", false), | ||
newItem("g", "g", false), | ||
newItem("h", "h", false), | ||
} | ||
rand.Shuffle(len(items), items.Swap) | ||
defer cleanupItems(t, ctx, store, items) | ||
|
||
if err := storage.PutAll(ctx, store, items...); err != nil { | ||
t.Fatalf("failed to setup: %v", err) | ||
} | ||
|
||
var output storage.Items | ||
err = store.Range(ctx, func(ctx context.Context, key storage.Key, value storage.Value) error { | ||
output = append(output, storage.ListItem{ | ||
Key: append([]byte{}, key...), | ||
Value: append([]byte{}, value...), | ||
}) | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
expected := storage.CloneItems(items) | ||
sort.Sort(expected) | ||
sort.Sort(output) | ||
|
||
require.EqualValues(t, expected, output) | ||
} |