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