[Java] Enable direct call by default. (#7408)

* WIP

* Address comments.

* Linting

* Fix

* Fix

* Fix test

* Fix

* Fix single process ci

* Fix ut

* Update java/test/src/main/java/org/ray/api/test/PlasmaFreeTest.java

* Address comments

* Fix linting

* Minor update comments.

* Fix streaming CI
This commit is contained in:
Qing Wang
2020-03-13 12:25:30 +08:00
committed by GitHub
parent 6993a471f1
commit f4656d8cc3
20 changed files with 34 additions and 161 deletions
@@ -3,7 +3,6 @@ package org.ray.api;
import com.google.common.base.Preconditions;
import java.io.Serializable;
import java.util.function.Supplier;
import org.ray.api.options.ActorCreationOptions;
import org.ray.api.runtime.RayRuntime;
import org.ray.runtime.AbstractRayRuntime;
import org.ray.runtime.RayMultiWorkerNativeRuntime;
@@ -20,8 +19,12 @@ public class TestUtils {
private static final int WAIT_INTERVAL_MS = 5;
public static boolean isSingleProcessMode() {
return getRuntime().getRayConfig().runMode == RunMode.SINGLE_PROCESS;
}
public static void skipTestUnderSingleProcess() {
if (getRuntime().getRayConfig().runMode == RunMode.SINGLE_PROCESS) {
if (isSingleProcessMode()) {
throw new SkipException("This test doesn't work under single-process mode.");
}
}
@@ -32,25 +35,6 @@ public class TestUtils {
}
}
public static boolean isDirectActorCallEnabled() {
return ActorCreationOptions.DEFAULT_USE_DIRECT_CALL;
}
public static void skipTestIfDirectActorCallEnabled() {
skipTestIfDirectActorCallEnabled(true);
}
private static void skipTestIfDirectActorCallEnabled(boolean enabled) {
if (enabled == ActorCreationOptions.DEFAULT_USE_DIRECT_CALL) {
throw new SkipException(String.format("This test doesn't work when direct actor call is %s.",
enabled ? "enabled" : "disabled"));
}
}
public static void skipTestIfDirectActorCallDisabled() {
skipTestIfDirectActorCallEnabled(false);
}
/**
* Wait until the given condition is met.
*
@@ -30,7 +30,7 @@ public class ActorConcurrentCallTest extends BaseTest {
}
public void testConcurrentCall() {
TestUtils.skipTestIfDirectActorCallDisabled();
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions op = new ActorCreationOptions.Builder()
.setMaxConcurrency(3)
@@ -61,9 +61,8 @@ public class ActorReconstructionTest extends BaseTest {
// Wait for the actor to be killed.
TimeUnit.SECONDS.sleep(1);
// Try calling increase on this actor again and check the value is now 4.
int value = actor.call(Counter::increase).get();
Assert.assertEquals(value, options.useDirectCall ? 1 : 4);
Assert.assertEquals(value, 1);
Assert.assertTrue(actor.call(Counter::wasCurrentActorReconstructed).get());
@@ -59,16 +59,12 @@ public class ActorTest extends BaseTest {
}
/**
* Test getting a direct object (an object that is returned by a direct-call task) twice from the
* object store.
* Test getting an object twice from the local memory store.
*
* Direct objects are stored in core worker's local memory. And it will be removed after the first
* Objects are stored in core worker's local memory. And it will be removed after the first
* get. To enable getting it twice, we cache the object in `RayObjectImpl`.
*
* NOTE(hchen): this test will run for non-direct actors as well, which doesn't have the above
* issue and should also succeed.
*/
public void testGetDirectObjectTwice() {
public void testGetObjectTwice() {
RayActor<Counter> actor = Ray.createActor(Counter::new, 1);
RayObject<Integer> result = actor.call(Counter::getValue);
Assert.assertEquals(result.get(), Integer.valueOf(1));
@@ -122,11 +118,12 @@ public class ActorTest extends BaseTest {
.get());
}
// TODO(qwang): Will re-enable this test case once ref counting is supported in Java.
@Test(enabled = false)
public void testUnreconstructableActorObject() throws InterruptedException {
TestUtils.skipTestUnderSingleProcess();
// The UnreconstructableException is created by raylet.
// TODO (kfstorm): This should be supported by direct actor call.
TestUtils.skipTestIfDirectActorCallEnabled();
RayActor<Counter> counter = Ray.createActor(Counter::new, 100);
// Call an actor method.
RayObject value = counter.call(Counter::getValue);
@@ -27,7 +27,6 @@ public class KillActorTest extends BaseTest {
public void testKillActor() {
TestUtils.skipTestUnderSingleProcess();
TestUtils.skipTestIfDirectActorCallDisabled();
RayActor<HangActor> actor = Ray.createActor(HangActor::new);
Assert.assertTrue(actor.call(HangActor::alive).get());
RayObject<Boolean> result = actor.call(HangActor::hang);
@@ -25,11 +25,11 @@ public class PlasmaFreeTest extends BaseTest {
final boolean result = TestUtils.waitForCondition(() ->
!TestUtils.getRuntime().getObjectStore()
.wait(ImmutableList.of(helloId.getId()), 1, 0).get(0), 50);
if (TestUtils.isDirectActorCallEnabled()) {
// Direct call will not delete object from im-memory store.
Assert.assertFalse(result);
} else {
if (TestUtils.isSingleProcessMode()) {
Assert.assertTrue(result);
} else {
// The object will not be deleted under cluster mode.
Assert.assertFalse(result);
}
}