Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
be905491
R
rocksdb
项目概览
kvdb
/
rocksdb
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rocksdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
be905491
编写于
12月 19, 2014
作者:
A
Adam Retter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test for WriteBatchWithIndex#newIteratorWithBase(org.rocksdb.RocksIterator)
上级
2241e3f4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
114 addition
and
0 deletion
+114
-0
java/Makefile
java/Makefile
+1
-0
java/org/rocksdb/test/WriteBatchWithIndexTest.java
java/org/rocksdb/test/WriteBatchWithIndexTest.java
+113
-0
未找到文件。
java/Makefile
浏览文件 @
be905491
...
...
@@ -81,6 +81,7 @@ JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
org.rocksdb.test.WriteBatchHandlerTest
\
org.rocksdb.test.WriteBatchTest
\
org.rocksdb.test.WriteOptionsTest
\
org.rocksdb.test.WriteBatchWithIndexTest
JAVA_TEST_LIBDIR
=
./test-libs/
JAVA_JUNIT_JAR
=
$(JAVA_TEST_LIBDIR)
junit-4.12-beta-2.jar
...
...
java/org/rocksdb/test/WriteBatchWithIndexTest.java
0 → 100644
浏览文件 @
be905491
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
package
org.rocksdb.test
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.rocksdb.*
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
public
class
WriteBatchWithIndexTest
{
@ClassRule
public
static
final
RocksMemoryResource
rocksMemoryResource
=
new
RocksMemoryResource
();
@Rule
public
TemporaryFolder
dbFolder
=
new
TemporaryFolder
();
@Test
public
void
readYourOwnWrites
()
throws
RocksDBException
{
RocksDB
db
=
null
;
Options
options
=
null
;
try
{
options
=
new
Options
();
// Setup options
options
.
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
final
byte
[]
k1
=
"key1"
.
getBytes
();
final
byte
[]
v1
=
"value1"
.
getBytes
();
final
byte
[]
k2
=
"key2"
.
getBytes
();
final
byte
[]
v2
=
"value2"
.
getBytes
();
db
.
put
(
k1
,
v1
);
db
.
put
(
k2
,
v2
);
final
WriteBatchWithIndex
wbwi
=
new
WriteBatchWithIndex
(
true
);
RocksIterator
base
=
null
;
RocksIterator
it
=
null
;
try
{
base
=
db
.
newIterator
();
it
=
wbwi
.
newIteratorWithBase
(
base
);
it
.
seek
(
k1
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
key
()).
isEqualTo
(
k1
);
assertThat
(
it
.
value
()).
isEqualTo
(
v1
);
it
.
seek
(
k2
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
key
()).
isEqualTo
(
k2
);
assertThat
(
it
.
value
()).
isEqualTo
(
v2
);
//put data to the write batch and make sure we can read it.
final
byte
[]
k3
=
"key3"
.
getBytes
();
final
byte
[]
v3
=
"value3"
.
getBytes
();
wbwi
.
put
(
k3
,
v3
);
it
.
seek
(
k3
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
key
()).
isEqualTo
(
k3
);
assertThat
(
it
.
value
()).
isEqualTo
(
v3
);
//update k2 in the write batch and check the value
final
byte
[]
v2Other
=
"otherValue2"
.
getBytes
();
wbwi
.
put
(
k2
,
v2Other
);
it
.
seek
(
k2
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
key
()).
isEqualTo
(
k2
);
assertThat
(
it
.
value
()).
isEqualTo
(
v2Other
);
//remove k1 and make sure we can read back the write
wbwi
.
remove
(
k1
);
it
.
seek
(
k1
);
assertThat
(
it
.
key
()).
isNotEqualTo
(
k1
);
//reinsert k1 and make sure we see the new value
final
byte
[]
v1Other
=
"otherValue1"
.
getBytes
();
wbwi
.
put
(
k1
,
v1Other
);
it
.
seek
(
k1
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
key
()).
isEqualTo
(
k1
);
assertThat
(
it
.
value
()).
isEqualTo
(
v1Other
);
}
finally
{
if
(
it
!=
null
)
{
it
.
dispose
();
}
if
(
base
!=
null
)
{
base
.
dispose
();
}
}
}
finally
{
if
(
db
!=
null
)
{
db
.
close
();
}
if
(
options
!=
null
)
{
options
.
dispose
();
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录