-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Tombstone handling in Iter #21
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package leveldb_test | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
@@ -15,12 +16,15 @@ import ( | |
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
// a test set of key/value pairs used to evaluate iteration | ||
// note because :: is the namespace separator in leveldb, we want to ensure that keys | ||
// with colons are correctly iterated on. | ||
var pairs = [][]string{ | ||
{"aa", "first"}, | ||
{"ab", "second"}, | ||
{"ba", "third"}, | ||
{"bb", "fourth"}, | ||
{"bc", "fifth"}, | ||
{"b::a", "third"}, | ||
{"b::b", "fourth"}, | ||
{"b::c", "fifth"}, | ||
{"ca", "sixth"}, | ||
{"cb", "seventh"}, | ||
} | ||
|
@@ -44,11 +48,19 @@ func setupLevelDBEngine(t testing.TB) (_ *leveldb.LevelDBEngine, path string) { | |
os.RemoveAll(tempDir) | ||
} | ||
require.NoError(t, err) | ||
|
||
// Add a cleanup function to ensure the fixture is deleted after tests | ||
t.Cleanup(func() { | ||
// Teardown after finishing the test | ||
engine.Close() | ||
os.RemoveAll(tempDir) | ||
fmt.Printf("cleaned up %s\n", tempDir) | ||
bbengfort marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}) | ||
|
||
return engine, tempDir | ||
} | ||
|
||
// Creates an options.Options struct with namespace set and returns | ||
// a pointer to it. | ||
// Creates an options.Options struct with namespace set and returns a pointer to it. | ||
func namespaceOpts(namespace string, t *testing.T) *options.Options { | ||
opts, err := options.New(options.WithNamespace(namespace)) | ||
require.NoError(t, err) | ||
|
@@ -78,18 +90,14 @@ func checkDelete(ldbStore engine.Store, opts *options.Options, key []byte, t *te | |
require.Empty(t, value) | ||
} | ||
|
||
func TestLeveldbEngine(t *testing.T) { | ||
func TestLevelDBEngine(t *testing.T) { | ||
// Setup a levelDB Engine. | ||
ldbEngine, ldbPath := setupLevelDBEngine(t) | ||
require.Equal(t, "leveldb", ldbEngine.Engine()) | ||
|
||
// Ensure the db was created. | ||
require.DirExists(t, ldbPath) | ||
|
||
// Teardown after finishing the test. | ||
defer os.RemoveAll(ldbPath) | ||
defer ldbEngine.Close() | ||
|
||
// Use a constant key to ensure namespaces | ||
// are working correctly. | ||
key := []byte("foo") | ||
|
@@ -111,12 +119,8 @@ func TestLeveldbEngine(t *testing.T) { | |
} | ||
} | ||
|
||
func TestLeveldbTransactions(t *testing.T) { | ||
ldbEngine, ldbPath := setupLevelDBEngine(t) | ||
|
||
// Teardown after finishing the test | ||
defer os.RemoveAll(ldbPath) | ||
defer ldbEngine.Close() | ||
func TestLevelDBTransactions(t *testing.T) { | ||
ldbEngine, _ := setupLevelDBEngine(t) | ||
|
||
// Use a constant key to ensure namespaces | ||
// are working correctly. | ||
|
@@ -155,20 +159,9 @@ func TestLeveldbTransactions(t *testing.T) { | |
} | ||
|
||
func TestLevelDBIter(t *testing.T) { | ||
ldbEngine, ldbPath := setupLevelDBEngine(t) | ||
|
||
// Teardown after finishing the test | ||
defer os.RemoveAll(ldbPath) | ||
defer ldbEngine.Close() | ||
ldbEngine, _ := setupLevelDBEngine(t) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding the cleanup func, it makes the teardown code a lot neater. |
||
|
||
for _, namespace := range testNamespaces { | ||
// TODO: figure out what to do with this testcase. | ||
// Iter currently grabs the namespace by splitting | ||
// on :: and grabbing the first string, so it only | ||
// grabs "namespace". | ||
if namespace == "namespace::with::colons" { | ||
continue | ||
} | ||
// Add data to the database to iterate over. | ||
opts := namespaceOpts(namespace, t) | ||
|
||
|
@@ -223,7 +216,16 @@ func addIterPairsToDB(ldbStore engine.Store, opts *options.Options, pairs [][]st | |
obj := &pb.Object{ | ||
Key: key, | ||
Namespace: opts.Namespace, | ||
Data: value, | ||
Version: &pb.Version{ | ||
Pid: 1, | ||
Version: 1, | ||
Region: "testing", | ||
Parent: nil, | ||
Tombstone: false, | ||
}, | ||
Region: "testing", | ||
Owner: "testing", | ||
Data: value, | ||
} | ||
|
||
data, err := proto.Marshal(obj) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we ignoring the error here or does it get captured somewhere else?