Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 17, 2024
1 parent c9e64f0 commit bb3488b
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,12 @@ jobs:
- unsync_iters
- unsync_get
- unsync_constructor
- unsync_insert_batch
- swmr_insert
- swmr_iters
- swmr_get
- swmr_constructor
- swmr_insert_batch
- swmr_generic_insert
- swmr_generic_iters
- swmr_generic_get
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(all_tests)',
'cfg(test_unsync_constructor)',
'cfg(test_unsync_insert)',
'cfg(test_unsync_insert_batch)',
'cfg(test_unsync_iters)',
'cfg(test_unsync_get)',
'cfg(test_swmr_constructor)',
'cfg(test_swmr_insert)',
'cfg(test_swmr_insert_batch)',
'cfg(test_swmr_iters)',
'cfg(test_swmr_get)',
'cfg(test_swmr_generic_constructor)',
Expand Down
38 changes: 20 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,26 @@ const MAGIC_TEXT_SIZE: usize = MAGIC_TEXT.len();
const MAGIC_VERSION_SIZE: usize = mem::size_of::<u16>();
const HEADER_SIZE: usize = MAGIC_TEXT_SIZE + MAGIC_VERSION_SIZE;

// #[cfg(all(
// test,
// any(
// all_tests,
// test_unsync_constructor,
// test_unsync_insert,
// test_unsync_get,
// test_unsync_iters,
// test_swmr_constructor,
// test_swmr_insert,
// test_swmr_get,
// test_swmr_iters,
// test_swmr_generic_constructor,
// test_swmr_generic_insert,
// test_swmr_generic_get,
// test_swmr_generic_iters,
// )
// ))]
#[cfg(all(
test,
any(
all_tests,
test_unsync_constructor,
test_unsync_insert,
test_unsync_insert_batch,
test_unsync_get,
test_unsync_iters,
test_swmr_constructor,
test_swmr_insert,
test_swmr_insert_batch,
test_swmr_get,
test_swmr_iters,
test_swmr_generic_constructor,
test_swmr_generic_insert,
test_swmr_generic_get,
test_swmr_generic_iters,
)
))]
#[cfg(test)]
#[macro_use]
mod tests;
Expand Down
3 changes: 3 additions & 0 deletions src/swmr/wal/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ mod iter;
#[cfg(all(test, any(test_swmr_get, all_tests)))]
mod get;

#[cfg(all(test, any(test_swmr_insert_batch, all_tests)))]
mod insert_batch;

const MB: u32 = 1024 * 1024;
2 changes: 1 addition & 1 deletion src/swmr/wal/tests/constructor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use super::*;

common_unittests!(unsync::constructor::OrderWal);
common_unittests!(swmr::constructor::OrderWal);
2 changes: 1 addition & 1 deletion src/swmr/wal/tests/get.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use super::*;

common_unittests!(unsync::get::OrderWal);
common_unittests!(swmr::get::OrderWal);
2 changes: 1 addition & 1 deletion src/swmr/wal/tests/insert.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use super::*;

common_unittests!(unsync::insert::OrderWal);
common_unittests!(swmr::insert::OrderWal);
3 changes: 3 additions & 0 deletions src/swmr/wal/tests/insert_batch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use super::*;

common_unittests!(swmr::insert_batch::OrderWal);
2 changes: 1 addition & 1 deletion src/swmr/wal/tests/iter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use super::*;

