mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 17:28:10 +08:00
[Java] Add killActor API in Java (#6728)
* Add killActor API in Java * fix javadoc * update test case * Address comments
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user