Skip to content

Commit

Permalink
mdbx v0_12_10 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Apr 15, 2024
1 parent a15c4f5 commit b2b0abd
Show file tree
Hide file tree
Showing 13 changed files with 1,256 additions and 503 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ jobs:
go-version: '1.20'

- run: go env
- run: go test ./mdbx ./exp/mdbxpool
- run: go test -p 1 ./mdbx
- run: go test -p 1 ./exp/mdbxpool
292 changes: 292 additions & 0 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,299 @@ func TestCursor_Del(t *testing.T) {
}
}

func TestDupCursor_EmptyKeyValues1(t *testing.T) {
env, _ := setup(t)

var db DBI
err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenDBI("testingdup", Create|DupSort, nil, nil)
if err != nil {
return err
}
cur, err := txn.OpenCursor(db)
if err != nil {
return err
}
defer cur.Close()

// empty value - must function as valid dupsort value
if err = txn.Put(db, []byte{1}, []byte{}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, []byte{1}, []byte{8}, 0); err != nil {
panic(err)
}

_, v, err := cur.Get([]byte{1}, []byte{}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}
_, v, err = cur.Get([]byte{1}, []byte{0}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{8}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
if err == nil {
panic("expecting 'not found' error")
}
if v != nil {
panic(v)
}

// can use empty key as valid key in non-dupsort operations
k, v, err := cur.Get([]byte{}, nil, SetRange)
if err != nil {
panic(err)
}
if k == nil {
panic("nil")
}
if !bytes.Equal(k, []byte{1}) {
panic(fmt.Sprintf("%x", k))
}
if !bytes.Equal(v, []byte{}) {
panic(fmt.Sprintf("%x", v))
}
k, v, err = cur.Get([]byte{}, nil, Set)
if err == nil {
panic("expected 'not found' error")
}
if k != nil {
panic("nil")
}

return nil
})
if err != nil {
t.Error(err)
}
}

func TestDupCursor_EmptyKeyValues2(t *testing.T) {
t.Skip()
env, _ := setup(t)

var db DBI
err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenDBI("testingdup", Create|DupSort, nil, nil)
if err != nil {
return err
}
cur, err := txn.OpenCursor(db)
if err != nil {
return err
}
defer cur.Close()

// empty value - must function as valid dupsort value
if err = txn.Put(db, []byte{1}, []byte{}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, []byte{1}, []byte{8}, 0); err != nil {
panic(err)
}

_, v, err := cur.Get([]byte{1}, []byte{}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}
_, v, err = cur.Get([]byte{1}, []byte{0}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{8}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
if err == nil {
panic("expecting 'not found' error")
}
if v != nil {
panic(v)
}

// can use empty key as valid key in non-dupsort operations
k, v, err := cur.Get([]byte{}, nil, SetRange)
if err != nil {
panic(err)
}
if k == nil {
panic("nil")
}
if !bytes.Equal(k, []byte{1}) {
panic(fmt.Sprintf("%x", k))
}
if !bytes.Equal(v, []byte{}) {
panic(fmt.Sprintf("%x", v))
}
k, v, err = cur.Get([]byte{}, nil, Set)
if err == nil {
panic("expected 'not found' error")
}
if k != nil {
panic("nil")
}

// empty key - must function as valid dupsort key
if err = txn.Put(db, []byte{}, []byte{}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, []byte{}, []byte{2}, 0); err != nil {
panic(err)
}
_, v, err = cur.Get([]byte{}, []byte{}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{2}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
if err == nil {
panic("expecting 'not found' error ")
}
if v != nil {
panic(v)
}

return nil
})
if err != nil {
t.Error(err)
}
}

func TestDupCursor_EmptyKeyValues3(t *testing.T) {
t.Skip()
env, _ := setup(t)

var db DBI
err := env.Update(func(txn *Txn) (err error) {
db, err = txn.OpenDBI("testingdup", Create|DupSort, nil, nil)
if err != nil {
return err
}
cur, err := txn.OpenCursor(db)
if err != nil {
return err
}
defer cur.Close()

// empty value - must function as valid dupsort value
if err = txn.Put(db, []byte{1}, []byte{}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, []byte{1}, []byte{8}, 0); err != nil {
panic(err)
}

_, v, err := cur.Get([]byte{1}, []byte{}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}
_, v, err = cur.Get([]byte{1}, []byte{0}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{8}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
if err == nil {
panic("expecting 'not found' error")
}
if v != nil {
panic(v)
}

// can use empty key as valid key in non-dupsort operations
k, v, err := cur.Get([]byte{}, nil, SetRange)
if err != nil {
panic(err)
}
if k == nil {
panic("nil")
}
if !bytes.Equal(k, []byte{1}) {
panic(fmt.Sprintf("%x", k))
}
if !bytes.Equal(v, []byte{}) {
panic(fmt.Sprintf("%x", v))
}
k, v, err = cur.Get([]byte{}, nil, Set)
if err == nil {
panic("expected 'not found' error")
}
if k != nil {
panic("nil")
}

// empty key - must function as valid dupsort key
if err = txn.Put(db, []byte{}, []byte{}, 0); err != nil {
panic(err)
}
if err = txn.Put(db, []byte{}, []byte{2}, 0); err != nil {
panic(err)
}
_, v, err = cur.Get([]byte{}, []byte{}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBothRange)
if err != nil {
panic(err)
}
if !bytes.Equal(v, []byte{2}) {
panic(v)
}
_, v, err = cur.Get([]byte{}, []byte{0}, GetBoth)
if err == nil {
panic("expecting 'not found' error ")
}
if v != nil {
panic(v)
}

// non-existing key
_, v, err = cur.Get([]byte{7}, []byte{}, GetBoth)
if err == nil {
panic("expecting 'not found' error")
}
if v != nil {
panic(v)
}

return nil
})
if err != nil {
t.Error(err)
}
}

func TestDupCursor_EmptyKeyValues(t *testing.T) {
t.Skip()
env, _ := setup(t)

var db DBI
Expand Down
Loading

0 comments on commit b2b0abd

Please sign in to comment.