common_unittests!(unsync::iters::OrderWal);
common_unittests!(swmr::iters::OrderWal);
204 changes: 187 additions & 17 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,169 @@ macro_rules! common_unittests {
}
}
};
($prefix:ident::insert_batch::$wal:ident) => {
paste::paste! {
#[test]
fn test_insert_batch_inmemory() {
insert_batch(&mut OrderWal::new(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
fn test_insert_batch_map_anon() {
insert_batch(&mut OrderWal::map_anon(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_insert_batch_map_file() {
let dir = tempdir().unwrap();
let path = dir.path().join(concat!(
"test_",
stringify!($prefix),
"_insert_batch_map_file"
));
let mut map = unsafe {
OrderWal::map_mut(
&path,
Builder::new(),
OpenOptions::new()
.create_new(Some(MB))
.write(true)
.read(true),
)
.unwrap()
};

insert_batch(&mut map);

let map = unsafe { OrderWal::map(&path, Builder::new()).unwrap() };

for i in 0..100u32 {
assert_eq!(map.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

#[test]
fn test_insert_batch_with_key_builder_inmemory() {
insert_batch(&mut OrderWal::new(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
fn test_insert_batch_with_key_builder_map_anon() {
insert_batch(&mut OrderWal::map_anon(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_insert_batch_with_key_builder_map_file() {
let dir = tempdir().unwrap();
let path = dir.path().join(concat!(
"test_",
stringify!($prefix),
"_insert_batch_with_key_builder_map_file"
));
let mut map = unsafe {
OrderWal::map_mut(
&path,
Builder::new(),
OpenOptions::new()
.create_new(Some(MB))
.write(true)
.read(true),
)
.unwrap()
};

insert_batch_with_key_builder(&mut map);

let map = unsafe { OrderWal::map(&path, Builder::new()).unwrap() };

for i in 0..100u32 {
assert_eq!(map.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

#[test]
fn test_insert_batch_with_value_builder_inmemory() {
insert_batch(&mut OrderWal::new(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
fn test_insert_batch_with_value_builder_map_anon() {
insert_batch(&mut OrderWal::map_anon(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_insert_batch_with_value_builder_map_file() {
let dir = tempdir().unwrap();
let path = dir.path().join(concat!(
"test_",
stringify!($prefix),
"_insert_batch_with_value_builder_map_file"
));
let mut map = unsafe {
OrderWal::map_mut(
&path,
Builder::new(),
OpenOptions::new()
.create_new(Some(MB))
.write(true)
.read(true),
)
.unwrap()
};

insert_batch_with_value_builder(&mut map);

let map = unsafe { OrderWal::map(&path, Builder::new()).unwrap() };

for i in 0..100u32 {
assert_eq!(map.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

#[test]
fn test_insert_batch_with_builders_inmemory() {
insert_batch_with_builders(&mut OrderWal::new(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
fn test_insert_batch_with_builders_map_anon() {
insert_batch_with_builders(&mut OrderWal::map_anon(Builder::new().with_capacity(MB)).unwrap());
}

#[test]
#[cfg_attr(miri, ignore)]
fn test_insert_batch_with_builders_map_file() {
let dir = tempdir().unwrap();
let path = dir.path().join(concat!(
"test_",
stringify!($prefix),
"_insert_batch_with_builders_map_file"
));
let mut map = unsafe {
OrderWal::map_mut(
&path,
Builder::new(),
OpenOptions::new()
.create_new(Some(MB))
.write(true)
.read(true),
)
.unwrap()
};

insert_batch_with_builders(&mut map);

let map = unsafe { OrderWal::map(&path, Builder::new()).unwrap() };

for i in 0..100u32 {
assert_eq!(map.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}
}
};
($prefix:ident::iters::$wal:ident) => {
paste::paste! {
#[test]
Expand Down Expand Up @@ -1054,86 +1217,93 @@ pub(crate) fn get_or_insert_with_value_builder<W: Wal<Ascend, Crc32>>(wal: &mut
}

pub(crate) fn insert_batch<W: Wal<Ascend, Crc32>>(wal: &mut W) {
const N: u32 = 100;

let mut batch = vec![];

for i in 0..100u32 {
for i in 0..N {
batch.push(Entry::new(i.to_be_bytes(), i.to_be_bytes()));
}

wal.insert_batch(&mut batch).unwrap();

for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}

let wal = wal.reader();
for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

pub(crate) fn insert_batch_with_key_builder<W: Wal<Ascend, Crc32>>(wal: &mut W) {
const N: u32 = 100;

let mut batch = vec![];

for i in 0..100u32 {
for i in 0..N {
batch.push(EntryWithKeyBuilder::new(
KeyBuilder::new(4, move |buf| buf.put_u32_le(i)),
KeyBuilder::new(4, move |buf| buf.put_u32_be(i)),
i.to_be_bytes(),
));
}

wal.insert_batch_with_key_builder(&mut batch).unwrap();

for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}

let wal = wal.reader();
for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

pub(crate) fn insert_batch_with_value_builder<W: Wal<Ascend, Crc32>>(wal: &mut W) {
let mut batch = vec![];
const N: u32 = 100;

for i in 0..100u32 {
let mut batch = vec![];
for i in 0..N {
batch.push(EntryWithValueBuilder::new(
i.to_be_bytes(),
ValueBuilder::new(4, move |buf| buf.put_u32_le(i)),
ValueBuilder::new(4, move |buf| buf.put_u32_be(i)),
));
}

wal.insert_batch_with_value_builder(&mut batch).unwrap();

for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}

let wal = wal.reader();
for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}

pub(crate) fn insert_batch_with_builders<W: Wal<Ascend, Crc32>>(wal: &mut W) {
const N: u32 = 100;

let mut batch = vec![];

for i in 0..100u32 {
for i in 0..N {
batch.push(EntryWithBuilders::new(
KeyBuilder::new(4, move |buf| buf.put_u32_le(i)),
ValueBuilder::new(4, move |buf| buf.put_u32_le(i)),
KeyBuilder::new(4, move |buf| buf.put_u32_be(i)),
ValueBuilder::new(4, move |buf| buf.put_u32_be(i)),
));
}

wal.insert_batch_with_builders(&mut batch).unwrap();

for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}

let wal = wal.reader();
for i in 0..100u32 {
for i in 0..N {
assert_eq!(wal.get(&i.to_be_bytes()).unwrap(), i.to_be_bytes());
}
}
Expand Down
1 change: 1 addition & 0 deletions src/unsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use c::*;
all_tests,
test_unsync_constructor,
test_unsync_insert,
test_unsync_insert_batch,
test_unsync_get,
test_unsync_iters,
)
Expand Down
3 changes: 3 additions & 0 deletions src/unsync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ mod iter;
#[cfg(all(test, any(test_unsync_get, all_tests)))]
mod get;

#[cfg(all(test, any(test_unsync_insert_batch, all_tests)))]
mod insert_batch;

const MB: u32 = 1024 * 1024;
Loading

0 comments on commit bb3488b

Please sign in to comment.