mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 20:17:17 +08:00
Rename max_reconstructions to max_restarts and use -1 for infinite (#8274)
Co-authored-by: Edward Oakes <ed.nmi.oakes@gmail.com>
This commit is contained in:
+10
-10
@@ -16,20 +16,20 @@ import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class ActorReconstructionTest extends BaseTest {
|
||||
public class ActorRestartTest extends BaseTest {
|
||||
|
||||
public static class Counter {
|
||||
|
||||
protected int value = 0;
|
||||
|
||||
private boolean wasCurrentActorReconstructed = false;
|
||||
private boolean wasCurrentActorRestarted = false;
|
||||
|
||||
public Counter() {
|
||||
wasCurrentActorReconstructed = Ray.getRuntimeContext().wasCurrentActorReconstructed();
|
||||
wasCurrentActorRestarted = Ray.getRuntimeContext().wasCurrentActorRestarted();
|
||||
}
|
||||
|
||||
public boolean wasCurrentActorReconstructed() {
|
||||
return wasCurrentActorReconstructed;
|
||||
public boolean wasCurrentActorRestarted() {
|
||||
return wasCurrentActorRestarted;
|
||||
}
|
||||
|
||||
public int increase() {
|
||||
@@ -42,17 +42,17 @@ public class ActorReconstructionTest extends BaseTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testActorReconstruction() throws InterruptedException, IOException {
|
||||
public void testActorRestart() throws InterruptedException, IOException {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
ActorCreationOptions options =
|
||||
new ActorCreationOptions.Builder().setMaxReconstructions(1).createActorCreationOptions();
|
||||
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
|
||||
RayActor<Counter> actor = Ray.createActor(Counter::new, options);
|
||||
// Call increase 3 times.
|
||||
for (int i = 0; i < 3; i++) {
|
||||
actor.call(Counter::increase).get();
|
||||
}
|
||||
|
||||
Assert.assertFalse(actor.call(Counter::wasCurrentActorReconstructed).get());
|
||||
Assert.assertFalse(actor.call(Counter::wasCurrentActorRestarted).get());
|
||||
|
||||
// Kill the actor process.
|
||||
int pid = actor.call(Counter::getPid).get();
|
||||
@@ -63,7 +63,7 @@ public class ActorReconstructionTest extends BaseTest {
|
||||
int value = actor.call(Counter::increase).get();
|
||||
Assert.assertEquals(value, 1);
|
||||
|
||||
Assert.assertTrue(actor.call(Counter::wasCurrentActorReconstructed).get());
|
||||
Assert.assertTrue(actor.call(Counter::wasCurrentActorRestarted).get());
|
||||
|
||||
// Kill the actor process again.
|
||||
pid = actor.call(Counter::getPid).get();
|
||||
@@ -124,7 +124,7 @@ public class ActorReconstructionTest extends BaseTest {
|
||||
public void testActorCheckpointing() throws IOException, InterruptedException {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
ActorCreationOptions options =
|
||||
new ActorCreationOptions.Builder().setMaxReconstructions(1).createActorCreationOptions();
|
||||
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
|
||||
RayActor<CheckpointableCounter> actor = Ray.createActor(CheckpointableCounter::new, options);
|
||||
// Call increase 3 times.
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -41,45 +41,45 @@ public class KillActorTest extends BaseTest {
|
||||
|
||||
public static class KillerActor {
|
||||
|
||||
public void kill(RayActor<?> actor, boolean noReconstruction) {
|
||||
actor.kill(noReconstruction);
|
||||
public void kill(RayActor<?> actor, boolean noRestart) {
|
||||
actor.kill(noRestart);
|
||||
}
|
||||
}
|
||||
|
||||
private static void localKill(RayActor<?> actor, boolean noReconstruction) {
|
||||
actor.kill(noReconstruction);
|
||||
private static void localKill(RayActor<?> actor, boolean noRestart) {
|
||||
actor.kill(noRestart);
|
||||
}
|
||||
|
||||
private static void remoteKill(RayActor<?> actor, boolean noReconstruction) {
|
||||
private static void remoteKill(RayActor<?> actor, boolean noRestart) {
|
||||
RayActor<KillerActor> killer = Ray.createActor(KillerActor::new);
|
||||
killer.call(KillerActor::kill, actor, noReconstruction);
|
||||
killer.call(KillerActor::kill, actor, noRestart);
|
||||
}
|
||||
|
||||
private void testKillActor(BiConsumer<RayActor<?>, Boolean> kill, boolean noReconstruction) {
|
||||
private void testKillActor(BiConsumer<RayActor<?>, Boolean> kill, boolean noRestart) {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
|
||||
ActorCreationOptions options =
|
||||
new ActorCreationOptions.Builder().setMaxReconstructions(1).createActorCreationOptions();
|
||||
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
|
||||
RayActor<HangActor> actor = Ray.createActor(HangActor::new, options);
|
||||
RayObject<Boolean> result = actor.call(HangActor::hang);
|
||||
// The actor will hang in this task.
|
||||
Assert.assertEquals(0, Ray.wait(ImmutableList.of(result), 1, 500).getReady().size());
|
||||
|
||||
// Kill the actor
|
||||
kill.accept(actor, noReconstruction);
|
||||
kill.accept(actor, noRestart);
|
||||
// The get operation will fail with RayActorException
|
||||
Assert.expectThrows(RayActorException.class, result::get);
|
||||
|
||||
try {
|
||||
// Sleep 1s here to make sure the driver has received the actor notification
|
||||
// (of state RECONSTRUCTING or DEAD).
|
||||
// (of state RESTARTING or DEAD).
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (noReconstruction) {
|
||||
// The actor should not be reconstructed.
|
||||
if (noRestart) {
|
||||
// The actor should not be restarted.
|
||||
Assert.expectThrows(RayActorException.class, () -> actor.call(HangActor::hang).get());
|
||||
} else {
|
||||
Assert.assertEquals(actor.call(HangActor::ping).get(), "pong");
|
||||
|
||||
Reference in New Issue
Block a user