Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
22c73d15
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,发现更多精彩内容 >>
提交
22c73d15
编写于
3月 02, 2015
作者:
F
fyrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[RocksJava] Fix ColumnFamily tests
Cleanup column family memory cleanup
上级
694988b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
203 addition
and
93 deletion
+203
-93
java/src/test/java/org/rocksdb/ColumnFamilyTest.java
java/src/test/java/org/rocksdb/ColumnFamilyTest.java
+131
-60
java/src/test/java/org/rocksdb/KeyMayExistTest.java
java/src/test/java/org/rocksdb/KeyMayExistTest.java
+8
-4
java/src/test/java/org/rocksdb/MergeTest.java
java/src/test/java/org/rocksdb/MergeTest.java
+13
-11
java/src/test/java/org/rocksdb/ReadOnlyTest.java
java/src/test/java/org/rocksdb/ReadOnlyTest.java
+51
-18
未找到文件。
java/src/test/java/org/rocksdb/ColumnFamilyTest.java
浏览文件 @
22c73d15
...
@@ -56,6 +56,7 @@ public class ColumnFamilyTest {
...
@@ -56,6 +56,7 @@ public class ColumnFamilyTest {
public
void
defaultColumnFamily
()
throws
RocksDBException
{
public
void
defaultColumnFamily
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
Options
options
=
null
;
Options
options
=
null
;
ColumnFamilyHandle
cfh
=
null
;
try
{
try
{
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -64,7 +65,7 @@ public class ColumnFamilyTest {
...
@@ -64,7 +65,7 @@ public class ColumnFamilyTest {
dbOptions
.
setCreateIfMissing
(
true
);
dbOptions
.
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
ColumnFamilyHandle
cfh
=
db
.
getDefaultColumnFamily
();
cfh
=
db
.
getDefaultColumnFamily
();
assertThat
(
cfh
).
isNotNull
();
assertThat
(
cfh
).
isNotNull
();
final
byte
[]
key
=
"key"
.
getBytes
();
final
byte
[]
key
=
"key"
.
getBytes
();
...
@@ -77,6 +78,9 @@ public class ColumnFamilyTest {
...
@@ -77,6 +78,9 @@ public class ColumnFamilyTest {
assertThat
(
cfh
).
isNotNull
();
assertThat
(
cfh
).
isNotNull
();
assertThat
(
actualValue
).
isEqualTo
(
value
);
assertThat
(
actualValue
).
isEqualTo
(
value
);
}
finally
{
}
finally
{
if
(
cfh
!=
null
)
{
cfh
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -90,16 +94,14 @@ public class ColumnFamilyTest {
...
@@ -90,16 +94,14 @@ public class ColumnFamilyTest {
public
void
createColumnFamily
()
throws
RocksDBException
{
public
void
createColumnFamily
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
Options
options
=
null
;
Options
options
=
null
;
ColumnFamilyHandle
columnFamilyHandle
=
null
;
try
{
try
{
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
DBOptions
dbOptions
=
new
DBOptions
();
dbOptions
.
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
(),
columnFamilyHandle
=
db
.
createColumnFamily
(
new
ColumnFamilyOptions
()));
new
ColumnFamily
Descriptor
(
"new_cf"
.
getBytes
(),
new
ColumnFamily
Options
()));
db
.
close
();
db
.
close
();
List
<
byte
[]>
columnFamilyNames
;
List
<
byte
[]>
columnFamilyNames
;
columnFamilyNames
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
columnFamilyNames
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
...
@@ -109,6 +111,9 @@ public class ColumnFamilyTest {
...
@@ -109,6 +111,9 @@ public class ColumnFamilyTest {
assertThat
(
new
String
(
columnFamilyNames
.
get
(
0
))).
isEqualTo
(
"default"
);
assertThat
(
new
String
(
columnFamilyNames
.
get
(
0
))).
isEqualTo
(
"default"
);
assertThat
(
new
String
(
columnFamilyNames
.
get
(
1
))).
isEqualTo
(
"new_cf"
);
assertThat
(
new
String
(
columnFamilyNames
.
get
(
1
))).
isEqualTo
(
"new_cf"
);
}
finally
{
}
finally
{
if
(
columnFamilyHandle
!=
null
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -122,15 +127,15 @@ public class ColumnFamilyTest {
...
@@ -122,15 +127,15 @@ public class ColumnFamilyTest {
public
void
openWithColumnFamilies
()
throws
RocksDBException
{
public
void
openWithColumnFamilies
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
// Test open database with column family names
// Test open database with column family names
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -156,6 +161,9 @@ public class ColumnFamilyTest {
...
@@ -156,6 +161,9 @@ public class ColumnFamilyTest {
assertThat
(
db
.
get
(
columnFamilyHandleList
.
get
(
0
),
new
ReadOptions
(),
assertThat
(
db
.
get
(
columnFamilyHandleList
.
get
(
0
),
new
ReadOptions
(),
"dfkey2"
.
getBytes
())).
isNull
();
"dfkey2"
.
getBytes
())).
isNull
();
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -169,15 +177,15 @@ public class ColumnFamilyTest {
...
@@ -169,15 +177,15 @@ public class ColumnFamilyTest {
public
void
getWithOutValueAndCf
()
throws
RocksDBException
{
public
void
getWithOutValueAndCf
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
// Test open database with column family names
// Test open database with column family names
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
(),
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
(),
cfDescriptors
,
columnFamilyHandleList
);
cfDescriptors
,
columnFamilyHandleList
);
...
@@ -198,6 +206,9 @@ public class ColumnFamilyTest {
...
@@ -198,6 +206,9 @@ public class ColumnFamilyTest {
assertThat
(
getResult
).
isNotEqualTo
(
RocksDB
.
NOT_FOUND
);
assertThat
(
getResult
).
isNotEqualTo
(
RocksDB
.
NOT_FOUND
);
assertThat
(
outValue
).
isEqualTo
(
"12345"
.
getBytes
());
assertThat
(
outValue
).
isEqualTo
(
"12345"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -212,14 +223,14 @@ public class ColumnFamilyTest {
...
@@ -212,14 +223,14 @@ public class ColumnFamilyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
opt
=
null
;
DBOptions
opt
=
null
;
ColumnFamilyHandle
tmpColumnFamilyHandle
=
null
;
ColumnFamilyHandle
tmpColumnFamilyHandle
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
opt
=
new
DBOptions
();
opt
=
new
DBOptions
();
opt
.
setCreateIfMissing
(
true
);
opt
.
setCreateIfMissing
(
true
);
opt
.
setCreateMissingColumnFamilies
(
true
);
opt
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -231,6 +242,9 @@ public class ColumnFamilyTest {
...
@@ -231,6 +242,9 @@ public class ColumnFamilyTest {
db
.
dropColumnFamily
(
tmpColumnFamilyHandle
);
db
.
dropColumnFamily
(
tmpColumnFamilyHandle
);
tmpColumnFamilyHandle
.
dispose
();
tmpColumnFamilyHandle
.
dispose
();
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
tmpColumnFamilyHandle
!=
null
)
{
if
(
tmpColumnFamilyHandle
!=
null
)
{
tmpColumnFamilyHandle
.
dispose
();
tmpColumnFamilyHandle
.
dispose
();
}
}
...
@@ -247,14 +261,15 @@ public class ColumnFamilyTest {
...
@@ -247,14 +261,15 @@ public class ColumnFamilyTest {
public
void
writeBatch
()
throws
RocksDBException
{
public
void
writeBatch
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
opt
=
null
;
DBOptions
opt
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
opt
=
new
DBOptions
();
opt
=
new
DBOptions
();
opt
.
setCreateIfMissing
(
true
);
opt
.
setCreateIfMissing
(
true
);
opt
.
setCreateMissingColumnFamilies
(
true
);
opt
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
().
setMergeOperator
(
new
StringAppendOperator
())));
new
ColumnFamilyOptions
().
setMergeOperator
(
new
StringAppendOperator
())));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -288,6 +303,9 @@ public class ColumnFamilyTest {
...
@@ -288,6 +303,9 @@ public class ColumnFamilyTest {
assertThat
(
new
String
(
db
.
get
(
db
.
getDefaultColumnFamily
(),
assertThat
(
new
String
(
db
.
get
(
db
.
getDefaultColumnFamily
(),
"mergeKey"
.
getBytes
()))).
isEqualTo
(
"merge,merge"
);
"mergeKey"
.
getBytes
()))).
isEqualTo
(
"merge,merge"
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -302,14 +320,15 @@ public class ColumnFamilyTest {
...
@@ -302,14 +320,15 @@ public class ColumnFamilyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
RocksIterator
rocksIterator
=
null
;
RocksIterator
rocksIterator
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -338,6 +357,9 @@ public class ColumnFamilyTest {
...
@@ -338,6 +357,9 @@ public class ColumnFamilyTest {
if
(
rocksIterator
!=
null
)
{
if
(
rocksIterator
!=
null
)
{
rocksIterator
.
dispose
();
rocksIterator
.
dispose
();
}
}
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -351,14 +373,15 @@ public class ColumnFamilyTest {
...
@@ -351,14 +373,15 @@ public class ColumnFamilyTest {
public
void
multiGet
()
throws
RocksDBException
{
public
void
multiGet
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -383,6 +406,9 @@ public class ColumnFamilyTest {
...
@@ -383,6 +406,9 @@ public class ColumnFamilyTest {
assertThat
(
new
String
(
retValues
.
get
(
keys
.
get
(
1
))))
assertThat
(
new
String
(
retValues
.
get
(
keys
.
get
(
1
))))
.
isEqualTo
(
"value"
);
.
isEqualTo
(
"value"
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -396,14 +422,15 @@ public class ColumnFamilyTest {
...
@@ -396,14 +422,15 @@ public class ColumnFamilyTest {
public
void
properties
()
throws
RocksDBException
{
public
void
properties
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -423,6 +450,9 @@ public class ColumnFamilyTest {
...
@@ -423,6 +450,9 @@ public class ColumnFamilyTest {
assertThat
(
db
.
getProperty
(
columnFamilyHandleList
.
get
(
1
),
assertThat
(
db
.
getProperty
(
columnFamilyHandleList
.
get
(
1
),
"rocksdb.sstables"
)).
isNotNull
();
"rocksdb.sstables"
)).
isNotNull
();
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -437,15 +467,15 @@ public class ColumnFamilyTest {
...
@@ -437,15 +467,15 @@ public class ColumnFamilyTest {
public
void
iterators
()
throws
RocksDBException
{
public
void
iterators
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
options
.
setCreateMissingColumnFamilies
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -476,6 +506,9 @@ public class ColumnFamilyTest {
...
@@ -476,6 +506,9 @@ public class ColumnFamilyTest {
iter
.
next
();
iter
.
next
();
}
}
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -489,13 +522,14 @@ public class ColumnFamilyTest {
...
@@ -489,13 +522,14 @@ public class ColumnFamilyTest {
public
void
failPutDisposedCF
()
throws
RocksDBException
{
public
void
failPutDisposedCF
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -504,6 +538,9 @@ public class ColumnFamilyTest {
...
@@ -504,6 +538,9 @@ public class ColumnFamilyTest {
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
put
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
(),
"value"
.
getBytes
());
db
.
put
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
(),
"value"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -517,13 +554,14 @@ public class ColumnFamilyTest {
...
@@ -517,13 +554,14 @@ public class ColumnFamilyTest {
public
void
failRemoveDisposedCF
()
throws
RocksDBException
{
public
void
failRemoveDisposedCF
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -532,6 +570,9 @@ public class ColumnFamilyTest {
...
@@ -532,6 +570,9 @@ public class ColumnFamilyTest {
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
remove
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
());
db
.
remove
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -545,13 +586,14 @@ public class ColumnFamilyTest {
...
@@ -545,13 +586,14 @@ public class ColumnFamilyTest {
public
void
failGetDisposedCF
()
throws
RocksDBException
{
public
void
failGetDisposedCF
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -560,6 +602,9 @@ public class ColumnFamilyTest {
...
@@ -560,6 +602,9 @@ public class ColumnFamilyTest {
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
dropColumnFamily
(
columnFamilyHandleList
.
get
(
1
));
db
.
get
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
());
db
.
get
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -573,13 +618,14 @@ public class ColumnFamilyTest {
...
@@ -573,13 +618,14 @@ public class ColumnFamilyTest {
public
void
failMultiGetWithoutCorrectNumberOfCF
()
throws
RocksDBException
{
public
void
failMultiGetWithoutCorrectNumberOfCF
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
List
<
ColumnFamilyDescriptor
>
cfNames
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfNames
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
...
@@ -592,6 +638,9 @@ public class ColumnFamilyTest {
...
@@ -592,6 +638,9 @@ public class ColumnFamilyTest {
db
.
multiGet
(
cfCustomList
,
keys
);
db
.
multiGet
(
cfCustomList
,
keys
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -605,6 +654,7 @@ public class ColumnFamilyTest {
...
@@ -605,6 +654,7 @@ public class ColumnFamilyTest {
public
void
testByteCreateFolumnFamily
()
throws
RocksDBException
{
public
void
testByteCreateFolumnFamily
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
Options
options
=
null
;
Options
options
=
null
;
ColumnFamilyHandle
cf1
=
null
,
cf2
=
null
,
cf3
=
null
;
try
{
try
{
options
=
new
Options
().
setCreateIfMissing
(
true
);
options
=
new
Options
().
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
...
@@ -612,12 +662,21 @@ public class ColumnFamilyTest {
...
@@ -612,12 +662,21 @@ public class ColumnFamilyTest {
byte
[]
b0
=
new
byte
[]
{
(
byte
)
0x00
};
byte
[]
b0
=
new
byte
[]
{
(
byte
)
0x00
};
byte
[]
b1
=
new
byte
[]
{
(
byte
)
0x01
};
byte
[]
b1
=
new
byte
[]
{
(
byte
)
0x01
};
byte
[]
b2
=
new
byte
[]
{
(
byte
)
0x02
};
byte
[]
b2
=
new
byte
[]
{
(
byte
)
0x02
};
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b0
));
cf1
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b0
));
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b1
));
cf2
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b1
));
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
b0
,
b1
);
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
b0
,
b1
);
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b2
));
cf3
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b2
));
}
finally
{
}
finally
{
if
(
cf1
!=
null
)
{
cf1
.
dispose
();
}
if
(
cf2
!=
null
)
{
cf2
.
dispose
();
}
if
(
cf3
!=
null
)
{
cf3
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -631,17 +690,24 @@ public class ColumnFamilyTest {
...
@@ -631,17 +690,24 @@ public class ColumnFamilyTest {
public
void
testCFNamesWithZeroBytes
()
throws
RocksDBException
{
public
void
testCFNamesWithZeroBytes
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
Options
options
=
null
;
Options
options
=
null
;
ColumnFamilyHandle
cf1
=
null
,
cf2
=
null
;
try
{
try
{
options
=
new
Options
().
setCreateIfMissing
(
true
);
options
=
new
Options
().
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
byte
[]
b0
=
new
byte
[]
{
0
,
0
};
byte
[]
b0
=
new
byte
[]
{
0
,
0
};
byte
[]
b1
=
new
byte
[]
{
0
,
1
};
byte
[]
b1
=
new
byte
[]
{
0
,
1
};
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b0
));
cf1
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b0
));
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b1
));
cf2
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
b1
));
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
b0
,
b1
);
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
b0
,
b1
);
}
finally
{
}
finally
{
if
(
cf1
!=
null
)
{
cf1
.
dispose
();
}
if
(
cf2
!=
null
)
{
cf2
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -655,15 +721,20 @@ public class ColumnFamilyTest {
...
@@ -655,15 +721,20 @@ public class ColumnFamilyTest {
public
void
testCFNameSimplifiedChinese
()
throws
RocksDBException
{
public
void
testCFNameSimplifiedChinese
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
Options
options
=
null
;
Options
options
=
null
;
ColumnFamilyHandle
columnFamilyHandle
=
null
;
try
{
try
{
options
=
new
Options
().
setCreateIfMissing
(
true
);
options
=
new
Options
().
setCreateIfMissing
(
true
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
final
String
simplifiedChinese
=
"简体字"
;
final
String
simplifiedChinese
=
"简体字"
;
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
simplifiedChinese
.
getBytes
()));
columnFamilyHandle
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
simplifiedChinese
.
getBytes
()));
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
List
<
byte
[]>
families
=
RocksDB
.
listColumnFamilies
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
simplifiedChinese
.
getBytes
());
assertThat
(
families
).
contains
(
"default"
.
getBytes
(),
simplifiedChinese
.
getBytes
());
}
finally
{
}
finally
{
if
(
columnFamilyHandle
!=
null
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
...
java/src/test/java/org/rocksdb/KeyMayExistTest.java
浏览文件 @
22c73d15
...
@@ -27,15 +27,16 @@ public class KeyMayExistTest {
...
@@ -27,15 +27,16 @@ public class KeyMayExistTest {
public
void
keyMayExist
()
throws
RocksDBException
{
public
void
keyMayExist
()
throws
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
options
=
null
;
DBOptions
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
options
=
new
DBOptions
();
options
=
new
DBOptions
();
options
.
setCreateIfMissing
(
true
)
options
.
setCreateIfMissing
(
true
)
.
setCreateMissingColumnFamilies
(
true
);
.
setCreateMissingColumnFamilies
(
true
);
// open database using cf names
// open database using cf names
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
"new_cf"
.
getBytes
()));
db
=
RocksDB
.
open
(
options
,
db
=
RocksDB
.
open
(
options
,
...
@@ -80,6 +81,9 @@ public class KeyMayExistTest {
...
@@ -80,6 +81,9 @@ public class KeyMayExistTest {
assertThat
(
db
.
keyMayExist
(
columnFamilyHandleList
.
get
(
1
),
assertThat
(
db
.
keyMayExist
(
columnFamilyHandleList
.
get
(
1
),
"key"
.
getBytes
(),
retValue
)).
isFalse
();
"key"
.
getBytes
(),
retValue
)).
isFalse
();
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
...
java/src/test/java/org/rocksdb/MergeTest.java
浏览文件 @
22c73d15
...
@@ -143,7 +143,11 @@ public class MergeTest {
...
@@ -143,7 +143,11 @@ public class MergeTest {
throws
InterruptedException
,
RocksDBException
{
throws
InterruptedException
,
RocksDBException
{
RocksDB
db
=
null
;
RocksDB
db
=
null
;
DBOptions
opt
=
null
;
DBOptions
opt
=
null
;
ColumnFamilyHandle
columnFamilyHandle
=
null
;
ColumnFamilyHandle
cfHandle
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
String
db_path_string
=
String
db_path_string
=
dbFolder
.
getRoot
().
getAbsolutePath
();
dbFolder
.
getRoot
().
getAbsolutePath
();
...
@@ -152,10 +156,6 @@ public class MergeTest {
...
@@ -152,10 +156,6 @@ public class MergeTest {
opt
.
setCreateMissingColumnFamilies
(
true
);
opt
.
setCreateMissingColumnFamilies
(
true
);
StringAppendOperator
stringAppendOperator
=
new
StringAppendOperator
();
StringAppendOperator
stringAppendOperator
=
new
StringAppendOperator
();
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
columnFamilyHandleList
=
new
ArrayList
<>();
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
().
setMergeOperator
(
new
ColumnFamilyOptions
().
setMergeOperator
(
stringAppendOperator
)));
stringAppendOperator
)));
...
@@ -175,23 +175,25 @@ public class MergeTest {
...
@@ -175,23 +175,25 @@ public class MergeTest {
String
strValue
=
new
String
(
value
);
String
strValue
=
new
String
(
value
);
// Test also with createColumnFamily
// Test also with createColumnFamily
c
olumnFamily
Handle
=
db
.
createColumnFamily
(
c
f
Handle
=
db
.
createColumnFamily
(
new
ColumnFamilyDescriptor
(
"new_cf2"
.
getBytes
(),
new
ColumnFamilyDescriptor
(
"new_cf2"
.
getBytes
(),
new
ColumnFamilyOptions
().
setMergeOperator
(
stringAppendOperator
)));
new
ColumnFamilyOptions
().
setMergeOperator
(
stringAppendOperator
)));
// writing xx under cfkey2
// writing xx under cfkey2
db
.
put
(
c
olumnFamily
Handle
,
"cfkey2"
.
getBytes
(),
"xx"
.
getBytes
());
db
.
put
(
c
f
Handle
,
"cfkey2"
.
getBytes
(),
"xx"
.
getBytes
());
// merge yy under cfkey2
// merge yy under cfkey2
db
.
merge
(
c
olumnFamily
Handle
,
new
WriteOptions
(),
"cfkey2"
.
getBytes
(),
"yy"
.
getBytes
());
db
.
merge
(
c
f
Handle
,
new
WriteOptions
(),
"cfkey2"
.
getBytes
(),
"yy"
.
getBytes
());
value
=
db
.
get
(
c
olumnFamily
Handle
,
"cfkey2"
.
getBytes
());
value
=
db
.
get
(
c
f
Handle
,
"cfkey2"
.
getBytes
());
String
strValueTmpCf
=
new
String
(
value
);
String
strValueTmpCf
=
new
String
(
value
);
columnFamilyHandle
.
dispose
();
assertThat
(
strValue
).
isEqualTo
(
"aa,bb"
);
assertThat
(
strValue
).
isEqualTo
(
"aa,bb"
);
assertThat
(
strValueTmpCf
).
isEqualTo
(
"xx,yy"
);
assertThat
(
strValueTmpCf
).
isEqualTo
(
"xx,yy"
);
}
finally
{
}
finally
{
if
(
columnFamilyHandle
!=
null
)
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
columnFamilyHandle
.
dispose
();
}
}
if
(
cfHandle
!=
null
)
{
cfHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
...
java/src/test/java/org/rocksdb/ReadOnlyTest.java
浏览文件 @
22c73d15
...
@@ -80,12 +80,21 @@ public class ReadOnlyTest {
...
@@ -80,12 +80,21 @@ public class ReadOnlyTest {
assertThat
(
new
String
(
db3
.
get
(
readOnlyColumnFamilyHandleList2
.
get
(
1
),
assertThat
(
new
String
(
db3
.
get
(
readOnlyColumnFamilyHandleList2
.
get
(
1
),
"key2"
.
getBytes
()))).
isEqualTo
(
"value2"
);
"key2"
.
getBytes
()))).
isEqualTo
(
"value2"
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
columnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db2
!=
null
)
{
if
(
db2
!=
null
)
{
db2
.
close
();
db2
.
close
();
}
}
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList2
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db3
!=
null
)
{
if
(
db3
!=
null
)
{
db3
.
close
();
db3
.
close
();
}
}
...
@@ -100,13 +109,15 @@ public class ReadOnlyTest {
...
@@ -100,13 +109,15 @@ public class ReadOnlyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -120,6 +131,9 @@ public class ReadOnlyTest {
...
@@ -120,6 +131,9 @@ public class ReadOnlyTest {
// test that put fails in readonly mode
// test that put fails in readonly mode
rDb
.
put
(
"key"
.
getBytes
(),
"value"
.
getBytes
());
rDb
.
put
(
"key"
.
getBytes
(),
"value"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -137,13 +151,14 @@ public class ReadOnlyTest {
...
@@ -137,13 +151,14 @@ public class ReadOnlyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -157,6 +172,9 @@ public class ReadOnlyTest {
...
@@ -157,6 +172,9 @@ public class ReadOnlyTest {
rDb
.
put
(
readOnlyColumnFamilyHandleList
.
get
(
0
),
rDb
.
put
(
readOnlyColumnFamilyHandleList
.
get
(
0
),
"key"
.
getBytes
(),
"value"
.
getBytes
());
"key"
.
getBytes
(),
"value"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -174,13 +192,13 @@ public class ReadOnlyTest {
...
@@ -174,13 +192,13 @@ public class ReadOnlyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -194,6 +212,9 @@ public class ReadOnlyTest {
...
@@ -194,6 +212,9 @@ public class ReadOnlyTest {
rDb
.
remove
(
"key"
.
getBytes
());
rDb
.
remove
(
"key"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -211,13 +232,13 @@ public class ReadOnlyTest {
...
@@ -211,13 +232,13 @@ public class ReadOnlyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -233,6 +254,9 @@ public class ReadOnlyTest {
...
@@ -233,6 +254,9 @@ public class ReadOnlyTest {
rDb
.
remove
(
readOnlyColumnFamilyHandleList
.
get
(
0
),
rDb
.
remove
(
readOnlyColumnFamilyHandleList
.
get
(
0
),
"key"
.
getBytes
());
"key"
.
getBytes
());
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -250,13 +274,14 @@ public class ReadOnlyTest {
...
@@ -250,13 +274,14 @@ public class ReadOnlyTest {
RocksDB
db
=
null
;
RocksDB
db
=
null
;
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -273,6 +298,9 @@ public class ReadOnlyTest {
...
@@ -273,6 +298,9 @@ public class ReadOnlyTest {
wb
.
put
(
"key"
.
getBytes
(),
"value"
.
getBytes
());
wb
.
put
(
"key"
.
getBytes
(),
"value"
.
getBytes
());
rDb
.
write
(
new
WriteOptions
(),
wb
);
rDb
.
write
(
new
WriteOptions
(),
wb
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
@@ -291,13 +319,15 @@ public class ReadOnlyTest {
...
@@ -291,13 +319,15 @@ public class ReadOnlyTest {
RocksDB
rDb
=
null
;
RocksDB
rDb
=
null
;
Options
options
=
null
;
Options
options
=
null
;
WriteBatch
wb
=
null
;
WriteBatch
wb
=
null
;
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
try
{
try
{
List
<
ColumnFamilyDescriptor
>
cfDescriptors
=
new
ArrayList
<>();
cfDescriptors
.
add
(
cfDescriptors
.
add
(
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyDescriptor
(
RocksDB
.
DEFAULT_COLUMN_FAMILY
,
new
ColumnFamilyOptions
()));
new
ColumnFamilyOptions
()));
List
<
ColumnFamilyHandle
>
readOnlyColumnFamilyHandleList
=
new
ArrayList
<>();
options
=
new
Options
();
options
=
new
Options
();
options
.
setCreateIfMissing
(
true
);
options
.
setCreateIfMissing
(
true
);
...
@@ -315,6 +345,9 @@ public class ReadOnlyTest {
...
@@ -315,6 +345,9 @@ public class ReadOnlyTest {
"key"
.
getBytes
(),
"value"
.
getBytes
());
"key"
.
getBytes
(),
"value"
.
getBytes
());
rDb
.
write
(
new
WriteOptions
(),
wb
);
rDb
.
write
(
new
WriteOptions
(),
wb
);
}
finally
{
}
finally
{
for
(
ColumnFamilyHandle
columnFamilyHandle
:
readOnlyColumnFamilyHandleList
)
{
columnFamilyHandle
.
dispose
();
}
if
(
db
!=
null
)
{
if
(
db
!=
null
)
{
db
.
close
();
db
.
close
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录