Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: dbg! -> assert! #41

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/ondisk/sstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub(crate) mod tests {
executor::tokio::TokioExecutor,
fs::FileProvider,
record::Record,
tests::{get_test_record_batch, Test},
tests::{get_test_record_batch, Test, TestRef},
timestamp::Timestamped,
DbOption,
};
Expand Down Expand Up @@ -175,13 +175,20 @@ pub(crate) mod tests {

let key = Timestamped::new("hello".to_owned(), 1.into());

dbg!(open_sstable::<Test, TokioExecutor>(&table_path)
.await
.get(key.borrow(), ProjectionMask::all())
.await
.unwrap()
.unwrap()
.get());
assert_eq!(
open_sstable::<Test, TokioExecutor>(&table_path)
.await
.get(key.borrow(), ProjectionMask::all())
.await
.unwrap()
.unwrap()
.get(),
Some(TestRef {
vstring: "hello",
vu32: Some(12),
vbool: Some(true),
})
);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
Expand Down
90 changes: 77 additions & 13 deletions src/stream/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod tests {

use super::MergeStream;
use crate::{
executor::tokio::TokioExecutor, fs::FileProvider, inmem::mutable::Mutable,
executor::tokio::TokioExecutor, fs::FileProvider, inmem::mutable::Mutable, stream::Entry,
wal::log::LogType, DbOption,
};

Expand Down Expand Up @@ -195,12 +195,42 @@ mod tests {
.await
.unwrap();

dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "a");
assert_eq!(entry.key().ts, 1.into());
assert_eq!(entry.value().as_deref(), Some("a"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "b");
assert_eq!(entry.key().ts, 3.into());
assert!(entry.value().is_none());
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "c");
assert_eq!(entry.key().ts, 4.into());
assert_eq!(entry.value().as_deref(), Some("c"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "d");
assert_eq!(entry.key().ts, 5.into());
assert_eq!(entry.value().as_deref(), Some("d"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "e");
assert_eq!(entry.key().ts, 4.into());
assert_eq!(entry.value().as_deref(), Some("e"));
} else {
unreachable!()
}
assert!(merge.next().await.is_none());
}

#[tokio::test]
Expand Down Expand Up @@ -238,9 +268,25 @@ mod tests {
.await
.unwrap();

dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "1");
assert_eq!(entry.key().ts, 0.into());
assert_eq!(entry.value().as_deref(), Some("1"));
};
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "2");
assert_eq!(entry.key().ts, 1.into());
assert_eq!(entry.value().as_deref(), Some("2"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "3");
assert_eq!(entry.key().ts, 1.into());
assert_eq!(entry.value().as_deref(), Some("3"));
} else {
unreachable!()
}

let lower = "1".to_string();
let upper = "4".to_string();
Expand All @@ -250,8 +296,26 @@ mod tests {
.await
.unwrap();

dbg!(merge.next().await);
dbg!(merge.next().await);
dbg!(merge.next().await);
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "1");
assert_eq!(entry.key().ts, 0.into());
assert_eq!(entry.value().as_deref(), Some("1"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "2");
assert_eq!(entry.key().ts, 1.into());
assert_eq!(entry.value().as_deref(), Some("2"));
} else {
unreachable!()
}
if let Some(Ok(Entry::Mutable(entry))) = merge.next().await {
assert_eq!(entry.key().value, "3");
assert_eq!(entry.key().ts, 1.into());
assert_eq!(entry.value().as_deref(), Some("3"));
} else {
unreachable!()
};
}
}
23 changes: 20 additions & 3 deletions src/stream/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ where

#[cfg(test)]
mod tests {
use std::collections::Bound;
use std::{collections::Bound, sync::Arc};

use arrow::array::{BooleanArray, RecordBatch, StringArray, UInt32Array};
use futures_util::StreamExt;
use tempfile::TempDir;

Expand All @@ -94,6 +95,7 @@ mod tests {
immutable::{tests::TestImmutableArrays, ArrowArrays},
mutable::Mutable,
},
record::Record,
stream::{merge::MergeStream, package::PackageStream},
tests::Test,
wal::log::LogType,
Expand Down Expand Up @@ -188,9 +190,24 @@ mod tests {
batch_size: 8192,
inner: merge,
builder: TestImmutableArrays::builder(8192),
projection_indices: Some(projection_indices),
projection_indices: Some(projection_indices.clone()),
};

dbg!(package.next().await);
let arrays = package.next().await.unwrap().unwrap();
assert_eq!(
arrays.as_record_batch(),
&RecordBatch::try_new(
Arc::new(Test::arrow_schema().project(&projection_indices).unwrap(),),
vec![
Arc::new(BooleanArray::from(vec![
false, false, false, false, false, false
])),
Arc::new(UInt32Array::from(vec![0, 1, 2, 3, 4, 5])),
Arc::new(StringArray::from(vec!["a", "b", "c", "d", "e", "f"])),
Arc::new(UInt32Array::from(vec![0, 1, 2, 3, 4, 5])),
],
)
.unwrap()
)
}
}
6 changes: 3 additions & 3 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
txn1.insert("foo".to_string());

let txn2 = db.transaction().await;
dbg!(txn2
assert!(txn2
.get(&"foo".to_string(), Projection::All)
.await
.unwrap()
Expand All @@ -260,11 +260,11 @@ mod tests {

{
let txn3 = db.transaction().await;
dbg!(txn3
assert!(txn3
.get(&"foo".to_string(), Projection::All)
.await
.unwrap()
.is_none());
.is_some());
txn3.commit().await.unwrap();
}
}
Expand Down
Loading