Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
kvdb
rocksdb
提交
461cec4e
R
rocksdb
项目概览
kvdb
/
rocksdb
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
461cec4e
编写于
2月 03, 2016
作者:
I
Igor Canadi
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #972 from adamretter/wb-threads
Threaded tests for WriteBatch
上级
bf767c64
9ab269ab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
105 addition
and
0 deletion
+105
-0
java/Makefile
java/Makefile
+1
-0
java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java
java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java
+104
-0
未找到文件。
java/Makefile
浏览文件 @
461cec4e
...
...
@@ -99,6 +99,7 @@ JAVA_TESTS = org.rocksdb.BackupableDBOptionsTest\
org.rocksdb.StatisticsCollectorTest
\
org.rocksdb.WriteBatchHandlerTest
\
org.rocksdb.WriteBatchTest
\
org.rocksdb.WriteBatchThreadedTest
\
org.rocksdb.WriteOptionsTest
\
org.rocksdb.WriteBatchWithIndexTest
...
...
java/src/test/java/org/rocksdb/WriteBatchThreadedTest.java
0 → 100644
浏览文件 @
461cec4e
// Copyright (c) 2016, 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.
package
org.rocksdb
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.TemporaryFolder
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized.Parameter
;
import
org.junit.runners.Parameterized.Parameters
;
import
java.nio.ByteBuffer
;
import
java.util.*
;
import
java.util.concurrent.*
;
@RunWith
(
Parameterized
.
class
)
public
class
WriteBatchThreadedTest
{
@Parameters
(
name
=
"WriteBatchThreadedTest(threadCount={0})"
)
public
static
Iterable
<
Integer
>
data
()
{
return
Arrays
.
asList
(
new
Integer
[]{
1
,
10
,
50
,
100
});
}
@Parameter
public
int
threadCount
;
@Rule
public
TemporaryFolder
dbFolder
=
new
TemporaryFolder
();
RocksDB
db
;
@Before
public
void
setUp
()
throws
Exception
{
RocksDB
.
loadLibrary
();
final
Options
options
=
new
Options
()
.
setCreateIfMissing
(
true
)
.
setIncreaseParallelism
(
32
);
db
=
RocksDB
.
open
(
options
,
dbFolder
.
getRoot
().
getAbsolutePath
());
assert
(
db
!=
null
);
}
@After
public
void
tearDown
()
throws
Exception
{
if
(
db
!=
null
)
{
db
.
close
();
}
}
@Test
public
void
threadedWrites
()
throws
InterruptedException
,
ExecutionException
{
final
List
<
Callable
<
Void
>>
callables
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
final
int
offset
=
i
*
100
;
callables
.
add
(
new
Callable
<
Void
>()
{
@Override
public
Void
call
()
throws
RocksDBException
{
final
WriteBatch
wb
=
new
WriteBatch
();
for
(
int
i
=
offset
;
i
<
offset
+
100
;
i
++)
{
wb
.
put
(
ByteBuffer
.
allocate
(
4
).
putInt
(
i
).
array
(),
"parallel rocks test"
.
getBytes
());
}
db
.
write
(
new
WriteOptions
(),
wb
);
return
null
;
}
});
}
//submit the callables
final
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
threadCount
);
try
{
final
ExecutorCompletionService
<
Void
>
completionService
=
new
ExecutorCompletionService
<>(
executorService
);
final
Set
<
Future
<
Void
>>
futures
=
new
HashSet
<>();
for
(
final
Callable
<
Void
>
callable
:
callables
)
{
futures
.
add
(
completionService
.
submit
(
callable
));
}
while
(
futures
.
size
()
>
0
)
{
final
Future
<
Void
>
future
=
completionService
.
take
();
futures
.
remove
(
future
);
try
{
future
.
get
();
}
catch
(
final
ExecutionException
e
)
{
for
(
final
Future
<
Void
>
f
:
futures
)
{
f
.
cancel
(
true
);
}
throw
e
;
}
}
}
finally
{
executorService
.
shutdown
();
executorService
.
awaitTermination
(
10
,
TimeUnit
.
SECONDS
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录