gpt4 book ai didi

java - 如何从 JUnit 内部使用 Voldemort 服务器?

转载 作者:搜寻专家 更新时间:2023-11-01 03:26:26 27 4
gpt4 key购买 nike

我正在尝试在 Maven 项目中从 JUnit 内部使用 Voldemort。以下代码编译时,它没有成功执行:

@Before
public void setUp() throws Exception
{
// Start Voldemort
VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
VoldemortServer server = new VoldemortServer(config);
server.start();
}

相反,抛出这个异常:

java.lang.UnsatisfiedLinkError: voldemort.utils.JNAUtils.mlockall(I)I
at voldemort.utils.JNAUtils.mlockall(Native Method)
at voldemort.utils.JNAUtils.tryMlockall(JNAUtils.java:51)
at voldemort.server.VoldemortServer.startInner(VoldemortServer.java:251)
at voldemort.server.AbstractService.start(AbstractService.java:62)
at a.b.c.FunctionalTest.setUp(FunctionalTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:115)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

知道如何解决这个问题吗?

最佳答案

在你的堆栈跟踪中记下这一行

at voldemort.utils.JNAUtils.mlockall(Native Method)

这表明无论调用什么代码,都会通过 JNI 使用一些本地库。 UnsatisfiedLinkedError 在加载请求加载的类时 JVM 无法加载 native 库时遇到。

为确保您的代码可以加载 ddl/so 文件,请使用以下 java 系统属性,

-Djava.library.path=/path/to/directory/containing/native/libraries

或者,您可以将相同的目录添加到 Windows 上的 PATH 环境变量,或 Linux 上的 LD_LIBRARY_PATH 变量。

查看 http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html此页面描述了如何将系统属性传递给 maven-surefire-plugin,它负责在 Maven 中运行测试。

关于java - 如何从 JUnit 内部使用 Voldemort 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12834306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com