testing pruning
This commit is contained in:
parent
60a8a63e62
commit
1632b7de18
@ -15,7 +15,7 @@ import (
|
||||
|
||||
const (
|
||||
defaultIAVLCacheSize = 10000
|
||||
defaultIAVLNumRecent = 1000
|
||||
defaultIAVLNumRecent = 100
|
||||
defaultIAVLStoreEvery = 10000
|
||||
)
|
||||
|
||||
@ -94,6 +94,11 @@ func (st *iavlStore) LastCommitID() CommitID {
|
||||
}
|
||||
}
|
||||
|
||||
// VersionExists returns whether or not a given version is stored
|
||||
func (st *iavlStore) VersionExists(version int64) bool {
|
||||
return st.tree.VersionExists(version)
|
||||
}
|
||||
|
||||
// Implements Store.
|
||||
func (st *iavlStore) GetStoreType() StoreType {
|
||||
return sdk.StoreTypeIAVL
|
||||
|
||||
@ -259,6 +259,35 @@ func TestIAVLReverseSubspaceIterator(t *testing.T) {
|
||||
require.Equal(t, len(expected), i)
|
||||
}
|
||||
|
||||
func nextVersion(iavl *iavlStore) {
|
||||
key := cmn.RandBytes(12)
|
||||
value := cmn.RandBytes(50)
|
||||
iavl.Set(key, value)
|
||||
iavl.Commit()
|
||||
}
|
||||
func TestIAVLPruning(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
tree := iavl.NewVersionedTree(db, cacheSize)
|
||||
iavlStore := newIAVLStore(tree, numRecent, storeEvery)
|
||||
nextVersion(iavlStore)
|
||||
var i, j int64
|
||||
for i = 1; i <= 100; i++ {
|
||||
for j = 1; j <= i; j++ {
|
||||
if (i-j) < numRecent || j%storeEvery == int64(0) {
|
||||
assert.True(t, iavlStore.VersionExists(j),
|
||||
"Missing version %d with latest version %d. Should save last %d and every %d",
|
||||
j, i, numRecent, storeEvery)
|
||||
} else {
|
||||
assert.False(t, iavlStore.VersionExists(j),
|
||||
"Unpruned version %d with latest version %d. Should prune all but last %d and every %d",
|
||||
j, i, numRecent, storeEvery)
|
||||
}
|
||||
}
|
||||
nextVersion(iavlStore)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestIAVLStoreQuery(t *testing.T) {
|
||||
db := dbm.NewMemDB()
|
||||
tree := iavl.NewVersionedTree(db, cacheSize)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user