MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / test_batch_insert

Function test_batch_insert

tests/trees.rs:341–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

339
340 #[test]
341 fn test_batch_insert() {
342 let path = PathBuf::from_str("tests/data")
343 .unwrap()
344 .join(uuid::Uuid::new_v4().to_string())
345 .join("test.bin");
346 fs::create_dir_all(&path.parent().unwrap()).expect("Failed to create directory");
347
348 let mut tree: Tree<i32, String> = Tree::new(path).expect("Failed to create tree");
349
350 const NUM_ITEMS: usize = 10_000;
351
352 for i in 0..NUM_ITEMS {
353 tree.insert(i as i32, format!("value_{}", i))
354 .expect(format!("Failed to insert {}", i).as_str());
355 }
356
357 for i in 0..NUM_ITEMS {
358 assert_eq!(tree.search(i as i32).unwrap(), Some(format!("value_{}", i)));
359 }
360
361 let path = PathBuf::from_str("tests/data")
362 .unwrap()
363 .join(uuid::Uuid::new_v4().to_string())
364 .join("test.bin");
365
366 fs::create_dir_all(&path.parent().unwrap()).expect("Failed to create directory");
367
368 let mut tree: Tree<i32, String> = Tree::new(path).expect("Failed to create tree");
369
370 let entries: Vec<(i32, String)> = (0..NUM_ITEMS)
371 .map(|i| (i as i32, format!("value_{}", i)))
372 .collect();
373
374 tree.batch_insert(entries).expect("Failed to batch insert");
375
376 for i in 0..NUM_ITEMS {
377 assert_eq!(tree.search(i as i32).unwrap(), Some(format!("value_{}", i)));
378 }
379 }
380}

Callers

nothing calls this directly

Calls 2

insertMethod · 0.45
batch_insertMethod · 0.45

Tested by

no test coverage detected