[Java] Add inner class Builder to build call options. (#4956)

* Add Builder class

* format

* Refactor by IDE

* Remove uncessary dependency
This commit is contained in:
Qing Wang
2019-06-10 23:52:08 +08:00
committed by GitHub
parent 4f8e100fe0
commit e6baffba56
6 changed files with 61 additions and 30 deletions
@@ -3,7 +3,6 @@ package org.ray.api.test;
import static org.ray.runtime.util.SystemUtil.pid;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.ray.api.Checkpointable;
@@ -47,7 +46,8 @@ public class ActorReconstructionTest extends BaseTest {
@Test
public void testActorReconstruction() throws InterruptedException, IOException {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options = new ActorCreationOptions(new HashMap<>(), 1);
ActorCreationOptions options =
new ActorCreationOptions.Builder().setMaxReconstructions(1).createActorCreationOptions();
RayActor<Counter> actor = Ray.createActor(Counter::new, options);
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
@@ -127,8 +127,8 @@ public class ActorReconstructionTest extends BaseTest {
@Test
public void testActorCheckpointing() throws IOException, InterruptedException {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions options = new ActorCreationOptions(new HashMap<>(), 1);
ActorCreationOptions options =
new ActorCreationOptions.Builder().setMaxReconstructions(1).createActorCreationOptions();
RayActor<CheckpointableCounter> actor = Ray.createActor(CheckpointableCounter::new, options);
// Call increase 3 times.
for (int i = 0; i < 3; i++) {
@@ -23,7 +23,8 @@ public class DynamicResourceTest extends BaseTest {
@Test
public void testSetResource() {
TestUtils.skipTestUnderSingleProcess();
CallOptions op1 = new CallOptions(ImmutableMap.of("A", 10.0));
CallOptions op1 =
new CallOptions.Builder().setResources(ImmutableMap.of("A", 10.0)).createCallOptions();
RayObject<String> obj = Ray.call(DynamicResourceTest::sayHi, op1);
WaitResult<String> result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(result.getReady().size(), 0);
@@ -33,4 +33,5 @@ public class HelloWorldTest extends BaseTest {
String helloWorld = Ray.call(HelloWorldTest::merge, hello, world).get();
Assert.assertEquals("hello,world!", helloWorld);
}
}
@@ -46,14 +46,16 @@ public class ResourcesManagementTest extends BaseTest {
@Test
public void testMethods() {
TestUtils.skipTestUnderSingleProcess();
CallOptions callOptions1 = new CallOptions(ImmutableMap.of("CPU", 4.0));
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".
RayObject<Integer> result1 = Ray.call(ResourcesManagementTest::echo, 100, callOptions1);
Assert.assertEquals(100, (int) result1.get());
CallOptions callOptions2 = new CallOptions(ImmutableMap.of("CPU", 4.0));
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".
@@ -64,7 +66,8 @@ public class ResourcesManagementTest extends BaseTest {
Assert.assertEquals(0, waitResult.getUnready().size());
try {
CallOptions callOptions3 = new CallOptions(ImmutableMap.of("CPU", 0.0));
CallOptions callOptions3 =
new CallOptions.Builder().setResources(ImmutableMap.of("CPU", 0.0)).createCallOptions();
Assert.fail();
} catch (RuntimeException e) {
// We should receive a RuntimeException indicates that we should not
@@ -76,9 +79,8 @@ public class ResourcesManagementTest extends BaseTest {
public void testActors() {
TestUtils.skipTestUnderSingleProcess();
ActorCreationOptions actorCreationOptions1 =
new ActorCreationOptions(ImmutableMap.of("CPU", 2.0));
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".
RayActor<Echo> echo1 = Ray.createActor(Echo::new, actorCreationOptions1);
@@ -87,8 +89,8 @@ public class ResourcesManagementTest extends BaseTest {
// 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(ImmutableMap.of("CPU", 8.0));
ActorCreationOptions actorCreationOptions2 = new ActorCreationOptions.Builder()
.setResources(ImmutableMap.of("CPU", 8.0)).createActorCreationOptions();
RayActor<ResourcesManagementTest.Echo> echo2 =
Ray.createActor(Echo::new, actorCreationOptions2);