Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ray.api.options;

import java.util.HashMap;
import java.util.Map;

/**
Expand All @@ -12,19 +13,32 @@ public class ActorCreationOptions extends BaseTaskOptions {

public final int maxReconstructions;

public ActorCreationOptions() {
super();
this.maxReconstructions = NO_RECONSTRUCTION;
}

public ActorCreationOptions(Map<String, Double> resources) {
private ActorCreationOptions(Map<String, Double> resources, int maxReconstructions) {
super(resources);
this.maxReconstructions = NO_RECONSTRUCTION;
this.maxReconstructions = maxReconstructions;
}

/**
* The inner class for building ActorCreationOptions.
*/
public static class Builder {

public ActorCreationOptions(Map<String, Double> resources, int maxReconstructions) {
super(resources);
this.maxReconstructions = maxReconstructions;
private Map<String, Double> resources = new HashMap<>();
private int maxReconstructions = NO_RECONSTRUCTION;

public Builder setResources(Map<String, Double> resources) {
this.resources = resources;
return this;
}

public Builder setMaxReconstructions(int maxReconstructions) {
this.maxReconstructions = maxReconstructions;
return this;
}

public ActorCreationOptions createActorCreationOptions() {
return new ActorCreationOptions(resources, maxReconstructions);
}
}

}
23 changes: 18 additions & 5 deletions java/api/src/main/java/org/ray/api/options/CallOptions.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package org.ray.api.options;

import java.util.HashMap;
import java.util.Map;

/**
* The options for RayCall.
*/
public class CallOptions extends BaseTaskOptions {

public CallOptions() {
super();
}

public CallOptions(Map<String, Double> resources) {
private CallOptions(Map<String, Double> resources) {
super(resources);
}

/**
* This inner class for building CallOptions.
*/
public static class Builder {

private Map<String, Double> resources = new HashMap<>();

public Builder setResources(Map<String, Double> resources) {
this.resources = resources;
return this;
}

public CallOptions createCallOptions() {
return new CallOptions(resources);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down Expand Up @@ -47,7 +46,8 @@ public int getPid() {
@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++) {
Expand Down Expand Up @@ -127,8 +127,8 @@ public void checkpointExpired(UniqueId actorId, UniqueId checkpointId) {
@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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static String sayHi() {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ public void testHelloWorld() {
String helloWorld = Ray.call(HelloWorldTest::merge, hello, world).get();
Assert.assertEquals("hello,world!", helloWorld);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ public Integer echo(Integer number) {
@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".
Expand All @@ -64,7 +66,8 @@ public void testMethods() {
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
Expand All @@ -76,9 +79,8 @@ public void testMethods() {
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);
Expand All @@ -87,8 +89,8 @@ public void testActors() {

// 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);
Expand Down