Running Java API tests

I managed to install Ray from source.

After doing the pip install step outlined in the documentation I wanted to build the Java part of the project.

In ray/java directory I ran:

mvn compile
mvn package

The first 3 steps complete successfully, the 4th step (running the tests) fails with:

DefaultRayRuntimeFactory [main]: Failed to initialize ray runtime, with config {...}

Any thoughts whether I’m missing some setup steps or what the cause of the error is?

Hey @doru1004 , how do you run Java test cases? Now running java examples depends on python. My general steps are as follows:
1 ./ build.sh -l java
2 cd java
3 mvn clean install -DskipTests - Dcheckstyle.skip=true
4 cd …/python
5 pip install -e . -v
6 cd …/java
7 mvn test -pl test -Dtest=“KillActorTest” - Dcheckstyle.skip

Could you give more details about the error? We should be able to see the full exception stack.

Thanks for your reply @ffbin, after running this chain of commands you mentioned I seem to get no tests found when running step 7:

[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

When I run mvn package I get this when trying to run one of the tests:

java.lang.RuntimeException: Failed to start Ray runtime.
	at io.ray.runtime.runner.RunManager.startRayHead(RunManager.java:41)
	at io.ray.runtime.RayNativeRuntime.start(RayNativeRuntime.java:75)
	at io.ray.runtime.DefaultRayRuntimeFactory.createRayRuntime(DefaultRayRuntimeFactory.java:39)
	at io.ray.api.Ray.init(Ray.java:38)
	at io.ray.api.Ray.init(Ray.java:25)
	at io.ray.test.BaseTest.setUpBase(BaseTest.java:14)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61)
	at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366)
	at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320)
	at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:701)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
	at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
	at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:379)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:340)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:413)
Caused by: java.lang.RuntimeException: The exit value of the process is 1. Command: ray start --head --redis-password 5241570000000000 --system-config={"put_small_object_in_memory_store":false}

output:
2021-01-25 11:17:33,370	INFO scripts.py:537 -- Local node IP: 192.168.1.187
RuntimeError: Couldn't start Redis. Check log files: /tmp/ray/session_2021-01-25_11-17-33_401571_33222/logs/redis.out /tmp/ray/session_2021-01-25_11-17-33_401571_33222/logs/redis.err

	at io.ray.runtime.runner.RunManager.runCommand(RunManager.java:117)
	at io.ray.runtime.runner.RunManager.startRayHead(RunManager.java:39)
	... 41 more

Is the python executable invoked directly when Java API is in use?

If so, is there a way to overwrite it or point to a specific python executable? I believe it is picking the wrong one.

After running:

ray start --head --redis-password ...

Ray runtime started then I stopped it using:

ray stop

This signaled that one of the ray processes was still running which is the one responsible for the error above I think. After doing:

ray stop --force

the process was killed and I was able to run a bit further than before I think:

Now I am getting this error:

java.lang.RuntimeException: Failed to get address info. Output: null
	at io.ray.runtime.runner.RunManager.getAddressInfoAndFillConfig(RunManager.java:90)
	at io.ray.runtime.RayNativeRuntime.start(RayNativeRuntime.java:88)
	at io.ray.runtime.DefaultRayRuntimeFactory.createRayRuntime(DefaultRayRuntimeFactory.java:39)
	at io.ray.api.Ray.init(Ray.java:38)
	at io.ray.api.Ray.init(Ray.java:25)
	at io.ray.test.BaseTest.setUpBase(BaseTest.java:14)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61)
	at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366)
	at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320)
	at org.testng.internal.TestInvoker.runConfigMethods(TestInvoker.java:701)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
	at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
	at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:379)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:340)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:125)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:413)

Caused by:

Caused by: java.lang.RuntimeException: The exit value of the process is 1. Command: python -c import ray; ...)
output:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named ray

This is because the wrong version of python is used.

Looks like the call to python is hardcoded and cannot be customized. Pointing manually to the correct python enabled the test to start running.

1 Like

@kfstorm Can we add a document describing how to run Java use cases?

@doru1004 is your Ray installed in a pyenv or virtualenv Python?
If so, you will need to run the Java tests in a shell environment where the ray command is available.


update: or set correct env vars in your Java IDE.

@raulchen I am running directly on my machine.

I managed to get the tests to run, 4 tests didn’t finish successfully though, but the rest did. I’m attaching the summary:

[ERROR] Failures:
[ERROR] io.ray.test.ClassLoaderTest.testClassLoaderInMultiThreading(io.ray.test.ClassLoaderTest)
[INFO]   Run 1: PASS
[INFO]   Run 2: PASS
[ERROR]   Run 3: ClassLoaderTest.testClassLoaderInMultiThreading:103 » RayActor The actor cb576...
[INFO]
[ERROR] io.ray.test.FailureTest.testGetThrowsQuicklyWhenFoundException(io.ray.test.FailureTest)
[INFO]   Run 1: PASS
[INFO]   Run 2: PASS
[ERROR]   Run 3: FailureTest.testGetThrowsQuicklyWhenFoundException:149 Should fail quickly. Actual execution time: 5596 ms. expected [true] but found [false]
[INFO]
[ERROR] io.ray.test.GcsClientTest.testGetAllNodeInfo(io.ray.test.GcsClientTest)
[INFO]   Run 1: PASS
[INFO]   Run 2: PASS
[ERROR]   Run 3: GcsClientTest.testGetAllNodeInfo:34 expected [9.163.80.145] but found [192.168.1.187]
[INFO]
[ERROR]   JobConfigTest.tearDownJobConfig:27 » NullPointer
[INFO]
[ERROR] Tests run: 109, Failures: 4, Errors: 0, Skipped: 0

@doru1004 do these tests fail consistently?
There are some flaky Java tests. @kfstorm is looking into them. We’ll probably skip some.

I only ran them once but I was thinking exactly that, to run them multiple times and see if the same tests fail.