Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
e01acb3a
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,发现更多精彩内容 >>
提交
e01acb3a
编写于
1月 03, 2015
作者:
A
Adam Retter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test for WriteBatchWithIndex#newIterator()
上级
56f24941
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
1 deletion
+82
-1
java/org/rocksdb/DirectSlice.java
java/org/rocksdb/DirectSlice.java
+3
-0
java/org/rocksdb/test/WriteBatchWithIndexTest.java
java/org/rocksdb/test/WriteBatchWithIndexTest.java
+79
-1
未找到文件。
java/org/rocksdb/DirectSlice.java
浏览文件 @
e01acb3a
...
...
@@ -16,6 +16,9 @@ import java.nio.ByteBuffer;
* values consider using @see org.rocksdb.Slice
*/
public
class
DirectSlice
extends
AbstractSlice
<
ByteBuffer
>
{
//TODO(AR) only needed by WriteBatchWithIndexTest until JDK8
public
final
static
DirectSlice
NONE
=
new
DirectSlice
();
/**
* Called from JNI to construct a new Java DirectSlice
* without an underlying C++ object set
...
...
java/org/rocksdb/test/WriteBatchWithIndexTest.java
浏览文件 @
e01acb3a
...
...
@@ -165,5 +165,83 @@ public class WriteBatchWithIndexTest {
}
}
}
}
@Test
public
void
iterator
()
throws
RocksDBException
{
final
WriteBatchWithIndex
wbwi
=
new
WriteBatchWithIndex
(
true
);
final
String
k1
=
"key1"
;
final
String
v1
=
"value1"
;
final
String
k2
=
"key2"
;
final
String
v2
=
"value2"
;
final
String
k3
=
"key3"
;
final
String
v3
=
"value3"
;
final
byte
[]
k1b
=
k1
.
getBytes
();
final
byte
[]
v1b
=
v1
.
getBytes
();
final
byte
[]
k2b
=
k2
.
getBytes
();
final
byte
[]
v2b
=
v2
.
getBytes
();
final
byte
[]
k3b
=
k3
.
getBytes
();
final
byte
[]
v3b
=
v3
.
getBytes
();
//add put records
wbwi
.
put
(
k1b
,
v1b
);
wbwi
.
put
(
k2b
,
v2b
);
wbwi
.
put
(
k3b
,
v3b
);
//add a deletion record
final
String
k4
=
"key4"
;
final
byte
[]
k4b
=
k4
.
getBytes
();
wbwi
.
remove
(
k4b
);
WBWIRocksIterator
.
WriteEntry
[]
expected
=
{
new
WBWIRocksIterator
.
WriteEntry
(
WBWIRocksIterator
.
WriteType
.
PUT
,
new
DirectSlice
(
k1
),
new
DirectSlice
(
v1
)),
new
WBWIRocksIterator
.
WriteEntry
(
WBWIRocksIterator
.
WriteType
.
PUT
,
new
DirectSlice
(
k2
),
new
DirectSlice
(
v2
)),
new
WBWIRocksIterator
.
WriteEntry
(
WBWIRocksIterator
.
WriteType
.
PUT
,
new
DirectSlice
(
k3
),
new
DirectSlice
(
v3
)),
new
WBWIRocksIterator
.
WriteEntry
(
WBWIRocksIterator
.
WriteType
.
DELETE
,
new
DirectSlice
(
k4
),
DirectSlice
.
NONE
)
};
WBWIRocksIterator
it
=
null
;
try
{
it
=
wbwi
.
newIterator
();
//direct access - seek to key offsets
final
int
[]
testOffsets
=
{
2
,
0
,
1
,
3
};
for
(
int
i
=
0
;
i
<
testOffsets
.
length
;
i
++)
{
final
int
testOffset
=
testOffsets
[
i
];
final
byte
[]
key
=
toArray
(
expected
[
testOffset
].
getKey
().
data
());
it
.
seek
(
key
);
assertThat
(
it
.
isValid
()).
isTrue
();
assertThat
(
it
.
entry
()).
isEqualTo
(
expected
[
testOffset
]);
}
//forward iterative access
int
i
=
0
;
for
(
it
.
seekToFirst
();
it
.
isValid
();
it
.
next
())
{
assertThat
(
it
.
entry
()).
isEqualTo
(
expected
[
i
++]);
}
//reverse iterative access
i
=
expected
.
length
-
1
;
for
(
it
.
seekToLast
();
it
.
isValid
();
it
.
prev
())
{
assertThat
(
it
.
entry
()).
isEqualTo
(
expected
[
i
--]);
}
}
finally
{
if
(
it
!=
null
)
{
it
.
dispose
();
}
}
}
private
byte
[]
toArray
(
final
ByteBuffer
buf
)
{
final
byte
[]
ary
=
new
byte
[
buf
.
remaining
()];
buf
.
get
(
ary
);
return
ary
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录