-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support ImportSnapshotOperation in oplog
- Loading branch information
1 parent
2c421d6
commit 89f95b3
Showing
4 changed files
with
168 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package indexutil | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"go.etcd.io/bbolt" | ||
) | ||
|
||
func TestIndexing(t *testing.T) { | ||
db, err := bbolt.Open(t.TempDir() + "/test.boltdb", 0600, nil) | ||
if err != nil { | ||
t.Fatalf("error opening database: %s", err) | ||
} | ||
|
||
if err := db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucket([]byte("test")) | ||
if err != nil { | ||
return fmt.Errorf("error creating bucket: %s", err) | ||
} | ||
for id := 0; id < 100; id += 1 { | ||
if err := IndexByteValue(b, []byte("document"), int64(id)); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("db.Update error: %v", err) | ||
} | ||
|
||
if err := db.View(func(tx *bbolt.Tx) error { | ||
b := tx.Bucket([]byte("test")) | ||
ids := IndexSearchByteValue(b, []byte("document")).ToSlice() | ||
if len(ids) != 100 { | ||
t.Errorf("want 100 ids, got %d", len(ids)) | ||
} | ||
ids = IndexSearchByteValue(b, []byte("other")).ToSlice() | ||
if len(ids) != 0 { | ||
t.Errorf("want 0 ids, got %d", len(ids)) | ||
} | ||
return nil | ||
}); err != nil { | ||
t.Fatalf("db.View error: %v", err) | ||
} | ||
} |
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