Add placement group java api (#9611)

* add part code

* add part code

* add part code

* fix code style

* fix review comment

* fix review comment

* add part code

* add part code

* add part code

* add part code

* fix review comment

* fix review comment

* fix code style

* fix review comment

* fix lint error

* fix lint error

Co-authored-by: 灵洵 <fengbin.ffb@antfin.com>
This commit is contained in:
fangfengbin
2020-07-25 15:39:05 +08:00
committed by GitHub
parent 5dc4b6686e
commit 28d5f9696d
22 changed files with 403 additions and 26 deletions
@@ -0,0 +1,50 @@
package io.ray.test;
import io.ray.api.ActorHandle;
import io.ray.api.Ray;
import io.ray.api.id.ActorId;
import io.ray.api.placementgroup.PlacementGroup;
import io.ray.api.placementgroup.PlacementStrategy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public class PlacementGroupTest extends BaseTest {
public static class Counter {
private int value;
public Counter(int initValue) {
this.value = initValue;
}
public int getValue() {
return value;
}
}
// TODO(ffbin): Currently Java doesn't support multi-node tests.
// This test just creates a placement group with one bundle.
// It's not comprehensive to test all placement group test cases.
public void testCreateAndCallActor() {
List<Map<String, Double>> bundles = new ArrayList<>();
Map<String, Double> bundle = new HashMap<>();
bundle.put("CPU", 1.0);
bundles.add(bundle);
PlacementStrategy strategy = PlacementStrategy.PACK;
PlacementGroup placementGroup = Ray.createPlacementGroup(bundles, strategy);
// Test creating an actor from a constructor.
ActorHandle<Counter> actor = Ray.actor(Counter::new, 1)
.setPlacementGroup(placementGroup, 0).remote();
Assert.assertNotEquals(actor.getId(), ActorId.NIL);
// Test calling an actor.
Assert.assertEquals(Integer.valueOf(1), actor.task(Counter::getValue).remote().get());
}
}