Add volatility tests

next
Sayan Nandan 3 years ago
parent 66b9ac27af
commit 6baa61176f

@ -238,13 +238,9 @@ impl Keyspace {
pub fn get_table_atomic_ref(&self, table_identifier: ObjectID) -> Option<Arc<Table>> {
self.tables.get(&table_identifier).map(|v| v.clone())
}
/// Create a new table with **default encoding**
pub fn create_table(&self, table_identifier: ObjectID, table_type: TableType) -> bool {
self.tables.true_if_insert(table_identifier, {
match table_type {
TableType::KeyValue => Arc::new(Table::new_default_kve()),
}
})
/// Create a new table
pub fn create_table(&self, tableid: ObjectID, table: Table) -> bool {
self.tables.true_if_insert(tableid, Arc::new(table))
}
pub fn drop_table(&self, table_identifier: ObjectID) -> Result<(), DdlError> {
if table_identifier.eq(&unsafe_objectid_from_slice!("default"))
@ -273,7 +269,10 @@ impl Keyspace {
#[test]
fn test_keyspace_drop_no_atomic_ref() {
let our_keyspace = Keyspace::empty_default();
assert!(our_keyspace.create_table(unsafe_objectid_from_slice!("apps"), TableType::KeyValue));
assert!(our_keyspace.create_table(
unsafe_objectid_from_slice!("apps"),
Table::new_default_kve()
));
assert!(our_keyspace
.drop_table(unsafe_objectid_from_slice!("apps"))
.is_ok());
@ -282,7 +281,10 @@ fn test_keyspace_drop_no_atomic_ref() {
#[test]
fn test_keyspace_drop_fail_with_atomic_ref() {
let our_keyspace = Keyspace::empty_default();
assert!(our_keyspace.create_table(unsafe_objectid_from_slice!("apps"), TableType::KeyValue));
assert!(our_keyspace.create_table(
unsafe_objectid_from_slice!("apps"),
Table::new_default_kve()
));
let _atomic_tbl_ref = our_keyspace
.get_table_atomic_ref(unsafe_objectid_from_slice!("apps"))
.unwrap();

@ -24,6 +24,8 @@
*
*/
#![allow(dead_code)] // TODO(@ohsayan): Remove this once we're done
use crate::coredb::htable::Coremap;
use crate::coredb::Data;
use crate::kvengine::KVEngine;

@ -251,8 +251,10 @@ mod se {
.tables
.len())))?;
for table in keyspace.tables.iter() {
// partition ID
// partition ID len
w.write_all(raw_byte_repr(&to_64bit_little_endian!(table.key().len())))?;
// parition ID
w.write_all(table.key())?;
// now storage type
w.write_all(raw_byte_repr(&table.storage_type()))?;
}
@ -453,7 +455,7 @@ mod de {
}
#[allow(clippy::needless_return)] // Clippy really misunderstands this
unsafe fn transmute_len(start_ptr: *const u8) -> usize {
pub(super) unsafe fn transmute_len(start_ptr: *const u8) -> usize {
little_endian!({
// So we have an LE target
is_64_bit!({

@ -188,3 +188,48 @@ mod preload_tests {
assert_veceq!(de, vec!["default".to_owned()]);
}
}
mod bytemark_set_tests {
use super::*;
use crate::coredb::memstore::{Keyspace, ObjectID};
use crate::coredb::table::Table;
use std::collections::HashMap;
#[test]
fn test_bytemark_for_nonvolatile() {
let ks = Keyspace::empty_default();
let mut v = Vec::new();
se::raw_serialize_partmap(&mut v, &ks).unwrap();
let ret: HashMap<ObjectID, u8> = de::deserialize_set_ctype_bytemark(&v).unwrap();
let mut expected = HashMap::new();
unsafe {
expected.insert(ObjectID::from_slice("default"), 0);
expected.insert(ObjectID::from_slice("_system"), 0);
}
assert_hmeq!(expected, ret);
}
#[test]
fn test_bytemark_volatility_mixed() {
let ks = Keyspace::empty();
unsafe {
ks.create_table(
ObjectID::from_slice("cache"),
Table::kve_from_model_code_and_data(0, true, Coremap::new()).unwrap(),
);
ks.create_table(
ObjectID::from_slice("supersafe"),
Table::kve_from_model_code_and_data(0, false, Coremap::new()).unwrap(),
);
}
let mut v = Vec::new();
se::raw_serialize_partmap(&mut v, &ks).unwrap();
let ret: HashMap<ObjectID, u8> = de::deserialize_set_ctype_bytemark(&v).unwrap();
let mut expected = HashMap::new();
unsafe {
// our cache is volatile
expected.insert(ObjectID::from_slice("cache"), 1);
// our supersafe is non volatile
expected.insert(ObjectID::from_slice("supersafe"), 0);
}
assert_hmeq!(expected, ret);
}
}

@ -105,3 +105,17 @@ macro_rules! assert_veceq {
assert!(veceq!($v1, $v2))
};
}
#[macro_export]
macro_rules! hmeq {
($h1:expr, $h2:expr) => {
$h1.len() == $h2.len() && $h1.iter().all(|(k, v)| $h2.get(k).unwrap().eq(v))
};
}
#[macro_export]
macro_rules! assert_hmeq {
($h1:expr, $h2: expr) => {
assert!(hmeq!($h1, $h2))
};
}

Loading…
Cancel
Save