use*_*782 6 client multithreading unit-testing elasticsearch
我正在为 ES5.2 编写单元测试,但遇到了一些问题。我需要创建一个连接到本地节点以运行测试的客户端,所以我使用
esClient = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
Run Code Online (Sandbox Code Playgroud)
这会导致问题
java.lang.IllegalStateException: running tests but failed to invoke RandomizedContext#getRandom
Run Code Online (Sandbox Code Playgroud)
然后我在我的单元测试类上使用了一个注释作为
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误
SEVERE: 2 threads leaked from TEST scope at {method_name}):
1) Thread[id=36, name={project_name}writer-thread-0, state=WAITING, group={project_name}-writer]
Run Code Online (Sandbox Code Playgroud)
并且单元测试抛出了错误
org.mockito.exceptions.misusing.WrongTypeOfReturnValue
Run Code Online (Sandbox Code Playgroud)
我尝试在单元测试类上使用如下注释
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
Run Code Online (Sandbox Code Playgroud)
这消除了一些错误消息,但代码中仍然存在并发问题。有谁知道如何处理这个?我应该使用一些明确的线程安全方法吗?
从依赖项中排除com.carrotsearch.randomizedtesting:randomizedtesting-runner
是可行的。
示例(build.gradle):
dependencies {
testCompile(project(path:':other-project')) {
exclude group:"com.carrotsearch.randomizedtesting", module:"randomizedtesting-runner"
}
}
Run Code Online (Sandbox Code Playgroud)
为什么?
如果你randomizedtesting-runner
的类路径中有,ES 将加载它:
并使用它:
归档时间: |
|
查看次数: |
494 次 |
最近记录: |