# Running Java API tests

**URL:** <https://discuss.ray.io/t/running-java-api-tests/549>\
**Category:** Ray Core\
**Created:** [January 22, 2021, 8:36pm UTC](https://discuss.ray.io/t/running-java-api-tests/549 "2021-01-22T20:36:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 22, 2021, 8:36pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/1 "2021-01-22T20:36:24Z")

</div>

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:

```auto
mvn compile
mvn package

```

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![ffbin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ffbin/32/296_2.png) [@ffbin](https://discuss.ray.io/u/ffbin)\
**Post date:** [January 23, 2021, 5:55am UTC](https://discuss.ray.io/t/running-java-api-tests/549/2 "2021-01-23T05:55:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kfstorm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/kfstorm/32/310_2.png) [@kfstorm](https://discuss.ray.io/u/kfstorm)\
**Post date:** [January 23, 2021, 8:00am UTC](https://discuss.ray.io/t/running-java-api-tests/549/3 "2021-01-23T08:00:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 25, 2021, 4:17pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/4 "2021-01-25T16:17:58Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 25, 2021, 4:18pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/5 "2021-01-25T16:18:41Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 25, 2021, 5:17pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/6 "2021-01-25T17:17:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 25, 2021, 5:20pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/7 "2021-01-25T17:20:50Z")

</div>

After running:

```auto
ray start --head --redis-password ...

```

Ray runtime started then I stopped it using:

```auto
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:

```auto
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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 25, 2021, 5:53pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/8 "2021-01-25T17:53:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ffbin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ffbin/32/296_2.png) [@ffbin](https://discuss.ray.io/u/ffbin)\
**Post date:** [January 26, 2021, 2:03am UTC](https://discuss.ray.io/t/running-java-api-tests/549/9 "2021-01-26T02:03:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![raulchen](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/raulchen/32/330_2.png) [@raulchen](https://discuss.ray.io/u/raulchen)\
**Post date:** [January 26, 2021, 3:14am UTC](https://discuss.ray.io/t/running-java-api-tests/549/10 "2021-01-26T03:14:32Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 26, 2021, 6:18am UTC](https://discuss.ray.io/t/running-java-api-tests/549/11 "2021-01-26T06:18:10Z")

</div>

@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:

```auto
[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

```

---

<div class="post-metadata">

**Author:** ![raulchen](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/raulchen/32/330_2.png) [@raulchen](https://discuss.ray.io/u/raulchen)\
**Post date:** [January 26, 2021, 8:34am UTC](https://discuss.ray.io/t/running-java-api-tests/549/12 "2021-01-26T08:34:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![doru1004](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/doru1004/32/291_2.png) [@doru1004](https://discuss.ray.io/u/doru1004)\
**Post date:** [January 26, 2021, 2:52pm UTC](https://discuss.ray.io/t/running-java-api-tests/549/13 "2021-01-26T14:52:48Z")

</div>

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