|
|
|
@ -290,12 +290,13 @@ impl <'txn> Iterator for IterDup<'txn> { |
|
|
|
|
#[cfg(test)] |
|
|
|
|
mod test { |
|
|
|
|
|
|
|
|
|
use std::{fs, ptr}; |
|
|
|
|
use std::ptr; |
|
|
|
|
use test::{Bencher, black_box}; |
|
|
|
|
|
|
|
|
|
use ffi::*; |
|
|
|
|
use tempdir::TempDir; |
|
|
|
|
|
|
|
|
|
use environment::*; |
|
|
|
|
use ffi::*; |
|
|
|
|
use flags::*; |
|
|
|
|
use super::*; |
|
|
|
|
use test_utils::*; |
|
|
|
@ -303,7 +304,7 @@ mod test { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_get() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.open_db(None).unwrap(); |
|
|
|
|
|
|
|
|
@ -313,27 +314,27 @@ mod test { |
|
|
|
|
txn.put(db, b"key3", b"val3", WriteFlags::empty()).unwrap(); |
|
|
|
|
|
|
|
|
|
let cursor = txn.open_ro_cursor(db).unwrap(); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_FIRST).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_GET_CURRENT).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val2"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val2"[..]), |
|
|
|
|
cursor.get(None, None, MDB_NEXT).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_PREV).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key3"), b"val3"), |
|
|
|
|
assert_eq!((Some(&b"key3"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_LAST).unwrap()); |
|
|
|
|
assert_eq!((None, b"val2"), |
|
|
|
|
assert_eq!((None, &b"val2"[..]), |
|
|
|
|
cursor.get(Some(b"key2"), None, MDB_SET).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key3"), b"val3"), |
|
|
|
|
cursor.get(Some(b"key3"), None, MDB_SET_KEY).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key3"), b"val3"), |
|
|
|
|
cursor.get(Some(b"key2\0"), None, MDB_SET_RANGE).unwrap()); |
|
|
|
|
assert_eq!((Some(&b"key3"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(Some(&b"key3"[..]), None, MDB_SET_KEY).unwrap()); |
|
|
|
|
assert_eq!((Some(&b"key3"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(Some(&b"key2\0"[..]), None, MDB_SET_RANGE).unwrap()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_get_dup() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.create_db(None, DUP_SORT).unwrap(); |
|
|
|
|
|
|
|
|
@ -346,40 +347,40 @@ mod test { |
|
|
|
|
txn.put(db, b"key2", b"val3", WriteFlags::empty()).unwrap(); |
|
|
|
|
|
|
|
|
|
let cursor = txn.open_ro_cursor(db).unwrap(); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_FIRST).unwrap()); |
|
|
|
|
assert_eq!((None, b"val1"), |
|
|
|
|
assert_eq!((None, &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_FIRST_DUP).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_GET_CURRENT).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_NEXT_NODUP).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val2"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val2"[..]), |
|
|
|
|
cursor.get(None, None, MDB_NEXT_DUP).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val3"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_NEXT_DUP).unwrap()); |
|
|
|
|
assert!(cursor.get(None, None, MDB_NEXT_DUP).is_err()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val2"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val2"[..]), |
|
|
|
|
cursor.get(None, None, MDB_PREV_DUP).unwrap()); |
|
|
|
|
assert_eq!((None, b"val3"), |
|
|
|
|
assert_eq!((None, &b"val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_LAST_DUP).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val3"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_PREV_NODUP).unwrap()); |
|
|
|
|
assert_eq!((None, b"val1"), |
|
|
|
|
cursor.get(Some(b"key1"), None, MDB_SET).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val1"), |
|
|
|
|
cursor.get(Some(b"key2"), None, MDB_SET_KEY).unwrap()); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val1"), |
|
|
|
|
cursor.get(Some(b"key1\0"), None, MDB_SET_RANGE).unwrap()); |
|
|
|
|
assert_eq!((None, b"val3"), |
|
|
|
|
cursor.get(Some(b"key1"), Some(b"val3"), MDB_GET_BOTH).unwrap()); |
|
|
|
|
assert_eq!((None, b"val1"), |
|
|
|
|
cursor.get(Some(b"key2"), Some(b"val"), MDB_GET_BOTH_RANGE).unwrap()); |
|
|
|
|
assert_eq!((None, &b"val1"[..]), |
|
|
|
|
cursor.get(Some(&b"key1"[..]), None, MDB_SET).unwrap()); |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(Some(&b"key2"[..]), None, MDB_SET_KEY).unwrap()); |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(Some(&b"key1\0"[..]), None, MDB_SET_RANGE).unwrap()); |
|
|
|
|
assert_eq!((None, &b"val3"[..]), |
|
|
|
|
cursor.get(Some(&b"key1"[..]), Some(&b"val3"[..]), MDB_GET_BOTH).unwrap()); |
|
|
|
|
assert_eq!((None, &b"val1"[..]), |
|
|
|
|
cursor.get(Some(&b"key2"[..]), Some(&b"val"[..]), MDB_GET_BOTH_RANGE).unwrap()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_get_dupfixed() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.create_db(None, DUP_SORT | DUP_FIXED).unwrap(); |
|
|
|
|
|
|
|
|
@ -392,20 +393,20 @@ mod test { |
|
|
|
|
txn.put(db, b"key2", b"val6", WriteFlags::empty()).unwrap(); |
|
|
|
|
|
|
|
|
|
let cursor = txn.open_ro_cursor(db).unwrap(); |
|
|
|
|
assert_eq!((Some(b"key1"), b"val1"), |
|
|
|
|
assert_eq!((Some(&b"key1"[..]), &b"val1"[..]), |
|
|
|
|
cursor.get(None, None, MDB_FIRST).unwrap()); |
|
|
|
|
assert_eq!((None, b"val1val2val3"), |
|
|
|
|
assert_eq!((None, &b"val1val2val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_GET_MULTIPLE).unwrap()); |
|
|
|
|
assert!(cursor.get(None, None, MDB_NEXT_MULTIPLE).is_err()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_iter() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.open_db(None).unwrap(); |
|
|
|
|
|
|
|
|
|
let items = vec!((b"key1", b"val1"), |
|
|
|
|
let items: Vec<(&[u8], &[u8])> = vec!((b"key1", b"val1"), |
|
|
|
|
(b"key2", b"val2"), |
|
|
|
|
(b"key3", b"val3")); |
|
|
|
|
|
|
|
|
@ -433,11 +434,11 @@ mod test { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_iter_dup() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.create_db(None, DUP_SORT).unwrap(); |
|
|
|
|
|
|
|
|
|
let items = vec!((b"a", b"1"), |
|
|
|
|
let items: Vec<(&[u8], &[u8])> = vec!((b"a", b"1"), |
|
|
|
|
(b"a", b"2"), |
|
|
|
|
(b"a", b"3"), |
|
|
|
|
(b"b", b"1"), |
|
|
|
@ -480,7 +481,7 @@ mod test { |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn test_put_del() { |
|
|
|
|
let dir = fs::TempDir::new("test").unwrap(); |
|
|
|
|
let dir = TempDir::new("test").unwrap(); |
|
|
|
|
let env = Environment::new().open(dir.path()).unwrap(); |
|
|
|
|
let db = env.open_db(None).unwrap(); |
|
|
|
|
|
|
|
|
@ -491,11 +492,11 @@ mod test { |
|
|
|
|
cursor.put(b"key2", b"val2", WriteFlags::empty()).unwrap(); |
|
|
|
|
cursor.put(b"key3", b"val3", WriteFlags::empty()).unwrap(); |
|
|
|
|
|
|
|
|
|
assert_eq!((Some(b"key3"), b"val3"), |
|
|
|
|
assert_eq!((Some(&b"key3"[..]), &b"val3"[..]), |
|
|
|
|
cursor.get(None, None, MDB_GET_CURRENT).unwrap()); |
|
|
|
|
|
|
|
|
|
cursor.del(WriteFlags::empty()).unwrap(); |
|
|
|
|
assert_eq!((Some(b"key2"), b"val2"), |
|
|
|
|
assert_eq!((Some(&b"key2"[..]), &b"val2"[..]), |
|
|
|
|
cursor.get(None, None, MDB_LAST).unwrap()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|