How to use Voldemort Server from inside JUnit?
Question
I'm trying to use Voldemort from inside JUnit in a Maven project. While the following Code compiles, it doesn't execute successfully:
@Before
public void setUp() throws Exception
{
// Start Voldemort
VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
VoldemortServer server = new VoldemortServer(config);
server.start();
}
instead, this exception is thrown:
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)
Any idea how to fix this?
La solution
Note this line in your stacktrace
at voldemort.utils.JNAUtils.mlockall(Native Method)
This indicates that whatever code is being called, uses some native library through JNI
. UnsatisfiedLinkedError
is encountered when the native library cannot be loaded by the JVM at the time of loading the class requesting to load this.
To ensure that the ddl / so files could be loaded by your code, use following java system property,
-Djava.library.path=/path/to/directory/containing/native/libraries
Alternatively you can add the same directory to PATH
environmental variable on windows, or LD_LIBRARY_PATH
variable on Linux.
Check out http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html this page describes how to pass system properties to maven-surefire-plugin
which is responsible for running the tests in Maven.