diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-10-02 12:43:30 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-10-02 12:43:30 +0300 |
| commit | 8dce4fbbaaf373a5a6c6b02e311a7d8f25cf66c3 (patch) | |
| tree | e171e1a44c357830040ca6d92521367f9dc49260 /tests | |
| parent | 7b84f3676b37a85e84b1364e5252283b16f4cb8b (diff) | |
Add test, small improvements
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/integration.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/integration.rs b/tests/integration.rs index 41c8807..3e132bc 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -231,3 +231,61 @@ fn test_log_reader_fixture_db1() { _ => false, }); } + +#[test] +#[serial] +fn test_upsert_and_get_from_secondary_memtable() { + let _ = env_logger::builder().is_test(true).try_init(); + let mut db = DB::configure() + .data_dir(TEST_DATA_DIR) + .fields(&vec![ + (Field::Id, RecordFieldType::Int), + (Field::Name, RecordFieldType::String), + (Field::Data, RecordFieldType::Bytes), + ]) + .primary_key(Field::Id) + .secondary_keys(vec![Field::Name]) + .initialize() + .expect("Failed to initialize DB instance"); + + // Insert some records + let record0 = Record { + values: vec![ + RecordValue::Int(0), + RecordValue::String("John".to_string()), + RecordValue::Bytes(vec![3, 4, 5]), + ], + }; + db.upsert(&record0).unwrap(); + + let record1 = Record { + values: vec![ + RecordValue::Int(1), + RecordValue::String("John".to_string()), + RecordValue::Bytes(vec![1, 2, 3]), + ], + }; + db.upsert(&record1).unwrap(); + + let record2 = Record { + values: vec![ + RecordValue::Int(2), + RecordValue::String("George".to_string()), + RecordValue::Bytes(vec![1, 2, 3]), + ], + }; + db.upsert(&record2).unwrap(); + + // Delete the DB so that any results must come from a memtable + fs::remove_file(Path::new(TEST_DATA_DIR).join("db")).expect("Failed to delete the DB log file"); + + // There should be 2 Johns + let johns = db + .find_all(&Field::Name, &RecordValue::String("John".to_string())) + .expect("Failed to find all Johns"); + + assert_eq!(johns.len(), 2); + + // Clean up + std::fs::remove_dir_all(TEST_DATA_DIR.to_string()).unwrap(); +} |
