Skip to content

Commit

Permalink
rebase to make CI happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ncloudioj committed Jul 27, 2018
1 parent efabffd commit 3de0b57
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ impl Rkv {
/// opens the given database by using a read transaction, which means other
/// in-flight write transaction will not block this call. This is preferred
/// to be used in the read_only scenarios.
pub fn open<'s, T, K>(&self, name: T) -> Result<Store<K>, StoreError>
pub fn open<'s, T>(&self, name: T) -> Result<Store, StoreError>
where
T: Into<Option<&'s str>>,
K: AsRef<[u8]>,
{
let db = self.env.open_db(name.into()).map_err(|e| match e {
lmdb::Error::BadRslot => StoreError::open_during_transaction(),
Expand Down Expand Up @@ -340,17 +339,17 @@ mod tests {
fs::create_dir_all(root.path()).expect("dir created");
let k = Rkv::new(root.path()).expect("new succeeded");
// First create the store, and start a write transaction on it.
let sk: Store<&str> = k.open_or_create("sk").expect("opened");
let mut writer = sk.write(&k).expect("writer");
writer.put("foo", &Value::Str("bar")).expect("write");
let sk = k.open_or_create("sk").expect("opened");
let mut writer = k.write().expect("writer");
writer.put(&sk, "foo", &Value::Str("bar")).expect("write");

// Open the same store for read, note that the write transaction is still in progress,
// it should not block the reader though.
let sk_readonly: Store<&str> = k.open("sk").expect("opened");
let sk_readonly = k.open("sk").expect("opened");
writer.commit().expect("commit");
// Now the write transaction is committed, any followed reads should see its change.
let reader = sk_readonly.read(&k).expect("reader");
assert_eq!(reader.get("foo").expect("read"), Some(Value::Str("bar")));
let reader = k.read().expect("reader");
assert_eq!(reader.get(&sk_readonly, "foo").expect("read"), Some(Value::Str("bar")));
}

#[test]
Expand All @@ -359,7 +358,7 @@ mod tests {
let root = Builder::new().prefix("test_open_a_missing_store").tempdir().expect("tempdir");
fs::create_dir_all(root.path()).expect("dir created");
let k = Rkv::new(root.path()).expect("new succeeded");
let _sk: Store<&str> = k.open("sk").expect("open a missing store");
let _sk = k.open("sk").expect("open a missing store");
}

#[test]
Expand All @@ -368,11 +367,11 @@ mod tests {
fs::create_dir_all(root.path()).expect("dir created");
let k = Rkv::new(root.path()).expect("new succeeded");
// First create the store
let sk: Store<&str> = k.open_or_create("sk").expect("opened");
let _sk = k.open_or_create("sk").expect("opened");
// Open a reader on this store
let _reader = sk.read(&k).expect("reader");
let _reader = k.read::<&str>().expect("reader");
// Open the same store for read while the reader is in progress will panic
let store: Result<Store<&str>, StoreError> = k.open("sk");
let store: Result<Store, StoreError> = k.open("sk");
match store {
Err(StoreError::OpenAttemptedDuringTransaction(_thread_id)) => assert!(true),
_ => panic!("should panic"),
Expand Down

0 comments on commit 3de0b57

Please sign in to comment.