[Java] Refactor java api (#8858)

This commit is contained in:
chaokunyang
2020-06-12 10:49:01 +08:00
committed by GitHub
parent cae475c46a
commit dfa4768fc6
64 changed files with 1854 additions and 3394 deletions
@@ -10,7 +10,7 @@ public class ActorPressTest extends RayBenchmarkTest {
@Test
public void singleLatencyTest() {
int times = 10;
ActorHandle<Adder> adder = Ray.createActor(ActorPressTest.Adder::new);
ActorHandle<Adder> adder = Ray.actor(ActorPressTest.Adder::new).remote();
super.singleLatencyTest(times, adder);
}
@@ -18,7 +18,7 @@ public class ActorPressTest extends RayBenchmarkTest {
public void maxTest() {
int clientNum = 2;
int totalNum = 20;
ActorHandle<Adder> adder = Ray.createActor(ActorPressTest.Adder::new);
ActorHandle<Adder> adder = Ray.actor(ActorPressTest.Adder::new).remote();
PressureTestParameter pressureTestParameter = new PressureTestParameter();
pressureTestParameter.setClientNum(clientNum);
pressureTestParameter.setTotalNum(totalNum);
@@ -32,7 +32,7 @@ public class ActorPressTest extends RayBenchmarkTest {
int clientNum = 2;
int totalQps = 2;
int duration = 3;
ActorHandle<Adder> adder = Ray.createActor(ActorPressTest.Adder::new);
ActorHandle<Adder> adder = Ray.actor(ActorPressTest.Adder::new).remote();
PressureTestParameter pressureTestParameter = new PressureTestParameter();
pressureTestParameter.setClientNum(clientNum);
pressureTestParameter.setTotalQps(totalQps);
@@ -44,7 +44,7 @@ public class ActorPressTest extends RayBenchmarkTest {
@Override
public ObjectRef<RemoteResult<Integer>> rayCall(ActorHandle rayActor) {
return ((ActorHandle<Adder>) rayActor).call(Adder::add, 10);
return ((ActorHandle<Adder>) rayActor).task(Adder::add, 10).remote();
}
@Override
@@ -30,7 +30,7 @@ public class MaxPressureTest extends RayBenchmarkTest {
@Override
public ObjectRef<RemoteResult<Integer>> rayCall(ActorHandle rayActor) {
return Ray.call(MaxPressureTest::currentTime);
return Ray.task(MaxPressureTest::currentTime).remote();
}
@Override
@@ -36,7 +36,7 @@ public class MicroBenchmarks {
Ray.init();
try {
time(() -> {
Ray.call(MicroBenchmarks::simpleFunction);
Ray.task(MicroBenchmarks::simpleFunction).remote();
}, numRepeats, "task submission");
} finally {
Ray.shutdown();
@@ -32,7 +32,7 @@ public class RateLimiterPressureTest extends RayBenchmarkTest {
@Override
public ObjectRef<RemoteResult<Integer>> rayCall(ActorHandle rayActor) {
return Ray.call(RateLimiterPressureTest::currentTime);
return Ray.task(RateLimiterPressureTest::currentTime).remote();
}
@Override
@@ -135,7 +135,7 @@ public abstract class RayBenchmarkTest<T> extends BaseTest implements Serializab
// defect of the Java compiler.
// TODO(hchen): Figure out how to avoid manually declaring `RayFunc` type in this case.
RayFunc1<PressureTestParameter, List<Long>> func = RayBenchmarkTest::singleClient;
objectRefs[i] = Ray.call(func, pressureTestParameter);
objectRefs[i] = Ray.task(func, pressureTestParameter).remote();
}
for (int i = 0; i < clientNum; i++) {
List<Long> subCounterList = objectRefs[i].get();
@@ -23,7 +23,7 @@ public class SingleLatencyTest extends RayBenchmarkTest {
@Override
public ObjectRef<RemoteResult<Integer>> rayCall(ActorHandle rayActor) {
return Ray.call(SingleLatencyTest::doFunc);
return Ray.task(SingleLatencyTest::doFunc).remote();
}
@Override
@@ -4,7 +4,6 @@ import com.google.common.collect.ImmutableList;
import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.options.ActorCreationOptions;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.testng.Assert;
@@ -30,13 +29,13 @@ public class ActorConcurrentCallTest extends BaseTest {
public void testConcurrentCall() {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions op = new ActorCreationOptions.Builder()
.setMaxConcurrency(3)
.createActorCreationOptions();
ActorHandle<ConcurrentActor> actor = Ray.createActor(ConcurrentActor::new, op);
ObjectRef<String> obj1 = actor.call(ConcurrentActor::countDown);
ObjectRef<String> obj2 = actor.call(ConcurrentActor::countDown);
ObjectRef<String> obj3 = actor.call(ConcurrentActor::countDown);
ActorHandle<ConcurrentActor> actor =
Ray.actor(ConcurrentActor::new)
.setMaxConcurrency(3)
.remote();
ObjectRef<String> obj1 = actor.task(ConcurrentActor::countDown).remote();
ObjectRef<String> obj2 = actor.task(ConcurrentActor::countDown).remote();
ObjectRef<String> obj3 = actor.task(ConcurrentActor::countDown).remote();
List<Integer> expectedResult = ImmutableList.of(1, 2, 3);
Assert.assertEquals(obj1.get(), "ok");
@@ -6,7 +6,6 @@ import io.ray.api.Ray;
import io.ray.api.exception.RayActorException;
import io.ray.api.id.ActorId;
import io.ray.api.id.UniqueId;
import io.ray.api.options.ActorCreationOptions;
import io.ray.runtime.util.SystemUtil;
import java.io.IOException;
import java.util.List;
@@ -43,35 +42,33 @@ public class ActorRestartTest extends BaseTest {
public void testActorRestart() throws InterruptedException, IOException {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options =
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
ActorHandle<Counter> actor = Ray.createActor(Counter::new, options);
ActorHandle<Counter> actor = Ray.actor(Counter::new).setMaxRestarts(1).remote();
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
actor.call(Counter::increase).get();
actor.task(Counter::increase).remote().get();
}
Assert.assertFalse(actor.call(Counter::wasCurrentActorRestarted).get());
Assert.assertFalse(actor.task(Counter::wasCurrentActorRestarted).remote().get());
// Kill the actor process.
int pid = actor.call(Counter::getPid).get();
int pid = actor.task(Counter::getPid).remote().get();
Runtime.getRuntime().exec("kill -9 " + pid);
// Wait for the actor to be killed.
TimeUnit.SECONDS.sleep(1);
int value = actor.call(Counter::increase).get();
int value = actor.task(Counter::increase).remote().get();
Assert.assertEquals(value, 1);
Assert.assertTrue(actor.call(Counter::wasCurrentActorRestarted).get());
Assert.assertTrue(actor.task(Counter::wasCurrentActorRestarted).remote().get());
// Kill the actor process again.
pid = actor.call(Counter::getPid).get();
pid = actor.task(Counter::getPid).remote().get();
Runtime.getRuntime().exec("kill -9 " + pid);
TimeUnit.SECONDS.sleep(1);
// Try calling increase on this actor again and this should fail.
try {
actor.call(Counter::increase).get();
actor.task(Counter::increase).remote().get();
Assert.fail("The above task didn't fail.");
} catch (RayActorException e) {
// We should receive a RayActorException because the actor is dead.
@@ -122,25 +119,24 @@ public class ActorRestartTest extends BaseTest {
public void testActorCheckpointing() throws IOException, InterruptedException {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options =
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
ActorHandle<CheckpointableCounter> actor = Ray.createActor(CheckpointableCounter::new, options);
ActorHandle<CheckpointableCounter> actor = Ray.actor(CheckpointableCounter::new)
.setMaxRestarts(1).remote();
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
actor.call(CheckpointableCounter::increase).get();
actor.task(CheckpointableCounter::increase).remote().get();
}
// Assert that the actor wasn't resumed from a checkpoint.
Assert.assertFalse(actor.call(CheckpointableCounter::wasResumedFromCheckpoint).get());
int pid = actor.call(CheckpointableCounter::getPid).get();
Assert.assertFalse(actor.task(CheckpointableCounter::wasResumedFromCheckpoint).remote().get());
int pid = actor.task(CheckpointableCounter::getPid).remote().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 = actor.call(CheckpointableCounter::increase).get();
int value = actor.task(CheckpointableCounter::increase).remote().get();
Assert.assertEquals(value, 4);
// Assert that the actor was resumed from a checkpoint.
Assert.assertTrue(actor.call(CheckpointableCounter::wasResumedFromCheckpoint).get());
Assert.assertTrue(actor.task(CheckpointableCounter::wasResumedFromCheckpoint).remote().get());
}
}
@@ -46,14 +46,15 @@ public class ActorTest extends BaseTest {
public void testCreateAndCallActor() {
// Test creating an actor from a constructor
ActorHandle<Counter> actor = Ray.createActor(Counter::new, 1);
ActorHandle<Counter> actor = Ray.actor(Counter::new, 1).remote();
Assert.assertNotEquals(actor.getId(), ActorId.NIL);
// A java actor is not a python actor
Assert.assertFalse(actor instanceof PyActorHandle);
// Test calling an actor
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());
Assert.assertEquals(Integer.valueOf(1), actor.task(Counter::getValue).remote().get());
actor.task(Counter::increase, 1).remote();
Assert.assertEquals(Integer.valueOf(3),
actor.task(Counter::increaseAndGet, 1).remote().get());
}
/**
@@ -63,8 +64,8 @@ public class ActorTest extends BaseTest {
* get. To enable getting it twice, we cache the object in `RayObjectImpl`.
*/
public void testGetObjectTwice() {
ActorHandle<Counter> actor = Ray.createActor(Counter::new, 1);
ObjectRef<Integer> result = actor.call(Counter::getValue);
ActorHandle<Counter> actor = Ray.actor(Counter::new, 1).remote();
ObjectRef<Integer> result = actor.task(Counter::getValue).remote();
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.
@@ -72,10 +73,10 @@ public class ActorTest extends BaseTest {
}
public void testCallActorWithLargeObject() {
ActorHandle<Counter> actor = Ray.createActor(Counter::new, 1);
ActorHandle<Counter> actor = Ray.actor(Counter::new, 1).remote();
TestUtils.LargeObject largeObject = new TestUtils.LargeObject();
Assert.assertEquals(Integer.valueOf(largeObject.data.length + 1),
actor.call(Counter::accessLargeObject, largeObject).get());
actor.task(Counter::accessLargeObject, largeObject).remote().get());
}
static Counter factory(int initValue) {
@@ -84,36 +85,36 @@ public class ActorTest extends BaseTest {
public void testCreateActorFromFactory() {
// Test creating an actor from a factory method
ActorHandle<Counter> actor = Ray.createActor(ActorTest::factory, 1);
ActorHandle<Counter> actor = Ray.actor(ActorTest::factory, 1).remote();
Assert.assertNotEquals(actor.getId(), UniqueId.NIL);
// Test calling an actor
Assert.assertEquals(Integer.valueOf(1), actor.call(Counter::getValue).get());
Assert.assertEquals(Integer.valueOf(1), actor.task(Counter::getValue).remote().get());
}
static int testActorAsFirstParameter(ActorHandle<Counter> actor, int delta) {
ObjectRef<Integer> res = actor.call(Counter::increaseAndGet, delta);
ObjectRef<Integer> res = actor.task(Counter::increaseAndGet, delta).remote();
return res.get();
}
static int testActorAsSecondParameter(int delta, ActorHandle<Counter> actor) {
ObjectRef<Integer> res = actor.call(Counter::increaseAndGet, delta);
ObjectRef<Integer> res = actor.task(Counter::increaseAndGet, delta).remote();
return res.get();
}
static int testActorAsFieldOfParameter(List<ActorHandle<Counter>> actor, int delta) {
ObjectRef<Integer> res = actor.get(0).call(Counter::increaseAndGet, delta);
ObjectRef<Integer> res = actor.get(0).task(Counter::increaseAndGet, delta).remote();
return res.get();
}
public void testPassActorAsParameter() {
ActorHandle<Counter> actor = Ray.createActor(Counter::new, 0);
ActorHandle<Counter> actor = Ray.actor(Counter::new, 0).remote();
Assert.assertEquals(Integer.valueOf(1),
Ray.call(ActorTest::testActorAsFirstParameter, actor, 1).get());
Ray.task(ActorTest::testActorAsFirstParameter, actor, 1).remote().get());
Assert.assertEquals(Integer.valueOf(11),
Ray.call(ActorTest::testActorAsSecondParameter, 10, actor).get());
Ray.task(ActorTest::testActorAsSecondParameter, 10, actor).remote().get());
Assert.assertEquals(Integer.valueOf(111),
Ray.call(ActorTest::testActorAsFieldOfParameter, Collections.singletonList(actor), 100)
.get());
Ray.task(ActorTest::testActorAsFieldOfParameter,
Collections.singletonList(actor), 100).remote().get());
}
// TODO(qwang): Will re-enable this test case once ref counting is supported in Java.
@@ -122,9 +123,9 @@ public class ActorTest extends BaseTest {
TestUtils.skipTestUnderSingleProcess();
// The UnreconstructableException is created by raylet.
ActorHandle<Counter> counter = Ray.createActor(Counter::new, 100);
ActorHandle<Counter> counter = Ray.actor(Counter::new, 100).remote();
// Call an actor method.
ObjectRef value = counter.call(Counter::getValue);
ObjectRef value = counter.task(Counter::getValue).remote();
Assert.assertEquals(100, value.get());
// Delete the object from the object store.
Ray.internal().free(ImmutableList.of(value.getId()), false, false);
@@ -69,24 +69,24 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
1.234, // Double
"example binary".getBytes()}; // byte[]
for (Object o : inputs) {
ObjectRef res = Ray.call(
ObjectRef res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", o.getClass()),
o);
o).remote();
Assert.assertEquals(res.get(), o);
}
// null
{
Object input = null;
ObjectRef<Object> res = Ray.call(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", Object.class), input);
ObjectRef<Object> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", Object.class), input).remote();
Object r = res.get();
Assert.assertEquals(r, input);
}
// array
{
int[] input = new int[]{1, 2};
ObjectRef<int[]> res = Ray.call(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", int[].class), input);
ObjectRef<int[]> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", int[].class), input).remote();
int[] r = res.get();
Assert.assertEquals(r, input);
}
@@ -94,8 +94,8 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
{
Object[] input = new Object[]{1, 2.3f, 4.56, "789", "10".getBytes(), null, true,
new int[]{1, 2}};
ObjectRef<Object[]> res = Ray.call(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", Object[].class), input);
ObjectRef<Object[]> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input", Object[].class), input).remote();
Object[] r = res.get();
// If we tell the value type is Object, then all numbers will be Number type.
Assert.assertEquals(((Number) r[0]).intValue(), input[0]);
@@ -119,9 +119,9 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
{
Assert.expectThrows(Exception.class, () -> {
List<Integer> input = Arrays.asList(1, 2);
ObjectRef<List<Integer>> res = Ray.call(
ObjectRef<List<Integer>> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_return_input",
(Class<List<Integer>>) input.getClass()), input);
(Class<List<Integer>>) input.getClass()), input).remote();
List<Integer> r = res.get();
Assert.assertEquals(r, input);
});
@@ -130,26 +130,26 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
@Test
public void testPythonCallJavaFunction() {
ObjectRef<String> res = Ray.call(
new PyRemoteFunction<>(PYTHON_MODULE, "py_func_call_java_function", String.class));
ObjectRef<String> res = Ray.task(new PyRemoteFunction<>(
PYTHON_MODULE, "py_func_call_java_function", String.class)).remote();
Assert.assertEquals(res.get(), "success");
}
@Test
public void testCallingPythonActor() {
PyActorHandle actor = Ray.createActor(
new PyActorClass(PYTHON_MODULE, "Counter"), "1".getBytes());
ObjectRef<byte[]> res = actor.call(
PyActorHandle actor = Ray.actor(
new PyActorClass(PYTHON_MODULE, "Counter"), "1".getBytes()).remote();
ObjectRef<byte[]> res = actor.task(
new PyActorMethod<>("increase", byte[].class),
"1".getBytes());
"1".getBytes()).remote();
Assert.assertEquals(res.get(), "2".getBytes());
}
@Test
public void testPythonCallJavaActor() {
ObjectRef<byte[]> res = Ray.call(
ObjectRef<byte[]> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE, "py_func_call_java_actor", byte[].class),
"1".getBytes());
"1".getBytes()).remote();
Assert.assertEquals(res.get(), "Counter1".getBytes());
}
@@ -158,33 +158,33 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
public void testPassActorHandleFromPythonToJava() {
// Call a python function which creates a python actor
// and pass the actor handle to callPythonActorHandle.
ObjectRef<byte[]> res = Ray.call(
new PyRemoteFunction<>(PYTHON_MODULE, "py_func_pass_python_actor_handle", byte[].class));
ObjectRef<byte[]> res = Ray.task(new PyRemoteFunction<>(
PYTHON_MODULE, "py_func_pass_python_actor_handle", byte[].class)).remote();
Assert.assertEquals(res.get(), "3".getBytes());
}
@Test
public void testPassActorHandleFromJavaToPython() {
// Create a java actor, and pass actor handle to python.
ActorHandle<TestActor> javaActor = Ray.createActor(TestActor::new, "1".getBytes());
ActorHandle<TestActor> javaActor = Ray.actor(TestActor::new, "1".getBytes()).remote();
Preconditions.checkState(javaActor instanceof NativeActorHandle);
byte[] actorHandleBytes = ((NativeActorHandle) javaActor).toBytes();
ObjectRef<byte[]> res = Ray.call(
ObjectRef<byte[]> res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE,
"py_func_call_java_actor_from_handle",
byte[].class),
actorHandleBytes);
actorHandleBytes).remote();
Assert.assertEquals(res.get(), "12".getBytes());
// Create a python actor, and pass actor handle to python.
PyActorHandle pyActor = Ray.createActor(
new PyActorClass(PYTHON_MODULE, "Counter"), "1".getBytes());
PyActorHandle pyActor = Ray.actor(
new PyActorClass(PYTHON_MODULE, "Counter"), "1".getBytes()).remote();
Preconditions.checkState(pyActor instanceof NativeActorHandle);
actorHandleBytes = ((NativeActorHandle) pyActor).toBytes();
res = Ray.call(
res = Ray.task(
new PyRemoteFunction<>(PYTHON_MODULE,
"py_func_call_python_actor_from_handle",
byte[].class),
actorHandleBytes);
actorHandleBytes).remote();
Assert.assertEquals(res.get(), "3".getBytes());
}
@@ -220,9 +220,9 @@ public class CrossLanguageInvocationTest extends BaseMultiLanguageTest {
public static byte[] callPythonActorHandle(byte[] value) {
// This function will be called from test_cross_language_invocation.py
NativePyActorHandle actor = (NativePyActorHandle) NativeActorHandle.fromBytes(value);
ObjectRef<byte[]> res = actor.call(
ObjectRef<byte[]> res = actor.task(
new PyActorMethod<>("increase", byte[].class),
"1".getBytes());
"1".getBytes()).remote();
Assert.assertEquals(res.get(), "3".getBytes());
return (byte[]) res.get();
}
@@ -1,11 +1,9 @@
package io.ray.test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.WaitResult;
import io.ray.api.options.CallOptions;
import io.ray.api.runtimecontext.NodeInfo;
import java.util.List;
import org.testng.Assert;
@@ -24,9 +22,9 @@ public class DynamicResourceTest extends BaseTest {
// Call a task in advance to warm up the cluster to avoid being too slow to start workers.
TestUtils.warmUpCluster();
CallOptions op1 =
new CallOptions.Builder().setResources(ImmutableMap.of("A", 10.0)).createCallOptions();
ObjectRef<String> obj = Ray.call(DynamicResourceTest::sayHi, op1);
ObjectRef<String> obj = Ray.task(DynamicResourceTest::sayHi)
.setResource("A", 10.0)
.remote();
WaitResult<String> result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(result.getReady().size(), 0);
@@ -87,28 +87,28 @@ public class FailureTest extends BaseTest {
@Test
public void testNormalTaskFailure() {
TestUtils.skipTestUnderSingleProcess();
assertTaskFailedWithRayTaskException(Ray.call(FailureTest::badFunc));
assertTaskFailedWithRayTaskException(Ray.task(FailureTest::badFunc).remote());
}
@Test
public void testActorCreationFailure() {
TestUtils.skipTestUnderSingleProcess();
ActorHandle<BadActor> actor = Ray.createActor(BadActor::new, true);
assertTaskFailedWithRayTaskException(actor.call(BadActor::badMethod));
ActorHandle<BadActor> actor = Ray.actor(BadActor::new, true).remote();
assertTaskFailedWithRayTaskException(actor.task(BadActor::badMethod).remote());
}
@Test
public void testActorTaskFailure() {
TestUtils.skipTestUnderSingleProcess();
ActorHandle<BadActor> actor = Ray.createActor(BadActor::new, false);
assertTaskFailedWithRayTaskException(actor.call(BadActor::badMethod));
ActorHandle<BadActor> actor = Ray.actor(BadActor::new, false).remote();
assertTaskFailedWithRayTaskException(actor.task(BadActor::badMethod).remote());
}
@Test
public void testWorkerProcessDying() {
TestUtils.skipTestUnderSingleProcess();
try {
Ray.call(FailureTest::badFunc2).get();
Ray.task(FailureTest::badFunc2).remote().get();
Assert.fail("This line shouldn't be reached.");
} catch (RayWorkerException e) {
// When the worker process dies while executing a task, we should receive an
@@ -119,16 +119,16 @@ public class FailureTest extends BaseTest {
@Test
public void testActorProcessDying() {
TestUtils.skipTestUnderSingleProcess();
ActorHandle<BadActor> actor = Ray.createActor(BadActor::new, false);
ActorHandle<BadActor> actor = Ray.actor(BadActor::new, false).remote();
try {
actor.call(BadActor::badMethod2).get();
actor.task(BadActor::badMethod2).remote().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 {
actor.call(BadActor::badMethod).get();
actor.task(BadActor::badMethod).remote().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
@@ -143,8 +143,8 @@ public class FailureTest extends BaseTest {
FailureTest::badFunc2);
TestUtils.warmUpCluster();
for (RayFunc0<Integer> badFunc : badFunctions) {
ObjectRef<Integer> obj1 = Ray.call(badFunc);
ObjectRef<Integer> obj2 = Ray.call(FailureTest::slowFunc);
ObjectRef<Integer> obj1 = Ray.task(badFunc).remote();
ObjectRef<Integer> obj2 = Ray.task(FailureTest::slowFunc).remote();
Instant start = Instant.now();
try {
Ray.get(Arrays.asList(obj1, obj2));
@@ -24,9 +24,9 @@ public class HelloWorldTest extends BaseTest {
@Test
public void testHelloWorld() {
ObjectRef<String> hello = Ray.call(HelloWorldTest::hello);
ObjectRef<String> world = Ray.call(HelloWorldTest::world);
String helloWorld = Ray.call(HelloWorldTest::merge, hello, world).get();
ObjectRef<String> hello = Ray.task(HelloWorldTest::hello).remote();
ObjectRef<String> world = Ray.task(HelloWorldTest::world).remote();
String helloWorld = Ray.task(HelloWorldTest::merge, hello, world).remote().get();
Assert.assertEquals("hello,world!", helloWorld);
}
@@ -5,7 +5,6 @@ import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.exception.RayActorException;
import io.ray.api.options.ActorCreationOptions;
import java.util.function.BiConsumer;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -50,19 +49,20 @@ public class KillActorTest extends BaseTest {
}
private static void remoteKill(ActorHandle<?> actor, boolean noRestart) {
ActorHandle<KillerActor> killer = Ray.createActor(KillerActor::new);
killer.call(KillerActor::kill, actor, noRestart);
ActorHandle<KillerActor> killer = Ray.actor(KillerActor::new).remote();
killer.task(KillerActor::kill, actor, noRestart).remote();
}
private void testKillActor(BiConsumer<ActorHandle<?>, Boolean> kill, boolean noRestart) {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options =
new ActorCreationOptions.Builder().setMaxRestarts(1).createActorCreationOptions();
ActorHandle<HangActor> actor = Ray.createActor(HangActor::new, options);
ObjectRef<Boolean> result = actor.call(HangActor::hang);
ActorHandle<HangActor> actor = Ray.actor(HangActor::new)
.setMaxRestarts(1)
.remote();
ObjectRef<Boolean> result = actor.task(HangActor::hang).remote();
// The actor will hang in this task.
Assert.assertEquals(0, Ray.wait(ImmutableList.of(result), 1, 500).getReady().size());
Assert.assertEquals(0,
Ray.wait(ImmutableList.of(result), 1, 500).getReady().size());
// Kill the actor
kill.accept(actor, noRestart);
@@ -79,9 +79,10 @@ public class KillActorTest extends BaseTest {
if (noRestart) {
// The actor should not be restarted.
Assert.expectThrows(RayActorException.class, () -> actor.call(HangActor::hang).get());
Assert.expectThrows(RayActorException.class,
() -> actor.task(HangActor::hang).remote().get());
} else {
Assert.assertEquals(actor.call(HangActor::ping).get(), "pong");
Assert.assertEquals(actor.task(HangActor::ping).remote().get(), "pong");
}
}
@@ -13,7 +13,7 @@ public class MultiLanguageClusterTest extends BaseMultiLanguageTest {
@Test
public void testMultiLanguageCluster() {
ObjectRef<String> obj = Ray.call(MultiLanguageClusterTest::echo, "hello");
ObjectRef<String> obj = Ray.task(MultiLanguageClusterTest::echo, "hello").remote();
Assert.assertEquals("hello", obj.get());
}
@@ -72,22 +72,22 @@ public class MultiThreadingTest extends BaseTest {
// Test calling normal functions.
runTestCaseInMultipleThreads(() -> {
int arg = random.nextInt();
ObjectRef<Integer> obj = Ray.call(MultiThreadingTest::echo, arg);
ObjectRef<Integer> obj = Ray.task(MultiThreadingTest::echo, arg).remote();
Assert.assertEquals(arg, (int) obj.get());
}, LOOP_COUNTER);
// Test calling actors.
ActorHandle<Echo> echoActor = Ray.createActor(Echo::new);
ActorHandle<Echo> echoActor = Ray.actor(Echo::new).remote();
runTestCaseInMultipleThreads(() -> {
int arg = random.nextInt();
ObjectRef<Integer> obj = echoActor.call(Echo::echo, arg);
ObjectRef<Integer> obj = echoActor.task(Echo::echo, arg).remote();
Assert.assertEquals(arg, (int) obj.get());
}, LOOP_COUNTER);
// Test creating multi actors
runTestCaseInMultipleThreads(() -> {
int arg = random.nextInt();
ActorHandle<Echo> echoActor1 = Ray.createActor(Echo::new);
ActorHandle<Echo> echoActor1 = Ray.actor(Echo::new).remote();
try {
// Sleep a while to test the case that another actor is created before submitting
// tasks to this actor.
@@ -95,7 +95,7 @@ public class MultiThreadingTest extends BaseTest {
} catch (InterruptedException e) {
LOGGER.warn("Got exception while sleeping.", e);
}
ObjectRef<Integer> obj = echoActor1.call(Echo::echo, arg);
ObjectRef<Integer> obj = echoActor1.task(Echo::echo, arg).remote();
Assert.assertEquals(arg, (int) obj.get());
}, 1);
@@ -108,7 +108,7 @@ public class MultiThreadingTest extends BaseTest {
TestUtils.warmUpCluster();
// Test wait for one object in multi threads.
ObjectRef<Integer> obj = Ray.call(MultiThreadingTest::echo, 100);
ObjectRef<Integer> obj = Ray.task(MultiThreadingTest::echo, 100).remote();
runTestCaseInMultipleThreads(() -> {
WaitResult<Integer> result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(1, result.getReady().size());
@@ -124,14 +124,14 @@ public class MultiThreadingTest extends BaseTest {
public void testInWorker() {
// Single-process mode doesn't have real workers.
TestUtils.skipTestUnderSingleProcess();
ObjectRef<String> obj = Ray.call(MultiThreadingTest::testMultiThreading);
ObjectRef<String> obj = Ray.task(MultiThreadingTest::testMultiThreading).remote();
Assert.assertEquals("ok", obj.get());
}
public void testGetCurrentActorId() {
TestUtils.skipTestUnderSingleProcess();
ActorHandle<ActorIdTester> actorIdTester = Ray.createActor(ActorIdTester::new);
ActorId actorId = actorIdTester.call(ActorIdTester::getCurrentActorId).get();
ActorHandle<ActorIdTester> actorIdTester = Ray.actor(ActorIdTester::new).remote();
ActorId actorId = actorIdTester.task(ActorIdTester::getCurrentActorId).remote().get();
Assert.assertEquals(actorId, actorIdTester.getId());
}
@@ -140,16 +140,16 @@ public class MultiThreadingTest extends BaseTest {
*/
static Runnable[] generateRunnables() {
final ObjectRef<Integer> fooObject = Ray.put(1);
final ActorHandle<Echo> fooActor = Ray.createActor(Echo::new);
final ActorHandle<Echo> fooActor = Ray.actor(Echo::new).remote();
return new Runnable[]{
() -> Ray.put(1),
() -> Ray.get(fooObject.getId(), fooObject.getType()),
fooObject::get,
() -> Ray.wait(ImmutableList.of(fooObject)),
Ray::getRuntimeContext,
() -> Ray.call(MultiThreadingTest::echo, 1),
() -> Ray.createActor(Echo::new),
() -> fooActor.call(Echo::echo, 1),
() -> Ray.task(MultiThreadingTest::echo, 1).remote(),
() -> Ray.actor(Echo::new).remote(),
() -> fooActor.task(Echo::echo, 1),
};
}
@@ -218,7 +218,7 @@ public class MultiThreadingTest extends BaseTest {
runnables[0].run();
}
// Return true here to make the Ray.call returns an ObjectRef.
// Return true here to make the caller.remote() returns an ObjectRef.
return true;
}
@@ -229,7 +229,7 @@ public class MultiThreadingTest extends BaseTest {
@Test
public void testMissingWrapRunnableInWorker() {
Ray.call(MultiThreadingTest::testMissingWrapRunnable).get();
Ray.task(MultiThreadingTest::testMissingWrapRunnable).remote().get();
}
@Test
@@ -302,7 +302,8 @@ public class MultiThreadingTest extends BaseTest {
}
public void testGetAsyncContextAndSetAsyncContextInWorker() {
ObjectRef<Boolean> obj = Ray.call(MultiThreadingTest::testGetAsyncContextAndSetAsyncContext);
ObjectRef<Boolean> obj = Ray.task(
MultiThreadingTest::testGetAsyncContextAndSetAsyncContext).remote();
Assert.assertTrue(obj.get());
}
@@ -16,7 +16,7 @@ public class PlasmaFreeTest extends BaseTest {
@Test
public void testDeleteObjects() {
ObjectRef<String> helloId = Ray.call(PlasmaFreeTest::hello);
ObjectRef<String> helloId = Ray.task(PlasmaFreeTest::hello).remote();
String helloString = helloId.get();
Assert.assertEquals("hello", helloString);
Ray.internal().free(ImmutableList.of(helloId.getId()), true, false);
@@ -35,7 +35,7 @@ public class PlasmaFreeTest extends BaseTest {
@Test
public void testDeleteCreatingTasks() {
TestUtils.skipTestUnderSingleProcess();
ObjectRef<String> helloId = Ray.call(PlasmaFreeTest::hello);
ObjectRef<String> helloId = Ray.task(PlasmaFreeTest::hello).remote();
Assert.assertEquals("hello", helloId.get());
Ray.internal().free(ImmutableList.of(helloId.getId()), true, true);
@@ -68,26 +68,26 @@ public class RayCallTest extends BaseTest {
*/
@Test
public void testType() {
Assert.assertEquals(1, (int) Ray.call(RayCallTest::testInt, 1).get());
Assert.assertEquals(1, (byte) Ray.call(RayCallTest::testByte, (byte) 1).get());
Assert.assertEquals(1, (short) Ray.call(RayCallTest::testShort, (short) 1).get());
Assert.assertEquals(1, (long) Ray.call(RayCallTest::testLong, 1L).get());
Assert.assertEquals(1.0, Ray.call(RayCallTest::testDouble, 1.0).get(), 0.0);
Assert.assertEquals(1.0f, Ray.call(RayCallTest::testFloat, 1.0f).get(), 0.0);
Assert.assertTrue(Ray.call(RayCallTest::testBool, true).get());
Assert.assertEquals("foo", Ray.call(RayCallTest::testString, "foo").get());
Assert.assertEquals(1, (int) Ray.task(RayCallTest::testInt, 1).remote().get());
Assert.assertEquals(1, (byte) Ray.task(RayCallTest::testByte, (byte) 1).remote().get());
Assert.assertEquals(1, (short) Ray.task(RayCallTest::testShort, (short) 1).remote().get());
Assert.assertEquals(1, (long) Ray.task(RayCallTest::testLong, 1L).remote().get());
Assert.assertEquals(1.0, Ray.task(RayCallTest::testDouble, 1.0).remote().get(), 0.0);
Assert.assertEquals(1.0f, Ray.task(RayCallTest::testFloat, 1.0f).remote().get(), 0.0);
Assert.assertTrue(Ray.task(RayCallTest::testBool, true).remote().get());
Assert.assertEquals("foo", Ray.task(RayCallTest::testString, "foo").remote().get());
List<Integer> list = ImmutableList.of(1, 2, 3);
Assert.assertEquals(list, Ray.call(RayCallTest::testList, list).get());
Assert.assertEquals(list, Ray.task(RayCallTest::testList, list).remote().get());
Map<String, Integer> map = ImmutableMap.of("1", 1, "2", 2);
Assert.assertEquals(map, Ray.call(RayCallTest::testMap, map).get());
Assert.assertEquals(map, Ray.task(RayCallTest::testMap, map).remote().get());
TestUtils.LargeObject largeObject = new TestUtils.LargeObject();
Assert.assertNotNull(Ray.call(RayCallTest::testLargeObject, largeObject).get());
Assert.assertNotNull(Ray.task(RayCallTest::testLargeObject, largeObject).remote().get());
// TODO(edoakes): this test doesn't work now that we've switched to direct call
// mode. To make it work, we need to implement the same protocol for resolving
// passed ObjectIDs that we have in Python.
// ObjectId randomObjectId = ObjectId.fromRandom();
// Ray.call(RayCallTest::testNoReturn, randomObjectId);
// Ray.task(RayCallTest::testNoReturn, randomObjectId).remote();
// Assert.assertEquals(((int) Ray.get(randomObjectId, Integer.class)), 1);
}
@@ -121,13 +121,18 @@ public class RayCallTest extends BaseTest {
@Test
public void testNumberOfParameters() {
Assert.assertEquals(0, (int) Ray.call(RayCallTest::testNoParam).get());
Assert.assertEquals(1, (int) Ray.call(RayCallTest::testOneParam, 1).get());
Assert.assertEquals(2, (int) Ray.call(RayCallTest::testTwoParams, 1, 1).get());
Assert.assertEquals(3, (int) Ray.call(RayCallTest::testThreeParams, 1, 1, 1).get());
Assert.assertEquals(4, (int) Ray.call(RayCallTest::testFourParams, 1, 1, 1, 1).get());
Assert.assertEquals(5, (int) Ray.call(RayCallTest::testFiveParams, 1, 1, 1, 1, 1).get());
Assert.assertEquals(6, (int) Ray.call(RayCallTest::testSixParams, 1, 1, 1, 1, 1, 1).get());
Assert.assertEquals(0, (int) Ray.task(RayCallTest::testNoParam).remote().get());
Assert.assertEquals(1, (int) Ray.task(RayCallTest::testOneParam, 1).remote().get());
Assert.assertEquals(2, (int) Ray.task(
RayCallTest::testTwoParams, 1, 1).remote().get());
Assert.assertEquals(3, (int) Ray.task(
RayCallTest::testThreeParams, 1, 1, 1).remote().get());
Assert.assertEquals(4, (int) Ray.task(
RayCallTest::testFourParams, 1, 1, 1, 1).remote().get());
Assert.assertEquals(5, (int) Ray.task(
RayCallTest::testFiveParams, 1, 1, 1, 1, 1).remote().get());
Assert.assertEquals(6, (int) Ray.task(
RayCallTest::testSixParams, 1, 1, 1, 1, 1, 1).remote().get());
}
}
@@ -12,8 +12,8 @@ public class RaySerializerTest extends BaseMultiLanguageTest {
@Test
public void testSerializePyActor() {
PyActorHandle pyActor = Ray.createActor(
new PyActorClass("test", "RaySerializerTest"));
PyActorHandle pyActor = Ray.actor(
new PyActorClass("test", "RaySerializerTest")).remote();
NativeRayObject nativeRayObject = ObjectSerializer.serialize(pyActor);
PyActorHandle result = (PyActorHandle) ObjectSerializer
.deserialize(nativeRayObject, null, Object.class);
@@ -31,8 +31,8 @@ public class RayletConfigTest extends BaseTest {
@Test
public void testRayletConfigPassThrough() {
ActorHandle<TestActor> actor = Ray.createActor(TestActor::new);
String configValue = actor.call(TestActor::getConfigValue).get();
ActorHandle<TestActor> actor = Ray.actor(TestActor::new).remote();
String configValue = actor.task(TestActor::getConfigValue).remote().get();
Assert.assertEquals(configValue, RAY_CONFIG_VALUE);
}
}
@@ -27,7 +27,7 @@ public class RedisPasswordTest extends BaseTest {
@Test
public void testRedisPassword() {
ObjectRef<String> obj = Ray.call(RedisPasswordTest::echo, "hello");
ObjectRef<String> obj = Ray.task(RedisPasswordTest::echo, "hello").remote();
Assert.assertEquals("hello", obj.get());
}
@@ -6,7 +6,6 @@ import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.WaitResult;
import io.ray.api.options.ActorCreationOptions;
import io.ray.api.options.CallOptions;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
@@ -42,20 +41,19 @@ public class ResourcesManagementTest extends BaseTest {
@Test
public void testMethods() {
TestUtils.skipTestUnderSingleProcess();
CallOptions callOptions1 =
new CallOptions.Builder().setResources(ImmutableMap.of("CPU", 4.0)).createCallOptions();
// This is a case that can satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
ObjectRef<Integer> result1 = Ray.call(ResourcesManagementTest::echo, 100, callOptions1);
ObjectRef<Integer> result1 = Ray.task(ResourcesManagementTest::echo, 100)
.setResource("CPU", 4.0)
.remote();
Assert.assertEquals(100, (int) result1.get());
CallOptions callOptions2 =
new CallOptions.Builder().setResources(ImmutableMap.of("CPU", 4.0)).createCallOptions();
// This is a case that can't satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
final ObjectRef<Integer> result2 = Ray.call(ResourcesManagementTest::echo, 200, callOptions2);
final ObjectRef<Integer> result2 = Ray.task(ResourcesManagementTest::echo, 200)
.setResource("CPU", 4.0)
.remote();
WaitResult<Integer> waitResult = Ray.wait(ImmutableList.of(result2), 1, 1000);
Assert.assertEquals(1, waitResult.getReady().size());
@@ -63,7 +61,7 @@ public class ResourcesManagementTest extends BaseTest {
try {
CallOptions callOptions3 =
new CallOptions.Builder().setResources(ImmutableMap.of("CPU", 0.0)).createCallOptions();
new CallOptions.Builder().setResources(ImmutableMap.of("CPU", 0.0)).build();
Assert.fail();
} catch (RuntimeException e) {
// We should receive a RuntimeException indicates that we should not
@@ -75,22 +73,21 @@ public class ResourcesManagementTest extends BaseTest {
public void testActors() {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions actorCreationOptions1 = new ActorCreationOptions.Builder()
.setResources(ImmutableMap.of("CPU", 2.0)).createActorCreationOptions();
// This is a case that can satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
ActorHandle<Echo> echo1 = Ray.createActor(Echo::new, actorCreationOptions1);
final ObjectRef<Integer> result1 = echo1.call(Echo::echo, 100);
ActorHandle<Echo> echo1 = Ray.actor(Echo::new)
.setResource("CPU", 2.0)
.remote();
final ObjectRef<Integer> result1 = echo1.task(Echo::echo, 100).remote();
Assert.assertEquals(100, (int) result1.get());
// This is a case that can't satisfy required resources.
// The static resources for test are "CPU:4,RES-A:4".
ActorCreationOptions actorCreationOptions2 = new ActorCreationOptions.Builder()
.setResources(ImmutableMap.of("CPU", 8.0)).createActorCreationOptions();
ActorHandle<Echo> echo2 =
Ray.createActor(Echo::new, actorCreationOptions2);
final ObjectRef<Integer> result2 = echo2.call(Echo::echo, 100);
Ray.actor(Echo::new)
.setResource("CPU", 8.0)
.remote();
final ObjectRef<Integer> result2 = echo2.task(Echo::echo, 100).remote();
WaitResult<Integer> waitResult = Ray.wait(ImmutableList.of(result2), 1, 1000);
Assert.assertEquals(0, waitResult.getReady().size());
@@ -60,9 +60,9 @@ public class RuntimeContextTest extends BaseTest {
@Test
public void testRuntimeContextInActor() {
ActorHandle<RuntimeContextTester> actor = Ray.createActor(RuntimeContextTester::new);
ActorHandle<RuntimeContextTester> actor = Ray.actor(RuntimeContextTester::new).remote();
Assert.assertEquals("ok",
actor.call(RuntimeContextTester::testRuntimeContext, actor.getId()).get());
actor.task(RuntimeContextTester::testRuntimeContext, actor.getId()).remote().get());
}
}
@@ -33,9 +33,9 @@ public class SingleProcessModeTest extends BaseTest {
List<ActorHandle<MyActor>> actors = new ArrayList<>();
Map<ActorId, Long> actorThreadIds = new HashMap<>();
for (int i = 0; i < NUM_ACTOR_INSTANCE; ++i) {
ActorHandle<MyActor> actor = Ray.createActor(MyActor::new);
ActorHandle<MyActor> actor = Ray.actor(MyActor::new).remote();
actors.add(actor);
actorThreadIds.put(actor.getId(), actor.call(MyActor::getThreadId).get());
actorThreadIds.put(actor.getId(), actor.task(MyActor::getThreadId).remote().get());
}
Map<ActorId, List<ObjectRef<Long>>> allResults = new HashMap<>();
@@ -43,7 +43,7 @@ public class SingleProcessModeTest extends BaseTest {
final ActorHandle<MyActor> actor = actors.get(i);
List<ObjectRef<Long>> thisActorResult = new ArrayList<>();
for (int j = 0; j < TIMES_TO_CALL_PER_ACTOR; ++j) {
thisActorResult.add(actor.call(MyActor::getThreadId));
thisActorResult.add(actor.task(MyActor::getThreadId).remote());
}
allResults.put(actor.getId(), thisActorResult);
}
@@ -24,7 +24,7 @@ public class StressTest extends BaseTest {
for (int i = 0; i < numIterations; i++) {
List<ObjectId> resultIds = new ArrayList<>();
for (int j = 0; j < numTasks; j++) {
resultIds.add(Ray.call(StressTest::echo, 1).getId());
resultIds.add(Ray.task(StressTest::echo, 1).remote().getId());
}
for (Integer result : Ray.<Integer>get(resultIds, Integer.class)) {
@@ -37,9 +37,9 @@ public class StressTest extends BaseTest {
@Test
public void testDependency() {
TestUtils.skipTestUnderSingleProcess();
ObjectRef<Integer> x = Ray.call(StressTest::echo, 1);
ObjectRef<Integer> x = Ray.task(StressTest::echo, 1).remote();
for (int i = 0; i < 1000; i++) {
x = Ray.call(StressTest::echo, x);
x = Ray.task(StressTest::echo, x).remote();
}
Assert.assertEquals(x.get(), Integer.valueOf(1));
@@ -63,7 +63,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(actor.call(Actor::ping).getId());
objectIds.add(actor.task(Actor::ping).remote().getId());
}
int sum = 0;
for (Integer result : Ray.<Integer>get(objectIds, Integer.class)) {
@@ -76,11 +76,11 @@ public class StressTest extends BaseTest {
@Test
public void testSubmittingManyTasksToOneActor() throws Exception {
TestUtils.skipTestUnderSingleProcess();
ActorHandle<Actor> actor = Ray.createActor(Actor::new);
ActorHandle<Actor> actor = Ray.actor(Actor::new).remote();
List<ObjectId> objectIds = new ArrayList<>();
for (int i = 0; i < 10; i++) {
ActorHandle<Worker> worker = Ray.createActor(Worker::new, actor);
objectIds.add(worker.call(Worker::ping, 100).getId());
ActorHandle<Worker> worker = Ray.actor(Worker::new, actor).remote();
objectIds.add(worker.task(Worker::ping, 100).remote().getId());
}
for (Integer result : Ray.<Integer>get(objectIds, Integer.class)) {
@@ -75,7 +75,7 @@ public class TestUtils {
* idle workers in Raylet's worker pool.
*/
public static void warmUpCluster() {
ObjectRef<String> obj = Ray.call(TestUtils::hi);
ObjectRef<String> obj = Ray.task(TestUtils::hi).remote();
Assert.assertEquals(obj.get(), "hi");
}
@@ -28,8 +28,8 @@ public class WaitTest extends BaseTest {
// Call a task in advance to warm up the cluster to avoid being too slow to start workers.
TestUtils.warmUpCluster();
ObjectRef<String> obj1 = Ray.call(WaitTest::hi);
ObjectRef<String> obj2 = Ray.call(WaitTest::delayedHi);
ObjectRef<String> obj1 = Ray.task(WaitTest::hi).remote();
ObjectRef<String> obj2 = Ray.task(WaitTest::delayedHi).remote();
List<ObjectRef<String>> waitList = ImmutableList.of(obj1, obj2);
WaitResult<String> waitResult = Ray.wait(waitList, 2, 2 * 1000);
@@ -53,7 +53,7 @@ public class WaitTest extends BaseTest {
@Test
public void testWaitInWorker() {
ObjectRef<Object> res = Ray.call(WaitTest::waitInWorker);
ObjectRef<Object> res = Ray.task(WaitTest::waitInWorker).remote();
res.get();
}
@@ -3,7 +3,6 @@ package io.ray.test;
import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import io.ray.api.options.ActorCreationOptions;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -18,13 +17,12 @@ public class WorkerJvmOptionsTest extends BaseTest {
@Test
public void testJvmOptions() {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options = new ActorCreationOptions.Builder()
// The whitespaces in following argument are intentionally added to test
// that raylet can correctly handle dynamic options with whitespaces.
// The whitespaces in following argument are intentionally added to test
// that raylet can correctly handle dynamic options with whitespaces.
ActorHandle<Echo> actor = Ray.actor(Echo::new)
.setJvmOptions(" -Dtest.suffix=suffix -Dtest.suffix1=suffix1 ")
.createActorCreationOptions();
ActorHandle<Echo> actor = Ray.createActor(Echo::new, options);
ObjectRef<String> obj = actor.call(Echo::getOptions);
.remote();
ObjectRef<String> obj = actor.task(Echo::getOptions).remote();
Assert.assertEquals(obj.get(), "suffix");
}
}