loro/crates/fuzz/tests/kv.rs
Leon Zhao c1620fdb37
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 a069c1ed37.

* 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 11:44:34 +08:00

168 lines
3.1 KiB
Rust

use fuzz::{kv_minify_simple, test_mem_kv_fuzzer, KVAction::*};
#[ctor::ctor]
fn init() {
dev_utils::setup_test_log();
}
#[test]
fn add_same_key_twice() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![],
value: vec![254],
},
Flush,
Add {
key: vec![],
value: vec![],
},
])
}
#[test]
fn add_and_remove() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![],
value: vec![238],
},
Remove(0),
])
}
#[test]
fn add_flush_remove() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![],
value: vec![],
},
Flush,
Remove(3791655167),
])
}
#[test]
fn export_and_import() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![],
value: vec![],
},
ExportAndImport,
])
}
#[test]
fn add_flush_add_scan() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![],
value: vec![],
},
Flush,
Add {
key: vec![128],
value: vec![252, 169],
},
Scan {
start: 12249507989402000797,
end: 18231419743747221929,
start_include: true,
end_include: true,
},
])
}
#[test]
fn add_some() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![255, 255, 255, 255, 63],
value: vec![],
},
Add {
key: vec![255, 3],
value: vec![255],
},
Add {
key: vec![255],
value: vec![],
},
Add {
key: vec![],
value: vec![],
},
Flush,
Scan {
start: 18446744073709551615,
end: 18446744073709551615,
start_include: true,
end_include: true,
},
])
}
#[test]
fn merge_import() {
test_mem_kv_fuzzer(&mut [
Add {
key: vec![205, 197, 255, 12],
value: vec![0, 0, 9],
},
Add {
key: vec![],
value: vec![],
},
Flush,
Add {
key: vec![57],
value: vec![209, 3, 255, 174, 0, 255],
},
Add {
key: vec![41],
value: vec![209, 0, 41, 63, 205],
},
Add {
key: vec![0, 0],
value: vec![1],
},
ExportAndImport,
Flush,
ExportAndImport,
Remove(14829789716734785489),
Remove(13191005920967349589),
ExportAndImport,
ExportAndImport,
Get(13238251090391746632),
Add {
key: vec![],
value: vec![],
},
])
}
#[test]
fn scan_empty() {
test_mem_kv_fuzzer(&mut [
Add{
key: vec![0, 255],
value: vec![]
},
Add{
key: vec![],
value: vec![]
},
Scan{
start: 129,
end: 0,
start_include: false,
end_include: false
},
])
}
#[test]
fn minify() {
kv_minify_simple(test_mem_kv_fuzzer, vec![])
}