use stdlib TempDir

without.crypto
Dan Burkert 10 years ago
parent 71ea09c938
commit 735bd511c9
  1. 1
      Cargo.toml
  2. 15
      src/cursor.rs
  3. 14
      src/environment.rs
  4. 9
      src/lib.rs
  5. 19
      src/transaction.rs

@ -23,5 +23,4 @@ version = "0.3.0"
bitflags = "*" bitflags = "*"
[dev-dependencies] [dev-dependencies]
tempdir = "*"
rand = "*" rand = "*"

@ -291,7 +291,7 @@ impl <'txn> Iterator for IterDup<'txn> {
mod test { mod test {
use std::old_io as io; use std::old_io as io;
use std::ptr; use std::{fs, ptr};
use test::{Bencher, black_box}; use test::{Bencher, black_box};
use ffi::*; use ffi::*;
@ -299,13 +299,12 @@ mod test {
use environment::*; use environment::*;
use flags::*; use flags::*;
use super::*; use super::*;
use tempdir;
use test_utils::*; use test_utils::*;
use transaction::*; use transaction::*;
#[test] #[test]
fn test_get() { fn test_get() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -335,7 +334,7 @@ mod test {
#[test] #[test]
fn test_get_dup() { fn test_get_dup() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.create_db(None, DUP_SORT).unwrap(); let db = env.create_db(None, DUP_SORT).unwrap();
@ -381,7 +380,7 @@ mod test {
#[test] #[test]
fn test_get_dupfixed() { fn test_get_dupfixed() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.create_db(None, DUP_SORT | DUP_FIXED).unwrap(); let db = env.create_db(None, DUP_SORT | DUP_FIXED).unwrap();
@ -403,7 +402,7 @@ mod test {
#[test] #[test]
fn test_iter() { fn test_iter() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -435,7 +434,7 @@ mod test {
#[test] #[test]
fn test_iter_dup() { fn test_iter_dup() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.create_db(None, DUP_SORT).unwrap(); let db = env.create_db(None, DUP_SORT).unwrap();
@ -482,7 +481,7 @@ mod test {
#[test] #[test]
fn test_put_del() { fn test_put_del() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();

@ -243,15 +243,15 @@ impl EnvironmentBuilder {
mod test { mod test {
use std::old_io as io; use std::old_io as io;
use std::fs;
use flags::*; use flags::*;
use tempdir;
use super::*; use super::*;
#[test] #[test]
fn test_open() { fn test_open() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
// opening non-existent env with read-only should fail // opening non-existent env with read-only should fail
assert!(Environment::new().set_flags(READ_ONLY) assert!(Environment::new().set_flags(READ_ONLY)
@ -269,7 +269,7 @@ mod test {
#[test] #[test]
fn test_begin_txn() { fn test_begin_txn() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
{ // writable environment { // writable environment
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
@ -290,7 +290,7 @@ mod test {
#[test] #[test]
fn test_open_db() { fn test_open_db() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(1) let env = Environment::new().set_max_dbs(1)
.open(dir.path(), io::USER_RWX) .open(dir.path(), io::USER_RWX)
.unwrap(); .unwrap();
@ -301,7 +301,7 @@ mod test {
#[test] #[test]
fn test_create_db() { fn test_create_db() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(11) let env = Environment::new().set_max_dbs(11)
.open(dir.path(), io::USER_RWX) .open(dir.path(), io::USER_RWX)
.unwrap(); .unwrap();
@ -312,7 +312,7 @@ mod test {
#[test] #[test]
fn test_close_database() { fn test_close_database() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let mut env = Environment::new().set_max_dbs(10) let mut env = Environment::new().set_max_dbs(10)
.open(dir.path(), io::USER_RWX) .open(dir.path(), io::USER_RWX)
.unwrap(); .unwrap();
@ -324,7 +324,7 @@ mod test {
#[test] #[test]
fn test_sync() { fn test_sync() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
{ {
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
assert!(env.sync(true).is_ok()); assert!(env.sync(true).is_ok());

@ -2,13 +2,12 @@
//! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/). //! [Symas Lightning Memory-Mapped Database (LMDB)](http://symas.com/mdb/).
#![feature(core, libc, old_io, optin_builtin_traits, path, std_misc, unsafe_destructor)] #![feature(core, libc, old_io, optin_builtin_traits, path, std_misc, unsafe_destructor)]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(fs, tempdir, test))]
extern crate libc; extern crate libc;
extern crate "lmdb-sys" as ffi; extern crate "lmdb-sys" as ffi;
#[cfg(test)] extern crate rand; #[cfg(test)] extern crate rand;
#[cfg(test)] extern crate tempdir;
#[cfg(test)] extern crate test; #[cfg(test)] extern crate test;
#[macro_use] extern crate bitflags; #[macro_use] extern crate bitflags;
@ -63,7 +62,7 @@ mod test_utils {
use std::old_io as io; use std::old_io as io;
use tempdir; use std::fs;
use super::*; use super::*;
@ -75,8 +74,8 @@ mod test_utils {
format!("data{}", n) format!("data{}", n)
} }
pub fn setup_bench_db<'a>(num_rows: u32) -> (tempdir::TempDir, Environment) { pub fn setup_bench_db<'a>(num_rows: u32) -> (fs::TempDir, Environment) {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
{ {

@ -363,7 +363,7 @@ impl <'env> Transaction<'env> for RwTransaction<'env> {
mod test { mod test {
use std::old_io as io; use std::old_io as io;
use std::ptr; use std::{fs, ptr};
use rand::{Rng, XorShiftRng}; use rand::{Rng, XorShiftRng};
use std::sync::{Arc, Barrier, Future}; use std::sync::{Arc, Barrier, Future};
use test::{Bencher, black_box}; use test::{Bencher, black_box};
@ -374,12 +374,11 @@ mod test {
use error::*; use error::*;
use flags::*; use flags::*;
use super::*; use super::*;
use tempdir;
use test_utils::*; use test_utils::*;
#[test] #[test]
fn test_put_get_del() { fn test_put_get_del() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -401,7 +400,7 @@ mod test {
#[test] #[test]
fn test_reserve() { fn test_reserve() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -422,7 +421,7 @@ mod test {
#[test] #[test]
fn test_inactive_txn() { fn test_inactive_txn() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -440,7 +439,7 @@ mod test {
#[test] #[test]
fn test_nested_txn() { fn test_nested_txn() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -460,7 +459,7 @@ mod test {
#[test] #[test]
fn test_clear_db() { fn test_clear_db() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap(); let env = Environment::new().open(dir.path(), io::USER_RWX).unwrap();
let db = env.open_db(None).unwrap(); let db = env.open_db(None).unwrap();
@ -483,7 +482,7 @@ mod test {
#[test] #[test]
fn test_drop_db() { fn test_drop_db() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Environment::new().set_max_dbs(2) let env = Environment::new().set_max_dbs(2)
.open(dir.path(), io::USER_RWX).unwrap(); .open(dir.path(), io::USER_RWX).unwrap();
let db = env.create_db(Some("test"), DatabaseFlags::empty()).unwrap(); let db = env.create_db(Some("test"), DatabaseFlags::empty()).unwrap();
@ -504,7 +503,7 @@ mod test {
#[test] #[test]
fn test_concurrent_readers_single_writer() { fn test_concurrent_readers_single_writer() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env: Arc<Environment> = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap()); let env: Arc<Environment> = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap());
let n = 10usize; // Number of concurrent readers let n = 10usize; // Number of concurrent readers
@ -546,7 +545,7 @@ mod test {
#[test] #[test]
fn test_concurrent_writers() { fn test_concurrent_writers() {
let dir = tempdir::TempDir::new("test").unwrap(); let dir = fs::TempDir::new("test").unwrap();
let env = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap()); let env = Arc::new(Environment::new().open(dir.path(), io::USER_RWX).unwrap());
let n = 10usize; // Number of concurrent writers let n = 10usize; // Number of concurrent writers

Loading…
Cancel
Save