Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
51a1588b
Commit
51a1588b
authored
Mar 05, 2016
by
Jay Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use test mod instead
parent
47329cae
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
29 deletions
+53
-29
ffi.rs
src/ffi.rs
+9
-3
main.rs
src/main.rs
+1
-0
merge_operator.rs
src/merge_operator.rs
+18
-13
rocksdb.rs
src/rocksdb.rs
+21
-13
test_column_family.rs
test/test_column_family.rs
+4
-0
No files found.
src/ffi.rs
View file @
51a1588b
...
@@ -411,10 +411,15 @@ extern "C" {
...
@@ -411,10 +411,15 @@ extern "C" {
}
}
#[test]
#[cfg(test)]
fn
internal
()
{
mod
test
{
unsafe
{
use
super
::
*
;
use
libc
::
*
;
use
std
::
ffi
::
CString
;
use
std
::
ffi
::
CString
;
#[test]
fn
internal
()
{
unsafe
{
let
opts
=
rocksdb_options_create
();
let
opts
=
rocksdb_options_create
();
assert
!
(
!
opts
.
0
.is_null
());
assert
!
(
!
opts
.
0
.is_null
());
...
@@ -466,4 +471,5 @@ fn internal() {
...
@@ -466,4 +471,5 @@ fn internal() {
rocksdb_destroy_db
(
opts
,
cpath_ptr
,
err_ptr
);
rocksdb_destroy_db
(
opts
,
cpath_ptr
,
err_ptr
);
assert
!
(
err
.is_null
());
assert
!
(
err
.is_null
());
}
}
}
}
}
src/main.rs
View file @
51a1588b
...
@@ -146,6 +146,7 @@ mod tests {
...
@@ -146,6 +146,7 @@ mod tests {
use
rocksdb
::{
BlockBasedOptions
,
DB
,
Options
};
use
rocksdb
::{
BlockBasedOptions
,
DB
,
Options
};
use
rocksdb
::
DBCompactionStyle
::
DBUniversalCompaction
;
use
rocksdb
::
DBCompactionStyle
::
DBUniversalCompaction
;
#[allow(dead_code)]
fn
tuned_for_somebody_elses_disk
(
path
:
&
str
,
fn
tuned_for_somebody_elses_disk
(
path
:
&
str
,
opts
:
&
mut
Options
,
opts
:
&
mut
Options
,
blockopts
:
&
mut
BlockBasedOptions
)
blockopts
:
&
mut
BlockBasedOptions
)
...
...
src/merge_operator.rs
View file @
51a1588b
...
@@ -151,9 +151,15 @@ impl<'a> Iterator for &'a mut MergeOperands {
...
@@ -151,9 +151,15 @@ impl<'a> Iterator for &'a mut MergeOperands {
}
}
}
}
#[allow(unused_variables)]
#[cfg(test)]
#[allow(dead_code)]
mod
test
{
fn
test_provided_merge
(
new_key
:
&
[
u8
],
use
super
::
*
;
use
rocksdb_options
::
Options
;
use
rocksdb
::{
DB
,
DBVector
,
Writable
};
#[allow(unused_variables)]
#[allow(dead_code)]
fn
test_provided_merge
(
new_key
:
&
[
u8
],
existing_val
:
Option
<&
[
u8
]
>
,
existing_val
:
Option
<&
[
u8
]
>
,
operands
:
&
mut
MergeOperands
)
operands
:
&
mut
MergeOperands
)
->
Vec
<
u8
>
{
->
Vec
<
u8
>
{
...
@@ -173,15 +179,11 @@ fn test_provided_merge(new_key: &[u8],
...
@@ -173,15 +179,11 @@ fn test_provided_merge(new_key: &[u8],
}
}
}
}
result
result
}
}
#[allow(dead_code)]
#[test]
fn
mergetest
()
{
use
rocksdb_options
::
Options
;
use
rocksdb
::{
DB
,
DBVector
,
Writable
};
#[allow(dead_code)]
#[test]
fn
mergetest
()
{
let
path
=
"_rust_rocksdb_mergetest"
;
let
path
=
"_rust_rocksdb_mergetest"
;
let
mut
opts
=
Options
::
new
();
let
mut
opts
=
Options
::
new
();
opts
.create_if_missing
(
true
);
opts
.create_if_missing
(
true
);
...
@@ -200,10 +202,12 @@ fn mergetest() {
...
@@ -200,10 +202,12 @@ fn mergetest() {
Ok
(
Some
(
value
))
=>
{
Ok
(
Some
(
value
))
=>
{
match
value
.to_utf8
()
{
match
value
.to_utf8
()
{
Some
(
v
)
=>
println!
(
"retrieved utf8 value: {}"
,
v
),
Some
(
v
)
=>
println!
(
"retrieved utf8 value: {}"
,
v
),
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
None
=>
{
println!
(
"did not read valid utf-8 out of the db"
)
}
}
}
}
Err
(
e
)
=>
println!
(
"error reading value"
),
}
Err
(
e
)
=>
println!
(
"error reading value {:?}"
,
e
),
_
=>
panic!
(
"value not present"
),
_
=>
panic!
(
"value not present"
),
}
}
...
@@ -214,4 +218,5 @@ fn mergetest() {
...
@@ -214,4 +218,5 @@ fn mergetest() {
assert
!
(
db
.get
(
b
"k1"
)
.unwrap
()
.is_none
());
assert
!
(
db
.get
(
b
"k1"
)
.unwrap
()
.is_none
());
}
}
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
}
}
}
src/rocksdb.rs
View file @
51a1588b
...
@@ -863,8 +863,14 @@ impl DBVector {
...
@@ -863,8 +863,14 @@ impl DBVector {
}
}
}
}
#[test]
#[cfg(test)]
fn
external
()
{
mod
test
{
use
super
::
*
;
use
rocksdb_options
::
*
;
use
std
::
str
;
#[test]
fn
external
()
{
let
path
=
"_rust_rocksdb_externaltest"
;
let
path
=
"_rust_rocksdb_externaltest"
;
{
{
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
...
@@ -878,10 +884,11 @@ fn external() {
...
@@ -878,10 +884,11 @@ fn external() {
let
opts
=
Options
::
new
();
let
opts
=
Options
::
new
();
let
result
=
DB
::
destroy
(
&
opts
,
path
);
let
result
=
DB
::
destroy
(
&
opts
,
path
);
assert
!
(
result
.is_ok
());
assert
!
(
result
.is_ok
());
}
}
#[test]
#[allow(unused_variables)]
fn
errors_do_stuff
()
{
#[test]
fn
errors_do_stuff
()
{
let
path
=
"_rust_rocksdb_error"
;
let
path
=
"_rust_rocksdb_error"
;
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
opts
=
Options
::
new
();
let
opts
=
Options
::
new
();
...
@@ -894,10 +901,10 @@ fn errors_do_stuff() {
...
@@ -894,10 +901,10 @@ fn errors_do_stuff() {
}
}
Ok
(
_
)
=>
panic!
(
"should fail"
),
Ok
(
_
)
=>
panic!
(
"should fail"
),
}
}
}
}
#[test]
#[test]
fn
writebatch_works
()
{
fn
writebatch_works
()
{
let
path
=
"_rust_rocksdb_writebacktest"
;
let
path
=
"_rust_rocksdb_writebacktest"
;
{
{
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
...
@@ -923,10 +930,10 @@ fn writebatch_works() {
...
@@ -923,10 +930,10 @@ fn writebatch_works() {
}
}
let
opts
=
Options
::
new
();
let
opts
=
Options
::
new
();
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
}
}
#[test]
#[test]
fn
iterator_test
()
{
fn
iterator_test
()
{
let
path
=
"_rust_rocksdb_iteratortest"
;
let
path
=
"_rust_rocksdb_iteratortest"
;
{
{
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
let
db
=
DB
::
open_default
(
path
)
.unwrap
();
...
@@ -939,10 +946,11 @@ fn iterator_test() {
...
@@ -939,10 +946,11 @@ fn iterator_test() {
let
iter
=
db
.iterator
(
IteratorMode
::
Start
);
let
iter
=
db
.iterator
(
IteratorMode
::
Start
);
for
(
k
,
v
)
in
iter
{
for
(
k
,
v
)
in
iter
{
println!
(
"Hello {}: {}"
,
println!
(
"Hello {}: {}"
,
from_utf8
(
&*
k
)
.unwrap
(),
str
::
from_utf8
(
&*
k
)
.unwrap
(),
from_utf8
(
&*
v
)
.unwrap
());
str
::
from_utf8
(
&*
v
)
.unwrap
());
}
}
}
}
let
opts
=
Options
::
new
();
let
opts
=
Options
::
new
();
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
assert
!
(
DB
::
destroy
(
&
opts
,
path
)
.is_ok
());
}
}
}
test/test_column_family.rs
View file @
51a1588b
...
@@ -76,6 +76,9 @@ pub fn test_column_family() {
...
@@ -76,6 +76,9 @@ pub fn test_column_family() {
"v1"
);
"v1"
);
let
p
=
db
.put_cf
(
cf1
,
b
"k1"
,
b
"a"
);
let
p
=
db
.put_cf
(
cf1
,
b
"k1"
,
b
"a"
);
assert
!
(
p
.is_ok
());
assert
!
(
p
.is_ok
());
/*
// TODO support family merge operator
// have not finished yet, following codes won't work.
db.merge_cf(cf1, b"k1", b"b").unwrap();
db.merge_cf(cf1, b"k1", b"b").unwrap();
db.merge_cf(cf1, b"k1", b"c").unwrap();
db.merge_cf(cf1, b"k1", b"c").unwrap();
db.merge_cf(cf1, b"k1", b"d").unwrap();
db.merge_cf(cf1, b"k1", b"d").unwrap();
...
@@ -98,6 +101,7 @@ pub fn test_column_family() {
...
@@ -98,6 +101,7 @@ pub fn test_column_family() {
// TODO assert!(r.unwrap().to_utf8().unwrap() == "abcdefgh");
// TODO assert!(r.unwrap().to_utf8().unwrap() == "abcdefgh");
assert!(db.delete(b"k1").is_ok());
assert!(db.delete(b"k1").is_ok());
assert!(db.get(b"k1").unwrap().is_none());
assert!(db.get(b"k1").unwrap().is_none());
*/
}
}
// TODO should be able to use writebatch ops with a cf
// TODO should be able to use writebatch ops with a cf
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment