loro/crates/kv-store/tests/test.rs

60 lines
1.6 KiB
Rust
Raw Normal View History

feat: memkv export import all (#422) * feat: sstable * fix: add magic number version * feat: new mem kv store based sstable * feat: binary_search * fix: sstable iter scan * fix: new mem kv * feat: add cache for sstable * fix: encode schema comment * fix: sstable iter scan * chore: clean * fix: export all * fix: sstable scan bound * fix: sstable iter scan next==prev * fix: merge iter next_back * fix: mem kv export * chore: clean * fix: prev to key * fix: prev find block * fix: get prev block idx * refactor: kv store * fix: checksum when import * fix: meta first last key * Revert "fix: meta first last key" This reverts commit a069c1ed37f89f04e1b7a51c3a91f562819a72f5. * fix: skip empty iter * fix: remove key from large block * chore: comment * feat: compress block * fix: remove key in large block * chore: const * doc: intro sstable encode * test: add kv store fuzz * style: format file * feat: add fuzz to kv store (#428) * fix: kv fuzzer * fix: debug * bk * fix: block iter next back * fix: block prev iter left = next idx * feat: move kv store a crate * fix: remove value len from normal block * doc: sstable format * test: add more test * test: add test * feat: new merge iter * chore: revert * fix: rename next back * fix: rename mem sstable * fix: rename to mem * fix: use Bytes as key * fix: use simple merge iter * feat: compress option * fix: remove empty iter * style: refine some impl details * fix: large block compress * feat: use write read for encode * doc: refine doc * fix: simplify the first chunk * feat: import many times * refactor: refine styles * test: fuzz merge iter * fix: rename peek_xxx() * fix: better sstable iter inner * fix: use mem kv store * pref: mem kv store * perf: export mem kv * chore: clean --------- Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-08-30 03:44:34 +00:00
use bytes::Bytes;
use loro_kv_store::{mem_store::MemKvConfig, MemKvStore};
feat: memkv export import all (#422) * feat: sstable * fix: add magic number version * feat: new mem kv store based sstable * feat: binary_search * fix: sstable iter scan * fix: new mem kv * feat: add cache for sstable * fix: encode schema comment * fix: sstable iter scan * chore: clean * fix: export all * fix: sstable scan bound * fix: sstable iter scan next==prev * fix: merge iter next_back * fix: mem kv export * chore: clean * fix: prev to key * fix: prev find block * fix: get prev block idx * refactor: kv store * fix: checksum when import * fix: meta first last key * Revert "fix: meta first last key" This reverts commit a069c1ed37f89f04e1b7a51c3a91f562819a72f5. * fix: skip empty iter * fix: remove key from large block * chore: comment * feat: compress block * fix: remove key in large block * chore: const * doc: intro sstable encode * test: add kv store fuzz * style: format file * feat: add fuzz to kv store (#428) * fix: kv fuzzer * fix: debug * bk * fix: block iter next back * fix: block prev iter left = next idx * feat: move kv store a crate * fix: remove value len from normal block * doc: sstable format * test: add more test * test: add test * feat: new merge iter * chore: revert * fix: rename next back * fix: rename mem sstable * fix: rename to mem * fix: use Bytes as key * fix: use simple merge iter * feat: compress option * fix: remove empty iter * style: refine some impl details * fix: large block compress * feat: use write read for encode * doc: refine doc * fix: simplify the first chunk * feat: import many times * refactor: refine styles * test: fuzz merge iter * fix: rename peek_xxx() * fix: better sstable iter inner * fix: use mem kv store * pref: mem kv store * perf: export mem kv * chore: clean --------- Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-08-30 03:44:34 +00:00
#[test]
fn add_and_remove() {
let key = &[0];
let value = Bytes::from_static(&[0]);
let mut store = MemKvStore::new(MemKvConfig::default());
feat: memkv export import all (#422) * feat: sstable * fix: add magic number version * feat: new mem kv store based sstable * feat: binary_search * fix: sstable iter scan * fix: new mem kv * feat: add cache for sstable * fix: encode schema comment * fix: sstable iter scan * chore: clean * fix: export all * fix: sstable scan bound * fix: sstable iter scan next==prev * fix: merge iter next_back * fix: mem kv export * chore: clean * fix: prev to key * fix: prev find block * fix: get prev block idx * refactor: kv store * fix: checksum when import * fix: meta first last key * Revert "fix: meta first last key" This reverts commit a069c1ed37f89f04e1b7a51c3a91f562819a72f5. * fix: skip empty iter * fix: remove key from large block * chore: comment * feat: compress block * fix: remove key in large block * chore: const * doc: intro sstable encode * test: add kv store fuzz * style: format file * feat: add fuzz to kv store (#428) * fix: kv fuzzer * fix: debug * bk * fix: block iter next back * fix: block prev iter left = next idx * feat: move kv store a crate * fix: remove value len from normal block * doc: sstable format * test: add more test * test: add test * feat: new merge iter * chore: revert * fix: rename next back * fix: rename mem sstable * fix: rename to mem * fix: use Bytes as key * fix: use simple merge iter * feat: compress option * fix: remove empty iter * style: refine some impl details * fix: large block compress * feat: use write read for encode * doc: refine doc * fix: simplify the first chunk * feat: import many times * refactor: refine styles * test: fuzz merge iter * fix: rename peek_xxx() * fix: better sstable iter inner * fix: use mem kv store * pref: mem kv store * perf: export mem kv * chore: clean --------- Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-08-30 03:44:34 +00:00
store.set(key, value.clone());
assert_eq!(store.get(key), Some(value));
store.remove(key);
assert_eq!(store.get(key), None);
}
#[test]
fn add_flush_remove() {
let key = &[0];
let value = Bytes::from_static(&[0]);
let mut store = MemKvStore::new(MemKvConfig::default());
feat: memkv export import all (#422) * feat: sstable * fix: add magic number version * feat: new mem kv store based sstable * feat: binary_search * fix: sstable iter scan * fix: new mem kv * feat: add cache for sstable * fix: encode schema comment * fix: sstable iter scan * chore: clean * fix: export all * fix: sstable scan bound * fix: sstable iter scan next==prev * fix: merge iter next_back * fix: mem kv export * chore: clean * fix: prev to key * fix: prev find block * fix: get prev block idx * refactor: kv store * fix: checksum when import * fix: meta first last key * Revert "fix: meta first last key" This reverts commit a069c1ed37f89f04e1b7a51c3a91f562819a72f5. * fix: skip empty iter * fix: remove key from large block * chore: comment * feat: compress block * fix: remove key in large block * chore: const * doc: intro sstable encode * test: add kv store fuzz * style: format file * feat: add fuzz to kv store (#428) * fix: kv fuzzer * fix: debug * bk * fix: block iter next back * fix: block prev iter left = next idx * feat: move kv store a crate * fix: remove value len from normal block * doc: sstable format * test: add more test * test: add test * feat: new merge iter * chore: revert * fix: rename next back * fix: rename mem sstable * fix: rename to mem * fix: use Bytes as key * fix: use simple merge iter * feat: compress option * fix: remove empty iter * style: refine some impl details * fix: large block compress * feat: use write read for encode * doc: refine doc * fix: simplify the first chunk * feat: import many times * refactor: refine styles * test: fuzz merge iter * fix: rename peek_xxx() * fix: better sstable iter inner * fix: use mem kv store * pref: mem kv store * perf: export mem kv * chore: clean --------- Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-08-30 03:44:34 +00:00
store.set(key, value.clone());
store.export_all();
store.remove(key);
assert_eq!(store.get(key), None);
}
#[test]
fn add_flush_add_scan() {
let key1 = &[0];
let value1 = Bytes::from_static(&[0]);
let key2 = &[128];
let value2 = Bytes::from_static(&[252, 169]);
let mut store = MemKvStore::new(MemKvConfig::new().should_encode_none(true));
feat: memkv export import all (#422) * feat: sstable * fix: add magic number version * feat: new mem kv store based sstable * feat: binary_search * fix: sstable iter scan * fix: new mem kv * feat: add cache for sstable * fix: encode schema comment * fix: sstable iter scan * chore: clean * fix: export all * fix: sstable scan bound * fix: sstable iter scan next==prev * fix: merge iter next_back * fix: mem kv export * chore: clean * fix: prev to key * fix: prev find block * fix: get prev block idx * refactor: kv store * fix: checksum when import * fix: meta first last key * Revert "fix: meta first last key" This reverts commit a069c1ed37f89f04e1b7a51c3a91f562819a72f5. * fix: skip empty iter * fix: remove key from large block * chore: comment * feat: compress block * fix: remove key in large block * chore: const * doc: intro sstable encode * test: add kv store fuzz * style: format file * feat: add fuzz to kv store (#428) * fix: kv fuzzer * fix: debug * bk * fix: block iter next back * fix: block prev iter left = next idx * feat: move kv store a crate * fix: remove value len from normal block * doc: sstable format * test: add more test * test: add test * feat: new merge iter * chore: revert * fix: rename next back * fix: rename mem sstable * fix: rename to mem * fix: use Bytes as key * fix: use simple merge iter * feat: compress option * fix: remove empty iter * style: refine some impl details * fix: large block compress * feat: use write read for encode * doc: refine doc * fix: simplify the first chunk * feat: import many times * refactor: refine styles * test: fuzz merge iter * fix: rename peek_xxx() * fix: better sstable iter inner * fix: use mem kv store * pref: mem kv store * perf: export mem kv * chore: clean --------- Co-authored-by: Zixuan Chen <remch183@outlook.com>
2024-08-30 03:44:34 +00:00
store.set(key1, value1.clone());
store.export_all();
store.set(key2, value2.clone());
let mut iter = store.scan(std::ops::Bound::Unbounded, std::ops::Bound::Unbounded);
assert_eq!(
iter.next(),
Some((Bytes::from_static(key1), value1.clone()))
);
assert_eq!(
iter.next(),
Some((Bytes::from_static(key2), value2.clone()))
);
assert_eq!(iter.next(), None);
let mut iter = store
.scan(std::ops::Bound::Unbounded, std::ops::Bound::Unbounded)
.rev();
assert_eq!(
iter.next(),
Some((Bytes::from_static(key2), value2.clone()))
);
assert_eq!(
iter.next(),
Some((Bytes::from_static(key1), value1.clone()))
);
assert_eq!(iter.next(), None);
}