fune/third_party/rust/rkv-0.10.4/tests/multi-integer-store.rs
Emilio Cobos Álvarez 0a80ad4a85 Bug 1621044 - Lockfile changes and revendoring. r=jrmuizel
This updates binjs_meta and thus weedle, bindgen and thus clang-sys
transitively, and the mime / mime_guess crate and thus unicase and
version-check.

Differential Revision: https://phabricator.services.mozilla.com/D66282

--HG--
rename : third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb/lock.mdb => third_party/rust/lmdb-rkv-sys/tests/fixtures/testdb-32/lock.mdb
rename : third_party/rust/mime_guess/Cargo.lock => third_party/rust/nom/Cargo.lock
rename : third_party/rust/nom/src/branch.rs => third_party/rust/nom/src/branch/macros.rs
rename : third_party/rust/nom/src/sequence.rs => third_party/rust/nom/src/sequence/macros.rs
rename : third_party/rust/rkv-0.10.2/.cargo-checksum.json => third_party/rust/rkv-0.10.4/.cargo-checksum.json
rename : third_party/rust/rkv-0.10.2/CODE_OF_CONDUCT.md => third_party/rust/rkv-0.10.4/CODE_OF_CONDUCT.md
rename : third_party/rust/rkv-0.10.2/Cargo.toml => third_party/rust/rkv-0.10.4/Cargo.toml
rename : third_party/rust/rkv-0.10.2/LICENSE => third_party/rust/rkv-0.10.4/LICENSE
rename : third_party/rust/rkv-0.10.2/examples/README.md => third_party/rust/rkv-0.10.4/examples/README.md
rename : third_party/rust/rkv-0.10.2/examples/iterator.rs => third_party/rust/rkv-0.10.4/examples/iterator.rs
rename : third_party/rust/rkv-0.10.2/examples/simple-store.rs => third_party/rust/rkv-0.10.4/examples/simple-store.rs
rename : third_party/rust/rkv-0.10.2/run-all-examples.sh => third_party/rust/rkv-0.10.4/run-all-examples.sh
rename : third_party/rust/rkv-0.10.2/src/bin/dump.rs => third_party/rust/rkv-0.10.4/src/bin/dump.rs
rename : third_party/rust/rkv-0.10.2/src/bin/rand.rs => third_party/rust/rkv-0.10.4/src/bin/rand.rs
rename : third_party/rust/rkv-0.10.2/src/env.rs => third_party/rust/rkv-0.10.4/src/env.rs
rename : third_party/rust/rkv-0.10.2/src/error.rs => third_party/rust/rkv-0.10.4/src/error.rs
rename : third_party/rust/rkv-0.10.2/src/lib.rs => third_party/rust/rkv-0.10.4/src/lib.rs
rename : third_party/rust/rkv-0.10.2/src/manager.rs => third_party/rust/rkv-0.10.4/src/manager.rs
rename : third_party/rust/rkv-0.10.2/src/migrate.rs => third_party/rust/rkv-0.10.4/src/migrate.rs
rename : third_party/rust/rkv-0.10.2/src/readwrite.rs => third_party/rust/rkv-0.10.4/src/readwrite.rs
rename : third_party/rust/rkv-0.10.2/src/store.rs => third_party/rust/rkv-0.10.4/src/store.rs
rename : third_party/rust/rkv-0.10.2/src/store/integer.rs => third_party/rust/rkv-0.10.4/src/store/integer.rs
rename : third_party/rust/rkv-0.10.2/src/store/integermulti.rs => third_party/rust/rkv-0.10.4/src/store/integermulti.rs
rename : third_party/rust/rkv-0.10.2/src/store/multi.rs => third_party/rust/rkv-0.10.4/src/store/multi.rs
rename : third_party/rust/rkv-0.10.2/src/store/single.rs => third_party/rust/rkv-0.10.4/src/store/single.rs
rename : third_party/rust/rkv-0.10.2/src/value.rs => third_party/rust/rkv-0.10.4/src/value.rs
rename : third_party/rust/rkv-0.10.2/tests/integer-store.rs => third_party/rust/rkv-0.10.4/tests/integer-store.rs
rename : third_party/rust/rkv-0.10.2/tests/manager.rs => third_party/rust/rkv-0.10.4/tests/manager.rs
rename : third_party/rust/rkv-0.10.2/tests/multi-integer-store.rs => third_party/rust/rkv-0.10.4/tests/multi-integer-store.rs
rename : third_party/rust/rkv-0.10.2/tests/test_txn.rs => third_party/rust/rkv-0.10.4/tests/test_txn.rs
extra : moz-landing-system : lando
2020-03-10 21:06:36 +00:00

91 lines
3.5 KiB
Rust

// Copyright 2018 Mozilla
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
use rkv::{
PrimitiveInt,
Rkv,
StoreOptions,
Value,
};
use serde_derive::Serialize;
use std::fs;
use tempfile::Builder;
#[test]
fn test_multi_integer_keys() {
let root = Builder::new().prefix("test_integer_keys").tempdir().expect("tempdir");
fs::create_dir_all(root.path()).expect("dir created");
let k = Rkv::new(root.path()).expect("new succeeded");
let s = k.open_multi_integer("s", StoreOptions::create()).expect("open");
macro_rules! test_integer_keys {
($store:expr, $key:expr) => {{
let mut writer = k.write().expect("writer");
$store.put(&mut writer, $key, &Value::Str("hello1")).expect("write");
$store.put(&mut writer, $key, &Value::Str("hello2")).expect("write");
$store.put(&mut writer, $key, &Value::Str("hello3")).expect("write");
let vals = $store
.get(&writer, $key)
.expect("read")
.map(|result| result.expect("ok"))
.map(|(_, v)| v.expect("multi read"))
.collect::<Vec<Value>>();
assert_eq!(vals, vec![Value::Str("hello1"), Value::Str("hello2"), Value::Str("hello3")]);
writer.commit().expect("committed");
let reader = k.read().expect("reader");
let vals = $store
.get(&reader, $key)
.expect("read")
.map(|result| result.expect("ok"))
.map(|(_, v)| v.expect("multi read"))
.collect::<Vec<Value>>();
assert_eq!(vals, vec![Value::Str("hello1"), Value::Str("hello2"), Value::Str("hello3")]);
}};
}
// The integer module provides only the u32 integer key variant
// of IntegerStore, so we can use it without further ado.
test_integer_keys!(s, std::u32::MIN);
test_integer_keys!(s, std::u32::MAX);
// If you want to use another integer key variant, you need to implement
// a newtype, implement PrimitiveInt, and implement or derive Serialize
// for it. Here we do so for the i32 type.
// DANGER! Doing this enables you to open a store with multiple,
// different integer key types, which may result in unexpected behavior.
// Make sure you know what you're doing!
let t = k.open_multi_integer("s", StoreOptions::create()).expect("open");
#[derive(Serialize)]
struct I32(i32);
impl PrimitiveInt for I32 {}
test_integer_keys!(t, I32(std::i32::MIN));
test_integer_keys!(t, I32(std::i32::MAX));
let u = k.open_multi_integer("s", StoreOptions::create()).expect("open");
#[derive(Serialize)]
struct U16(u16);
impl PrimitiveInt for U16 {}
test_integer_keys!(u, U16(std::u16::MIN));
test_integer_keys!(u, U16(std::u16::MAX));
let v = k.open_multi_integer("s", StoreOptions::create()).expect("open");
#[derive(Serialize)]
struct U64(u64);
impl PrimitiveInt for U64 {}
test_integer_keys!(v, U64(std::u64::MIN));
test_integer_keys!(v, U64(std::u64::MAX));
}