[Java] New Java actor API (#7414)

This commit is contained in:
Hao Chen
2020-03-04 22:39:23 +08:00
committed by GitHub
parent 4198db5038
commit fe7820fec9
46 changed files with 1576 additions and 753 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.annotation.RayRemote;
import org.ray.api.options.ActorCreationOptions;
import org.ray.api.runtime.RayRuntime;
import org.ray.runtime.AbstractRayRuntime;
@@ -79,7 +78,6 @@ public class TestUtils {
return false;
}
@RayRemote
private static String hi() {
return "hi";
}
@@ -3,7 +3,6 @@ package org.ray.api.benchmark;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.annotations.Test;
public class ActorPressTest extends RayBenchmarkTest {
@@ -45,7 +44,7 @@ public class ActorPressTest extends RayBenchmarkTest {
@Override
public RayObject<RemoteResult<Integer>> rayCall(RayActor rayActor) {
return Ray.call(Adder::add, (RayActor<Adder>) rayActor, 10);
return ((RayActor<Adder>) rayActor).call(Adder::add, 10);
}
@Override
@@ -53,7 +52,6 @@ public class ActorPressTest extends RayBenchmarkTest {
return true;
}
@RayRemote
public static class Adder {
private Integer sum = 0;
@@ -3,7 +3,6 @@ package org.ray.api.benchmark;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.annotations.Test;
public class MaxPressureTest extends RayBenchmarkTest {
@@ -12,7 +11,6 @@ public class MaxPressureTest extends RayBenchmarkTest {
public static final int totalNum = 10;
private static final long serialVersionUID = -1684518885171395952L;
@RayRemote
public static RemoteResult<Integer> currentTime() {
RemoteResult<Integer> remoteResult = new RemoteResult<>();
remoteResult.setFinishTime(System.nanoTime());
@@ -3,7 +3,6 @@ package org.ray.api.benchmark;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.annotations.Test;
public class RateLimiterPressureTest extends RayBenchmarkTest {
@@ -13,7 +12,6 @@ public class RateLimiterPressureTest extends RayBenchmarkTest {
public static final int duration = 10;
private static final long serialVersionUID = 6616958120966144235L;
@RayRemote
public static RemoteResult<Integer> currentTime() {
RemoteResult<Integer> remoteResult = new RemoteResult<>();
remoteResult.setFinishTime(System.nanoTime());
@@ -9,7 +9,6 @@ import java.util.List;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.function.RayFunc1;
import org.ray.api.test.BaseTest;
import org.slf4j.Logger;
@@ -23,7 +22,6 @@ public abstract class RayBenchmarkTest<T> extends BaseTest implements Serializab
public static final DecimalFormat df = new DecimalFormat("00.00");
private static final long serialVersionUID = 416045641835782523L;
@RayRemote
private static List<Long> singleClient(PressureTestParameter pressureTestParameter) {
try {
@@ -3,7 +3,6 @@ package org.ray.api.benchmark;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.annotations.Test;
public class SingleLatencyTest extends RayBenchmarkTest {
@@ -11,7 +10,6 @@ public class SingleLatencyTest extends RayBenchmarkTest {
public static final int totalNum = 10;
private static final long serialVersionUID = 3559601273941694468L;
@RayRemote
public static RemoteResult<Integer> doFunc() {
RemoteResult<Integer> remoteResult = new RemoteResult<>();
remoteResult.setResult(1);
@@ -7,7 +7,6 @@ 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.options.ActorCreationOptions;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -16,7 +15,6 @@ import org.testng.annotations.Test;
@Test
public class ActorConcurrentCallTest extends BaseTest {
@RayRemote
public static class ConcurrentActor {
private final CountDownLatch countDownLatch = new CountDownLatch(3);
@@ -38,9 +36,9 @@ public class ActorConcurrentCallTest extends BaseTest {
.setMaxConcurrency(3)
.createActorCreationOptions();
RayActor<ConcurrentActor> actor = Ray.createActor(ConcurrentActor::new, op);
RayObject<String> obj1 = Ray.call(ConcurrentActor::countDown, actor);
RayObject<String> obj2 = Ray.call(ConcurrentActor::countDown, actor);
RayObject<String> obj3 = Ray.call(ConcurrentActor::countDown, actor);
RayObject<String> obj1 = actor.call(ConcurrentActor::countDown);
RayObject<String> obj2 = actor.call(ConcurrentActor::countDown);
RayObject<String> obj3 = actor.call(ConcurrentActor::countDown);
List<Integer> expectedResult = ImmutableList.of(1, 2, 3);
Assert.assertEquals(obj1.get(), "ok");
@@ -9,7 +9,6 @@ import org.ray.api.Checkpointable;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.TestUtils;
import org.ray.api.annotation.RayRemote;
import org.ray.api.exception.RayActorException;
import org.ray.api.id.ActorId;
import org.ray.api.id.UniqueId;
@@ -20,7 +19,6 @@ import org.testng.annotations.Test;
@Test
public class ActorReconstructionTest extends BaseTest {
@RayRemote()
public static class Counter {
protected int value = 0;
@@ -52,31 +50,31 @@ public class ActorReconstructionTest extends BaseTest {
RayActor<Counter> actor = Ray.createActor(Counter::new, options);
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
Ray.call(Counter::increase, actor).get();
actor.call(Counter::increase).get();
}
Assert.assertFalse(Ray.call(Counter::wasCurrentActorReconstructed, actor).get());
Assert.assertFalse(actor.call(Counter::wasCurrentActorReconstructed).get());
// Kill the actor process.
int pid = Ray.call(Counter::getPid, actor).get();
int pid = actor.call(Counter::getPid).get();
Runtime.getRuntime().exec("kill -9 " + pid);
// 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 = Ray.call(Counter::increase, actor).get();
int value = actor.call(Counter::increase).get();
Assert.assertEquals(value, options.useDirectCall ? 1 : 4);
Assert.assertTrue(Ray.call(Counter::wasCurrentActorReconstructed, actor).get());
Assert.assertTrue(actor.call(Counter::wasCurrentActorReconstructed).get());
// Kill the actor process again.
pid = Ray.call(Counter::getPid, actor).get();
pid = actor.call(Counter::getPid).get();
Runtime.getRuntime().exec("kill -9 " + pid);
TimeUnit.SECONDS.sleep(1);
// Try calling increase on this actor again and this should fail.
try {
Ray.call(Counter::increase, actor).get();
actor.call(Counter::increase).get();
Assert.fail("The above task didn't fail.");
} catch (RayActorException e) {
// We should receive a RayActorException because the actor is dead.
@@ -132,20 +130,20 @@ public class ActorReconstructionTest extends BaseTest {
RayActor<CheckpointableCounter> actor = Ray.createActor(CheckpointableCounter::new, options);
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
Ray.call(CheckpointableCounter::increase, actor).get();
actor.call(CheckpointableCounter::increase).get();
}
// Assert that the actor wasn't resumed from a checkpoint.
Assert.assertFalse(Ray.call(CheckpointableCounter::wasResumedFromCheckpoint, actor).get());
int pid = Ray.call(CheckpointableCounter::getPid, actor).get();
Assert.assertFalse(actor.call(CheckpointableCounter::wasResumedFromCheckpoint).get());
int pid = actor.call(CheckpointableCounter::getPid).get();
Runtime.getRuntime().exec("kill -9 " + pid);
// 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 = Ray.call(CheckpointableCounter::increase, actor).get();
int value = actor.call(CheckpointableCounter::increase).get();
Assert.assertEquals(value, 4);
// Assert that the actor was resumed from a checkpoint.
Assert.assertTrue(Ray.call(CheckpointableCounter::wasResumedFromCheckpoint, actor).get());
Assert.assertTrue(actor.call(CheckpointableCounter::wasResumedFromCheckpoint).get());
}
}
@@ -10,8 +10,8 @@ import org.ray.api.RayObject;
import org.ray.api.RayPyActor;
import org.ray.api.TestUtils;
import org.ray.api.TestUtils.LargeObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.exception.UnreconstructableException;
import org.ray.api.id.ActorId;
import org.ray.api.id.UniqueId;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -19,7 +19,6 @@ import org.testng.annotations.Test;
@Test
public class ActorTest extends BaseTest {
@RayRemote
public static class Counter {
private int value;
@@ -50,13 +49,13 @@ public class ActorTest extends BaseTest {
public void testCreateAndCallActor() {
// Test creating an actor from a constructor
RayActor<Counter> actor = Ray.createActor(Counter::new, 1);
Assert.assertNotEquals(actor.getId(), UniqueId.NIL);
Assert.assertNotEquals(actor.getId(), ActorId.NIL);
// A java actor is not a python actor
Assert.assertFalse(actor instanceof RayPyActor);
// Test calling an actor
Assert.assertEquals(Integer.valueOf(1), Ray.call(Counter::getValue, actor).get());
Ray.call(Counter::increase, actor, 1);
Assert.assertEquals(Integer.valueOf(3), Ray.call(Counter::increaseAndGet, actor, 1).get());
Assert.assertEquals(Integer.valueOf(1), actor.call(Counter::getValue).get());
actor.call(Counter::increase, 1);
Assert.assertEquals(Integer.valueOf(3), actor.call(Counter::increaseAndGet, 1).get());
}
/**
@@ -71,7 +70,7 @@ public class ActorTest extends BaseTest {
*/
public void testGetDirectObjectTwice() {
RayActor<Counter> actor = Ray.createActor(Counter::new, 1);
RayObject<Integer> result = Ray.call(Counter::getValue, actor);
RayObject<Integer> result = actor.call(Counter::getValue);
Assert.assertEquals(result.get(), Integer.valueOf(1));
Assert.assertEquals(result.get(), Integer.valueOf(1));
// TODO(hchen): The following code will still fail, and can be fixed by using ref counting.
@@ -82,10 +81,9 @@ public class ActorTest extends BaseTest {
RayActor<Counter> actor = Ray.createActor(Counter::new, 1);
LargeObject largeObject = new LargeObject();
Assert.assertEquals(Integer.valueOf(largeObject.data.length + 1),
Ray.call(Counter::accessLargeObject, actor, largeObject).get());
actor.call(Counter::accessLargeObject, largeObject).get());
}
@RayRemote
static Counter factory(int initValue) {
return new Counter(initValue);
}
@@ -95,24 +93,21 @@ public class ActorTest extends BaseTest {
RayActor<Counter> actor = Ray.createActor(ActorTest::factory, 1);
Assert.assertNotEquals(actor.getId(), UniqueId.NIL);
// Test calling an actor
Assert.assertEquals(Integer.valueOf(1), Ray.call(Counter::getValue, actor).get());
Assert.assertEquals(Integer.valueOf(1), actor.call(Counter::getValue).get());
}
@RayRemote
static int testActorAsFirstParameter(RayActor<Counter> actor, int delta) {
RayObject<Integer> res = Ray.call(Counter::increaseAndGet, actor, delta);
RayObject<Integer> res = actor.call(Counter::increaseAndGet, delta);
return res.get();
}
@RayRemote
static int testActorAsSecondParameter(int delta, RayActor<Counter> actor) {
RayObject<Integer> res = Ray.call(Counter::increaseAndGet, actor, delta);
RayObject<Integer> res = actor.call(Counter::increaseAndGet, delta);
return res.get();
}
@RayRemote
static int testActorAsFieldOfParameter(List<RayActor<Counter>> actor, int delta) {
RayObject<Integer> res = Ray.call(Counter::increaseAndGet, actor.get(0), delta);
RayObject<Integer> res = actor.get(0).call(Counter::increaseAndGet, delta);
return res.get();
}
@@ -134,7 +129,7 @@ public class ActorTest extends BaseTest {
TestUtils.skipTestIfDirectActorCallEnabled();
RayActor<Counter> counter = Ray.createActor(Counter::new, 100);
// Call an actor method.
RayObject value = Ray.call(Counter::getValue, counter);
RayObject value = counter.call(Counter::getValue);
Assert.assertEquals(100, value.get());
// Delete the object from the object store.
Ray.internal().free(ImmutableList.of(value.getId()), false, false);
@@ -12,7 +12,6 @@ import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.RayPyActor;
import org.ray.api.TestUtils;
import org.ray.api.annotation.RayRemote;
import org.ray.runtime.actor.NativeRayActor;
import org.ray.runtime.actor.NativeRayPyActor;
import org.slf4j.Logger;
@@ -117,7 +116,6 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
return (byte[])res.get();
}
@RayRemote // Python can create java actors without @RayRemote
public static class TestActor {
public TestActor(byte[] v) {
value = v;
@@ -7,7 +7,6 @@ import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;
import org.ray.api.options.CallOptions;
import org.ray.api.runtimecontext.NodeInfo;
import org.testng.Assert;
@@ -15,7 +14,6 @@ import org.testng.annotations.Test;
public class DynamicResourceTest extends BaseTest {
@RayRemote
public static String sayHi() {
return "hi";
}
@@ -95,14 +95,14 @@ public class FailureTest extends BaseTest {
public void testActorCreationFailure() {
TestUtils.skipTestUnderSingleProcess();
RayActor<BadActor> actor = Ray.createActor(BadActor::new, true);
assertTaskFailedWithRayTaskException(Ray.call(BadActor::badMethod, actor));
assertTaskFailedWithRayTaskException(actor.call(BadActor::badMethod));
}
@Test
public void testActorTaskFailure() {
TestUtils.skipTestUnderSingleProcess();
RayActor<BadActor> actor = Ray.createActor(BadActor::new, false);
assertTaskFailedWithRayTaskException(Ray.call(BadActor::badMethod, actor));
assertTaskFailedWithRayTaskException(actor.call(BadActor::badMethod));
}
@Test
@@ -125,14 +125,14 @@ public class FailureTest extends BaseTest {
TestUtils.skipTestIfDirectActorCallEnabled();
RayActor<BadActor> actor = Ray.createActor(BadActor::new, false);
try {
Ray.call(BadActor::badMethod2, actor).get();
actor.call(BadActor::badMethod2).get();
Assert.fail("This line shouldn't be reached.");
} catch (RayActorException e) {
// When the actor process dies while executing a task, we should receive an
// RayActorException.
}
try {
Ray.call(BadActor::badMethod, actor).get();
actor.call(BadActor::badMethod).get();
Assert.fail("This line shouldn't be reached.");
} catch (RayActorException e) {
// When a actor task is submitted to a dead actor, we should also receive an
@@ -2,7 +2,6 @@ package org.ray.api.test;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -11,17 +10,14 @@ import org.testng.annotations.Test;
*/
public class HelloWorldTest extends BaseTest {
@RayRemote
private static String hello() {
return "hello";
}
@RayRemote
private static String world() {
return "world!";
}
@RayRemote
private static String merge(String hello, String world) {
return hello + "," + world;
}
@@ -5,7 +5,6 @@ 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;
@@ -13,7 +12,6 @@ import org.testng.annotations.Test;
@Test
public class KillActorTest extends BaseTest {
@RayRemote
public static class HangActor {
public boolean alive() {
@@ -31,8 +29,8 @@ public class KillActorTest extends BaseTest {
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.assertTrue(actor.call(HangActor::alive).get());
RayObject<Boolean> result = actor.call(HangActor::hang);
Assert.assertEquals(0, Ray.wait(ImmutableList.of(result), 1, 500).getReady().size());
Ray.killActor(actor);
Assert.expectThrows(RayActorException.class, result::get);
@@ -2,13 +2,11 @@ package org.ray.api.test;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.Assert;
import org.testng.annotations.Test;
public class MultiLanguageClusterTest extends BaseMultiLanguageTest {
@RayRemote
public static String echo(String word) {
return word;
}
@@ -14,7 +14,6 @@ import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;
import org.ray.api.id.ActorId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -29,21 +28,17 @@ public class MultiThreadingTest extends BaseTest {
private static final int LOOP_COUNTER = 100;
private static final int NUM_THREADS = 20;
@RayRemote
static Integer echo(int num) {
return num;
}
@RayRemote
public static class Echo {
@RayRemote
public Integer echo(int num) {
return num;
}
}
@RayRemote
public static class ActorIdTester {
private final ActorId actorId;
@@ -53,7 +48,6 @@ public class MultiThreadingTest extends BaseTest {
Assert.assertNotEquals(actorId, ActorId.NIL);
}
@RayRemote
public ActorId getCurrentActorId() throws Exception {
final Object[] result = new Object[1];
Thread thread = new Thread(Ray.wrapRunnable(() -> {
@@ -86,7 +80,7 @@ public class MultiThreadingTest extends BaseTest {
RayActor<Echo> echoActor = Ray.createActor(Echo::new);
runTestCaseInMultipleThreads(() -> {
int arg = random.nextInt();
RayObject<Integer> obj = Ray.call(Echo::echo, echoActor, arg);
RayObject<Integer> obj = echoActor.call(Echo::echo, arg);
Assert.assertEquals(arg, (int) obj.get());
}, LOOP_COUNTER);
@@ -101,7 +95,7 @@ public class MultiThreadingTest extends BaseTest {
} catch (InterruptedException e) {
LOGGER.warn("Got exception while sleeping.", e);
}
RayObject<Integer> obj = Ray.call(Echo::echo, echoActor1, arg);
RayObject<Integer> obj = echoActor1.call(Echo::echo, arg);
Assert.assertEquals(arg, (int) obj.get());
}, 1);
@@ -137,7 +131,7 @@ public class MultiThreadingTest extends BaseTest {
public void testGetCurrentActorId() {
TestUtils.skipTestUnderSingleProcess();
RayActor<ActorIdTester> actorIdTester = Ray.createActor(ActorIdTester::new);
ActorId actorId = Ray.call(ActorIdTester::getCurrentActorId, actorIdTester).get();
ActorId actorId = actorIdTester.call(ActorIdTester::getCurrentActorId).get();
Assert.assertEquals(actorId, actorIdTester.getId());
}
@@ -5,14 +5,12 @@ import java.util.Arrays;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.annotation.RayRemote;
import org.ray.api.id.TaskId;
import org.testng.Assert;
import org.testng.annotations.Test;
public class PlasmaFreeTest extends BaseTest {
@RayRemote
private static String hello() {
return "hello";
}
@@ -7,7 +7,6 @@ import java.util.Map;
import org.ray.api.Ray;
import org.ray.api.TestUtils;
import org.ray.api.TestUtils.LargeObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.id.ObjectId;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -17,62 +16,50 @@ import org.testng.annotations.Test;
*/
public class RayCallTest extends BaseTest {
@RayRemote
private static int testInt(int val) {
return val;
}
@RayRemote
private static byte testByte(byte val) {
return val;
}
@RayRemote
private static short testShort(short val) {
return val;
}
@RayRemote
private static long testLong(long val) {
return val;
}
@RayRemote
private static double testDouble(double val) {
return val;
}
@RayRemote
private static float testFloat(float val) {
return val;
}
@RayRemote
private static boolean testBool(boolean val) {
return val;
}
@RayRemote
private static String testString(String val) {
return val;
}
@RayRemote
private static List<Integer> testList(List<Integer> val) {
return val;
}
@RayRemote
private static Map<String, Integer> testMap(Map<String, Integer> val) {
return val;
}
@RayRemote
private static LargeObject testLargeObject(LargeObject largeObject) {
return largeObject;
}
@RayRemote
private static void testNoReturn(ObjectId objectId) {
// Put an object in object store to inform driver that this function is executing.
TestUtils.getRuntime().getObjectStore().put(1, objectId);
@@ -103,37 +90,30 @@ public class RayCallTest extends BaseTest {
Assert.assertEquals(((int) Ray.get(randomObjectId)), 1);
}
@RayRemote
private static int testNoParam() {
return 0;
}
@RayRemote
private static int testOneParam(int a) {
return a;
}
@RayRemote
private static int testTwoParams(int a, int b) {
return a + b;
}
@RayRemote
private static int testThreeParams(int a, int b, int c) {
return a + b + c;
}
@RayRemote
private static int testFourParams(int a, int b, int c, int d) {
return a + b + c + d;
}
@RayRemote
private static int testFiveParams(int a, int b, int c, int d, int e) {
return a + b + c + d + e;
}
@RayRemote
private static int testSixParams(int a, int b, int c, int d, int e, int f) {
return a + b + c + d + e + f;
}
@@ -2,7 +2,6 @@ package org.ray.api.test;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -22,7 +21,6 @@ public class RedisPasswordTest extends BaseTest {
System.clearProperty("ray.redis.password");
}
@RayRemote
public static String echo(String str) {
return str;
}
@@ -7,7 +7,6 @@ import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;
import org.ray.api.options.ActorCreationOptions;
import org.ray.api.options.CallOptions;
import org.testng.Assert;
@@ -30,12 +29,10 @@ public class ResourcesManagementTest extends BaseTest {
System.clearProperty("ray.resources");
}
@RayRemote
public static Integer echo(Integer number) {
return number;
}
@RayRemote
public static class Echo {
public Integer echo(Integer number) {
@@ -84,7 +81,7 @@ public class ResourcesManagementTest extends BaseTest {
// This is a case that can satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
RayActor<Echo> echo1 = Ray.createActor(Echo::new, actorCreationOptions1);
final RayObject<Integer> result1 = Ray.call(Echo::echo, echo1, 100);
final RayObject<Integer> result1 = echo1.call(Echo::echo, 100);
Assert.assertEquals(100, (int) result1.get());
// This is a case that can't satisfy required resources.
@@ -94,7 +91,7 @@ public class ResourcesManagementTest extends BaseTest {
RayActor<ResourcesManagementTest.Echo> echo2 =
Ray.createActor(Echo::new, actorCreationOptions2);
final RayObject<Integer> result2 = Ray.call(Echo::echo, echo2, 100);
final RayObject<Integer> result2 = echo2.call(Echo::echo, 100);
WaitResult<Integer> waitResult = Ray.wait(ImmutableList.of(result2), 1, 1000);
Assert.assertEquals(0, waitResult.getReady().size());
@@ -4,7 +4,6 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.annotation.RayRemote;
import org.ray.api.id.ActorId;
import org.ray.api.id.JobId;
import org.testng.Assert;
@@ -47,7 +46,6 @@ public class RuntimeContextTest extends BaseTest {
Ray.getRuntimeContext().getObjectStoreSocketName());
}
@RayRemote
public static class RuntimeContextTester {
public String testRuntimeContext(ActorId actorId) {
@@ -64,7 +62,7 @@ public class RuntimeContextTest extends BaseTest {
public void testRuntimeContextInActor() {
RayActor<RuntimeContextTester> actor = Ray.createActor(RuntimeContextTester::new);
Assert.assertEquals("ok",
Ray.call(RuntimeContextTester::testRuntimeContext, actor, actor.getId()).get());
actor.call(RuntimeContextTester::testRuntimeContext, actor.getId()).get());
}
}
@@ -8,7 +8,6 @@ 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.id.ActorId;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -19,7 +18,6 @@ public class SingleProcessModeTest extends BaseTest {
private static final int TIMES_TO_CALL_PER_ACTOR = 10;
@RayRemote
static class MyActor {
public MyActor() {
}
@@ -38,7 +36,7 @@ public class SingleProcessModeTest extends BaseTest {
for (int i = 0; i < NUM_ACTOR_INSTANCE; ++i) {
RayActor<MyActor> actor = Ray.createActor(MyActor::new);
actors.add(actor);
actorThreadIds.put(actor.getId(), Ray.call(MyActor::getThreadId, actor).get());
actorThreadIds.put(actor.getId(), actor.call(MyActor::getThreadId).get());
}
Map<ActorId, List<RayObject<Long>>> allResults = new HashMap<>();
@@ -46,7 +44,7 @@ public class SingleProcessModeTest extends BaseTest {
final RayActor<MyActor> actor = actors.get(i);
List<RayObject<Long>> thisActorResult = new ArrayList<>();
for (int j = 0; j < TIMES_TO_CALL_PER_ACTOR; ++j) {
thisActorResult.add(Ray.call(MyActor::getThreadId, actor));
thisActorResult.add(actor.call(MyActor::getThreadId));
}
allResults.put(actor.getId(), thisActorResult);
}
@@ -64,7 +64,7 @@ public class StressTest extends BaseTest {
public int ping(int n) {
List<ObjectId> objectIds = new ArrayList<>();
for (int i = 0; i < n; i++) {
objectIds.add(Ray.call(Actor::ping, actor).getId());
objectIds.add(actor.call(Actor::ping).getId());
}
int sum = 0;
for (Integer result : Ray.<Integer>get(objectIds)) {
@@ -81,7 +81,7 @@ public class StressTest extends BaseTest {
List<ObjectId> objectIds = new ArrayList<>();
for (int i = 0; i < 10; i++) {
RayActor<Worker> worker = Ray.createActor(Worker::new, actor);
objectIds.add(Ray.call(Worker::ping, worker, 100).getId());
objectIds.add(worker.call(Worker::ping, 100).getId());
}
for (Integer result : Ray.<Integer>get(objectIds)) {
@@ -7,18 +7,15 @@ import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;
import org.testng.Assert;
import org.testng.annotations.Test;
public class WaitTest extends BaseTest {
@RayRemote
private static String hi() {
return "hi";
}
@RayRemote
private static String delayedHi() {
try {
Thread.sleep(100 * 1000);
@@ -50,7 +47,6 @@ public class WaitTest extends BaseTest {
testWait();
}
@RayRemote
public static Object waitInWorker() {
testWait();
return null;
@@ -4,14 +4,12 @@ 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.options.ActorCreationOptions;
import org.testng.Assert;
import org.testng.annotations.Test;
public class WorkerJvmOptionsTest extends BaseTest {
@RayRemote
public static class Echo {
String getOptions() {
return System.getProperty("test.suffix");
@@ -27,7 +25,7 @@ public class WorkerJvmOptionsTest extends BaseTest {
.setJvmOptions(" -Dtest.suffix=suffix -Dtest.suffix1=suffix1 ")
.createActorCreationOptions();
RayActor<Echo> actor = Ray.createActor(Echo::new, options);
RayObject<String> obj = Ray.call(Echo::getOptions, actor);
RayObject<String> obj = actor.call(Echo::getOptions);
Assert.assertEquals(obj.get(), "suffix");
}
}