[Java] Add killActor API in Java (#6728)

* Add killActor API in Java

* fix javadoc

* update test case

* Address comments
This commit is contained in:
Kai Yang
2020-01-14 17:12:00 +08:00
committed by Qing Wang
parent 2bcf72e306
commit ddd4c42fe5
9 changed files with 109 additions and 2 deletions
@@ -28,8 +28,17 @@ public class TestUtils {
}
public static void skipTestIfDirectActorCallEnabled() {
if (ActorCreationOptions.DEFAULT_USE_DIRECT_CALL) {
throw new SkipException("This test doesn't work when direct actor call is enabled.");
skipTestIfDirectActorCallEnabled(true);
}
public static void skipTestIfDirectActorCallDisabled() {
skipTestIfDirectActorCallEnabled(false);
}
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"));
}
}
@@ -0,0 +1,40 @@
package org.ray.api.test;
import com.google.common.collect.ImmutableList;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.annotation.RayRemote;
import org.ray.api.exception.RayActorException;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test(groups = { "directCall" })
public class KillActorTest extends BaseTest {
@RayRemote
public static class HangActor {
public boolean alive() {
return true;
}
public boolean hang() throws InterruptedException {
while (true) {
Thread.sleep(1000);
}
}
}
public void testKillActor() {
TestUtils.skipTestUnderSingleProcess();
TestUtils.skipTestIfDirectActorCallDisabled();
RayActor<HangActor> actor = Ray.createActor(HangActor::new);
Assert.assertTrue(Ray.call(HangActor::alive, actor).get());
RayObject<Boolean> result = Ray.call(HangActor::hang, actor);
Assert.assertEquals(0, Ray.wait(ImmutableList.of(result), 1, 500).getReady().size());
Ray.killActor(actor);
Assert.expectThrows(RayActorException.class, result::get);
}
}