mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 22:37:36 +08:00
[JavaWorker] Java code lint check and binding to CI (#2225)
* add java code lint check and fix the java code lint error * add java doc lint check and fix the java doc lint error * add java code and doc lint to the CI
This commit is contained in:
committed by
Philipp Moritz
parent
5789a247f9
commit
3b5e700fd7
@@ -46,19 +46,6 @@ public class ActorPressTest extends RayBenchmarkTest {
|
||||
super.rateLimiterPressureTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static class Adder {
|
||||
|
||||
public RemoteResult<Integer> add(Integer n) {
|
||||
RemoteResult<Integer> remoteResult = new RemoteResult<>();
|
||||
remoteResult.setResult(sum += n);
|
||||
remoteResult.setFinishTime(System.nanoTime());
|
||||
return remoteResult;
|
||||
}
|
||||
|
||||
private Integer sum = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayObject<RemoteResult<Integer>> rayCall(RayActor rayActor) {
|
||||
return Ray.call(Adder::add, (RayActor<Adder>) rayActor, 10);
|
||||
@@ -69,4 +56,17 @@ public class ActorPressTest extends RayBenchmarkTest {
|
||||
return true;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static class Adder {
|
||||
|
||||
private Integer sum = 0;
|
||||
|
||||
public RemoteResult<Integer> add(Integer n) {
|
||||
RemoteResult<Integer> remoteResult = new RemoteResult<>();
|
||||
remoteResult.setResult(sum += n);
|
||||
remoteResult.setFinishTime(System.nanoTime());
|
||||
return remoteResult;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,20 +11,9 @@ import org.ray.api.test.MyRunner;
|
||||
@RunWith(MyRunner.class)
|
||||
public class MaxPressureTest extends RayBenchmarkTest {
|
||||
|
||||
private static final long serialVersionUID = -1684518885171395952L;
|
||||
|
||||
public static final int clientNum = 2;
|
||||
|
||||
public static final int totalNum = 10;
|
||||
|
||||
@Test
|
||||
public void Test() {
|
||||
PressureTestParameter pressureTestParameter = new PressureTestParameter();
|
||||
pressureTestParameter.setClientNum(clientNum);
|
||||
pressureTestParameter.setTotalNum(totalNum);
|
||||
pressureTestParameter.setRayBenchmarkTest(this);
|
||||
super.maxPressureTest(pressureTestParameter);
|
||||
}
|
||||
private static final long serialVersionUID = -1684518885171395952L;
|
||||
|
||||
@RayRemote
|
||||
public static RemoteResult<Integer> currentTime() {
|
||||
@@ -34,9 +23,13 @@ public class MaxPressureTest extends RayBenchmarkTest {
|
||||
return remoteResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkResult(Object o) {
|
||||
return (int) o == 0;
|
||||
@Test
|
||||
public void test() {
|
||||
PressureTestParameter pressureTestParameter = new PressureTestParameter();
|
||||
pressureTestParameter.setClientNum(clientNum);
|
||||
pressureTestParameter.setTotalNum(totalNum);
|
||||
pressureTestParameter.setRayBenchmarkTest(this);
|
||||
super.maxPressureTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,4 +38,9 @@ public class MaxPressureTest extends RayBenchmarkTest {
|
||||
return Ray.call(MaxPressureTest::currentTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkResult(Object o) {
|
||||
return (int) o == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,23 +11,10 @@ import org.ray.api.test.MyRunner;
|
||||
@RunWith(MyRunner.class)
|
||||
public class RateLimiterPressureTest extends RayBenchmarkTest {
|
||||
|
||||
private static final long serialVersionUID = 6616958120966144235L;
|
||||
|
||||
public static final int clientNum = 2;
|
||||
|
||||
public static final int totalQps = 2;
|
||||
|
||||
public static final int duration = 10;
|
||||
|
||||
@Test
|
||||
public void Test() {
|
||||
PressureTestParameter pressureTestParameter = new PressureTestParameter();
|
||||
pressureTestParameter.setClientNum(clientNum);
|
||||
pressureTestParameter.setTotalQps(totalQps);
|
||||
pressureTestParameter.setDuration(duration);
|
||||
pressureTestParameter.setRayBenchmarkTest(this);
|
||||
super.rateLimiterPressureTest(pressureTestParameter);
|
||||
}
|
||||
private static final long serialVersionUID = 6616958120966144235L;
|
||||
|
||||
@RayRemote
|
||||
public static RemoteResult<Integer> currentTime() {
|
||||
@@ -37,9 +24,14 @@ public class RateLimiterPressureTest extends RayBenchmarkTest {
|
||||
return remoteResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkResult(Object o) {
|
||||
return (int) o == 0;
|
||||
@Test
|
||||
public void test() {
|
||||
PressureTestParameter pressureTestParameter = new PressureTestParameter();
|
||||
pressureTestParameter.setClientNum(clientNum);
|
||||
pressureTestParameter.setTotalQps(totalQps);
|
||||
pressureTestParameter.setDuration(duration);
|
||||
pressureTestParameter.setRayBenchmarkTest(this);
|
||||
super.rateLimiterPressureTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,4 +39,9 @@ public class RateLimiterPressureTest extends RayBenchmarkTest {
|
||||
|
||||
return Ray.call(RateLimiterPressureTest::currentTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkResult(Object o) {
|
||||
return (int) o == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,78 +15,9 @@ import org.ray.util.logger.RayLog;
|
||||
|
||||
public abstract class RayBenchmarkTest<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 416045641835782523L;
|
||||
|
||||
//not thread safe ,but we only have one thread here
|
||||
public static final DecimalFormat df = new DecimalFormat("00.00");
|
||||
|
||||
private static void printList(List<Long> list) {
|
||||
int len = list.size();
|
||||
int middle = len / 2;
|
||||
int almostHundred = (int) (len * 0.9999);
|
||||
int ninetyNine = (int) (len * 0.99);
|
||||
int ninetyFive = (int) (len * 0.95);
|
||||
int ninety = (int) (len * 0.9);
|
||||
int fifty = (int) (len * 0.5);
|
||||
|
||||
RayLog.core.error("Final result of rt as below:");
|
||||
RayLog.core.error("max: " + list.get(len - 1) + "μs");
|
||||
RayLog.core.error("min: " + list.get(0) + "μs");
|
||||
RayLog.core.error("median: " + list.get(middle) + "μs");
|
||||
RayLog.core.error("99.99% data smaller than: " + list.get(almostHundred) + "μs");
|
||||
RayLog.core.error("99% data smaller than: " + list.get(ninetyNine) + "μs");
|
||||
RayLog.core.error("95% data smaller than: " + list.get(ninetyFive) + "μs");
|
||||
RayLog.core.error("90% data smaller than: " + list.get(ninety) + "μs");
|
||||
RayLog.core.error("50% data smaller than: " + list.get(fifty) + "μs");
|
||||
}
|
||||
|
||||
public void singleLatencyTest(int times, RayActor rayActor) {
|
||||
|
||||
List<Long> counterList = new ArrayList<>();
|
||||
for (int i = 0; i < times; i++) {
|
||||
long startTime = System.nanoTime();
|
||||
RayObject<RemoteResult<T>> rayObject = rayCall(rayActor);
|
||||
RemoteResult<T> remoteResult = rayObject.get();
|
||||
T t = remoteResult.getResult();
|
||||
long endTime = System.nanoTime();
|
||||
long costTime = endTime - startTime;
|
||||
counterList.add(costTime / 1000);
|
||||
RayLog.core.warn("SINGLE_LATENCY_cost_time: " + costTime + " us");
|
||||
Assert.assertTrue(checkResult(t));
|
||||
}
|
||||
Collections.sort(counterList);
|
||||
printList(counterList);
|
||||
}
|
||||
|
||||
public void rateLimiterPressureTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
pressureTestParameter.setPressureTestType(PressureTestType.RATE_LIMITER);
|
||||
notSinglePressTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
public void maxPressureTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
pressureTestParameter.setPressureTestType(PressureTestType.MAX);
|
||||
notSinglePressTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
private void notSinglePressTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
List<Long> counterList = new ArrayList<>();
|
||||
int clientNum = pressureTestParameter.getClientNum();
|
||||
RayObject<List<Long>>[] rayObjects = new RayObject[clientNum];
|
||||
|
||||
for (int i = 0; i < clientNum; i++) {
|
||||
rayObjects[i] = Ray.call(RayBenchmarkTest::singleClient, pressureTestParameter);
|
||||
}
|
||||
for (int i = 0; i < clientNum; i++) {
|
||||
List<Long> subCounterList = rayObjects[i].get();
|
||||
Assert.assertNotNull(subCounterList);
|
||||
counterList.addAll(subCounterList);
|
||||
}
|
||||
Collections.sort(counterList);
|
||||
printList(counterList);
|
||||
}
|
||||
private static final long serialVersionUID = 416045641835782523L;
|
||||
|
||||
@RayRemote
|
||||
private static List<Long> singleClient(PressureTestParameter pressureTestParameter) {
|
||||
@@ -117,10 +48,6 @@ public abstract class RayBenchmarkTest<T> implements Serializable {
|
||||
if (rateLimiter != null) {
|
||||
rateLimiter.acquire();
|
||||
}
|
||||
// Date currentTime = new Date();
|
||||
// String dateString = formatter.format(currentTime);
|
||||
// RayLog.core.info(logPrefix + "_startTime: " + dateString);
|
||||
|
||||
RemoteResultWrapper temp = new RemoteResultWrapper();
|
||||
temp.setStartTime(System.nanoTime());
|
||||
temp.setRayObject(rayBenchmarkTest.rayCall(pressureTestParameter.getRayActor()));
|
||||
@@ -145,8 +72,76 @@ public abstract class RayBenchmarkTest<T> implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
abstract public RayObject<RemoteResult<T>> rayCall(RayActor rayActor);
|
||||
public void singleLatencyTest(int times, RayActor rayActor) {
|
||||
|
||||
abstract public boolean checkResult(T t);
|
||||
List<Long> counterList = new ArrayList<>();
|
||||
for (int i = 0; i < times; i++) {
|
||||
long startTime = System.nanoTime();
|
||||
RayObject<RemoteResult<T>> rayObject = rayCall(rayActor);
|
||||
RemoteResult<T> remoteResult = rayObject.get();
|
||||
T t = remoteResult.getResult();
|
||||
long endTime = System.nanoTime();
|
||||
long costTime = endTime - startTime;
|
||||
counterList.add(costTime / 1000);
|
||||
RayLog.core.warn("SINGLE_LATENCY_cost_time: " + costTime + " us");
|
||||
Assert.assertTrue(checkResult(t));
|
||||
}
|
||||
Collections.sort(counterList);
|
||||
printList(counterList);
|
||||
}
|
||||
|
||||
public abstract RayObject<RemoteResult<T>> rayCall(RayActor rayActor);
|
||||
|
||||
public abstract boolean checkResult(T t);
|
||||
|
||||
private void printList(List<Long> list) {
|
||||
int len = list.size();
|
||||
int middle = len / 2;
|
||||
int almostHundred = (int) (len * 0.9999);
|
||||
int ninetyNine = (int) (len * 0.99);
|
||||
int ninetyFive = (int) (len * 0.95);
|
||||
int ninety = (int) (len * 0.9);
|
||||
int fifty = (int) (len * 0.5);
|
||||
|
||||
RayLog.core.error("Final result of rt as below:");
|
||||
RayLog.core.error("max: " + list.get(len - 1) + "μs");
|
||||
RayLog.core.error("min: " + list.get(0) + "μs");
|
||||
RayLog.core.error("median: " + list.get(middle) + "μs");
|
||||
RayLog.core.error("99.99% data smaller than: " + list.get(almostHundred) + "μs");
|
||||
RayLog.core.error("99% data smaller than: " + list.get(ninetyNine) + "μs");
|
||||
RayLog.core.error("95% data smaller than: " + list.get(ninetyFive) + "μs");
|
||||
RayLog.core.error("90% data smaller than: " + list.get(ninety) + "μs");
|
||||
RayLog.core.error("50% data smaller than: " + list.get(fifty) + "μs");
|
||||
}
|
||||
|
||||
public void rateLimiterPressureTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
pressureTestParameter.setPressureTestType(PressureTestType.RATE_LIMITER);
|
||||
notSinglePressTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
private void notSinglePressTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
List<Long> counterList = new ArrayList<>();
|
||||
int clientNum = pressureTestParameter.getClientNum();
|
||||
RayObject<List<Long>>[] rayObjects = new RayObject[clientNum];
|
||||
|
||||
for (int i = 0; i < clientNum; i++) {
|
||||
rayObjects[i] = Ray.call(RayBenchmarkTest::singleClient, pressureTestParameter);
|
||||
}
|
||||
for (int i = 0; i < clientNum; i++) {
|
||||
List<Long> subCounterList = rayObjects[i].get();
|
||||
Assert.assertNotNull(subCounterList);
|
||||
counterList.addAll(subCounterList);
|
||||
}
|
||||
Collections.sort(counterList);
|
||||
printList(counterList);
|
||||
}
|
||||
|
||||
public void maxPressureTest(PressureTestParameter pressureTestParameter) {
|
||||
|
||||
pressureTestParameter.setPressureTestType(PressureTestType.MAX);
|
||||
notSinglePressTest(pressureTestParameter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,14 +11,8 @@ import org.ray.api.test.MyRunner;
|
||||
@RunWith(MyRunner.class)
|
||||
public class SingleLatencyTest extends RayBenchmarkTest {
|
||||
|
||||
private static final long serialVersionUID = 3559601273941694468L;
|
||||
|
||||
public static final int totalNum = 10;
|
||||
|
||||
@Test
|
||||
public void Test() {
|
||||
super.singleLatencyTest(totalNum, null);
|
||||
}
|
||||
private static final long serialVersionUID = 3559601273941694468L;
|
||||
|
||||
@RayRemote
|
||||
public static RemoteResult<Integer> doFunc() {
|
||||
@@ -27,6 +21,11 @@ public class SingleLatencyTest extends RayBenchmarkTest {
|
||||
return remoteResult;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
super.singleLatencyTest(totalNum, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RayObject<RemoteResult<Integer>> rayCall(RayActor rayActor) {
|
||||
return Ray.call(SingleLatencyTest::doFunc);
|
||||
|
||||
@@ -13,15 +13,15 @@ import org.ray.api.RayObject;
|
||||
import org.ray.api.RayRemote;
|
||||
|
||||
/**
|
||||
* mimic the MapReduce interface atop of Ray API (in memory version)
|
||||
* mimic the MapReduce interface atop of Ray API (in memory version).
|
||||
*/
|
||||
public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
public class MemoryMapReduce<TInputT, TMapKeyT, TMapValueT, TReduceValueT> {
|
||||
|
||||
public List<Pair<TMapKey, TMapValue>> Map(TInput input) throws Exception {
|
||||
public List<Pair<TMapKeyT, TMapValueT>> map(TInputT input) throws Exception {
|
||||
throw new Exception("not implemented");
|
||||
}
|
||||
|
||||
public TReduceValue Reduce(TMapKey k, List<TMapValue> values) throws Exception {
|
||||
public TReduceValueT reduce(TMapKeyT k, List<TMapValueT> values) throws Exception {
|
||||
throw new Exception("not implemented");
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
// @param inputs - given input file segments each containing List<TInput>
|
||||
// @return output file segments each containing SortedMap<TMapKey, TReduceValue>
|
||||
//
|
||||
public SortedMap<TMapKey, TReduceValue> Run(List<List<TInput>> inputs, int mapperCount,
|
||||
Integer reducerCount) {
|
||||
public SortedMap<TMapKeyT, TReduceValueT> run(List<List<TInputT>> inputs, int mapperCount,
|
||||
Integer reducerCount) {
|
||||
// start all mappers
|
||||
ArrayList<RayList<SortedMap<TMapKey, List<TMapValue>>>> mappers = new ArrayList<>();
|
||||
ArrayList<RayList<SortedMap<TMapKeyT, List<TMapValueT>>>> mappers = new ArrayList<>();
|
||||
|
||||
int inputCountPerMap = inputs.size() / mapperCount;
|
||||
int index = 0;
|
||||
@@ -43,12 +43,12 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
break;
|
||||
}
|
||||
|
||||
List<List<TInput>> perMapInputs = new ArrayList<>();
|
||||
List<List<TInputT>> perMapInputs = new ArrayList<>();
|
||||
for (int j = 0; j < inputCountPerMap && index < inputs.size(); j++) {
|
||||
perMapInputs.add(inputs.get(index++));
|
||||
}
|
||||
|
||||
mappers.add(Ray.call_n(MemoryMapReduce::InternalMap, reducerCount, reducerCount, perMapInputs,
|
||||
mappers.add(Ray.call_n(MemoryMapReduce::internalMap, reducerCount, reducerCount, perMapInputs,
|
||||
this.getClass().getName()));
|
||||
}
|
||||
|
||||
@@ -57,18 +57,18 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
// Ray.wait(mappers.toArray(new RayObject<?>[0]), mappers.size(), 0);
|
||||
|
||||
// start all reducers
|
||||
ArrayList<RayObject<SortedMap<TMapKey, TReduceValue>>> reducers = new ArrayList<>();
|
||||
ArrayList<RayObject<SortedMap<TMapKeyT, TReduceValueT>>> reducers = new ArrayList<>();
|
||||
for (int i = 0; i < reducerCount; i++) {
|
||||
// collect states from mappers for this reducer
|
||||
RayList<SortedMap<TMapKey, List<TMapValue>>> fromMappers = new RayList();
|
||||
RayList<SortedMap<TMapKeyT, List<TMapValueT>>> fromMappers = new RayList();
|
||||
for (int j = 0; j < mapperCount; j++) {
|
||||
assert (mappers.get(j).size() == reducerCount);
|
||||
fromMappers.add(mappers.get(j).Get(i));
|
||||
}
|
||||
|
||||
// start this reducer with given input
|
||||
reducers.add(Ray.call(MemoryMapReduce::InternalReduce,
|
||||
(List<SortedMap<TMapKey, List<TMapValue>>>) fromMappers, this.getClass().getName()));
|
||||
reducers.add(Ray.call(MemoryMapReduce::internalReduce,
|
||||
(List<SortedMap<TMapKeyT, List<TMapValueT>>>) fromMappers, this.getClass().getName()));
|
||||
}
|
||||
|
||||
// BSP barrier for all reducers to be finished
|
||||
@@ -76,8 +76,8 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
// Ray.wait(reducers.toArray(new RayObject<?>[0]), reducers.size(), 0);
|
||||
|
||||
// collect outputs
|
||||
TreeMap<TMapKey, TReduceValue> outputs = new TreeMap<>();
|
||||
for (RayObject<SortedMap<TMapKey, TReduceValue>> r : reducers) {
|
||||
TreeMap<TMapKeyT, TReduceValueT> outputs = new TreeMap<>();
|
||||
for (RayObject<SortedMap<TMapKeyT, TReduceValueT>> r : reducers) {
|
||||
r.get().forEach(outputs::put);
|
||||
}
|
||||
return outputs;
|
||||
@@ -91,13 +91,14 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
// for each output file, it contains SortedMap<TMapKey, List<TMapValue>>
|
||||
//
|
||||
@RayRemote
|
||||
public static <TInput, TMapKey, TMapValue, TReduceValue> List<SortedMap<TMapKey, List<TMapValue>>> InternalMap(
|
||||
public static <TInputT, TMapKeyT, TMapValueT, TReduceValueT> List<SortedMap<TMapKeyT,
|
||||
List<TMapValueT>>> internalMap(
|
||||
Integer reducerCount,
|
||||
List<List<TInput>> inputs,
|
||||
List<List<TInputT>> inputs,
|
||||
String mrClassName) {
|
||||
MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> mr;
|
||||
MemoryMapReduce<TInputT, TMapKeyT, TMapValueT, TReduceValueT> mr;
|
||||
try {
|
||||
mr = (MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue>) Class
|
||||
mr = (MemoryMapReduce<TInputT, TMapKeyT, TMapValueT, TReduceValueT>) Class
|
||||
.forName(mrClassName).getConstructors()[0].newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | SecurityException | ClassNotFoundException e1) {
|
||||
@@ -106,16 +107,16 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<SortedMap<TMapKey, List<TMapValue>>> out = new ArrayList<>();
|
||||
ArrayList<SortedMap<TMapKeyT, List<TMapValueT>>> out = new ArrayList<>();
|
||||
for (int i = 0; i < reducerCount; i++) {
|
||||
out.add(new TreeMap<>());
|
||||
}
|
||||
|
||||
for (List<TInput> inputSeg : inputs) {
|
||||
for (TInput input : inputSeg) {
|
||||
for (List<TInputT> inputSeg : inputs) {
|
||||
for (TInputT input : inputSeg) {
|
||||
try {
|
||||
List<Pair<TMapKey, TMapValue>> result = mr.Map(input);
|
||||
for (Pair<TMapKey, TMapValue> pr : result) {
|
||||
List<Pair<TMapKeyT, TMapValueT>> result = mr.map(input);
|
||||
for (Pair<TMapKeyT, TMapValueT> pr : result) {
|
||||
int reducerIndex = Math.abs(pr.getKey().hashCode()) % reducerCount;
|
||||
out.get(reducerIndex).computeIfAbsent(pr.getKey(), k -> new ArrayList<>());
|
||||
out.get(reducerIndex).get(pr.getKey()).add(pr.getValue());
|
||||
@@ -138,12 +139,13 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
// @return an output file contains SortedMap<TMapKey, TReduceValue>
|
||||
//
|
||||
@RayRemote
|
||||
public static <TInput, TMapKey, TMapValue, TReduceValue> SortedMap<TMapKey, TReduceValue> InternalReduce(
|
||||
List<SortedMap<TMapKey, List<TMapValue>>> inputs,
|
||||
public static <TInputT, TMapKeyT, TMapValueT, TReduceValueT> SortedMap<TMapKeyT, TReduceValueT>
|
||||
internalReduce(
|
||||
List<SortedMap<TMapKeyT, List<TMapValueT>>> inputs,
|
||||
String mrClassName) {
|
||||
MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> mr;
|
||||
MemoryMapReduce<TInputT, TMapKeyT, TMapValueT, TReduceValueT> mr;
|
||||
try {
|
||||
mr = (MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue>) Class
|
||||
mr = (MemoryMapReduce<TInputT, TMapKeyT, TMapValueT, TReduceValueT>) Class
|
||||
.forName(mrClassName).getConstructors()[0].newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
|
||||
| InvocationTargetException | SecurityException | ClassNotFoundException e1) {
|
||||
@@ -153,9 +155,9 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
}
|
||||
|
||||
// merge inputs from many mappers
|
||||
TreeMap<TMapKey, List<TMapValue>> minputs = new TreeMap<>();
|
||||
for (SortedMap<TMapKey, List<TMapValue>> input : inputs) {
|
||||
for (Map.Entry<TMapKey, List<TMapValue>> entry : input.entrySet()) {
|
||||
TreeMap<TMapKeyT, List<TMapValueT>> minputs = new TreeMap<>();
|
||||
for (SortedMap<TMapKeyT, List<TMapValueT>> input : inputs) {
|
||||
for (Map.Entry<TMapKeyT, List<TMapValueT>> entry : input.entrySet()) {
|
||||
if (!minputs.containsKey(entry.getKey())) {
|
||||
minputs.put(entry.getKey(), new ArrayList<>());
|
||||
}
|
||||
@@ -164,10 +166,10 @@ public class MemoryMapReduce<TInput, TMapKey, TMapValue, TReduceValue> {
|
||||
}
|
||||
|
||||
// reduce
|
||||
TreeMap<TMapKey, TReduceValue> out = new TreeMap<>();
|
||||
for (Map.Entry<TMapKey, List<TMapValue>> entry : minputs.entrySet()) {
|
||||
TreeMap<TMapKeyT, TReduceValueT> out = new TreeMap<>();
|
||||
for (Map.Entry<TMapKeyT, List<TMapValueT>> entry : minputs.entrySet()) {
|
||||
try {
|
||||
out.put(entry.getKey(), mr.Reduce(entry.getKey(), entry.getValue()));
|
||||
out.put(entry.getKey(), mr.reduce(entry.getKey(), entry.getValue()));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -14,8 +14,14 @@ import org.ray.api.UniqueID;
|
||||
@RunWith(MyRunner.class)
|
||||
public class ActorTest {
|
||||
|
||||
@RayRemote
|
||||
public static Integer sayWorld(Integer n, RayActor<ActorTest.Adder> adder) {
|
||||
RayObject<Integer> result = Ray.call(ActorTest.Adder::add, adder, 1);
|
||||
return result.get() + n;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Test() {
|
||||
public void test() {
|
||||
|
||||
RayActor<ActorTest.Adder> adder = Ray.create(ActorTest.Adder.class);
|
||||
Ray.call(Adder::set, adder, 10);
|
||||
@@ -55,6 +61,11 @@ public class ActorTest {
|
||||
public static class Adder {
|
||||
|
||||
private List<RayObject<Integer>> objectList;
|
||||
private Integer sum = 0;
|
||||
|
||||
public static Integer add2(Integer n) {
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
public Integer set(Integer n) {
|
||||
sum = n;
|
||||
@@ -69,10 +80,6 @@ public class ActorTest {
|
||||
return (sum += n);
|
||||
}
|
||||
|
||||
public static Integer add2(Integer n) {
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
public Integer setObjectList(List<RayObject<Integer>> objectList) {
|
||||
this.objectList = objectList;
|
||||
return 1;
|
||||
@@ -81,14 +88,6 @@ public class ActorTest {
|
||||
public Integer testObjectList() {
|
||||
return ((RayObject<Integer>) objectList.get(0)).get();
|
||||
}
|
||||
|
||||
private Integer sum = 0;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Integer sayWorld(Integer n, RayActor<ActorTest.Adder> adder) {
|
||||
RayObject<Integer> result = Ray.call(ActorTest.Adder::add, adder, 1);
|
||||
return result.get() + n;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
@@ -99,6 +98,11 @@ public class ActorTest {
|
||||
private List<RayActor<Adder>> adderList;
|
||||
|
||||
private UniqueID id;
|
||||
private Integer sum = 0;
|
||||
|
||||
public static Integer add2(Adder a, Integer n) {
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
public Integer set(Integer n) {
|
||||
sum = n;
|
||||
@@ -121,10 +125,6 @@ public class ActorTest {
|
||||
return (sum += n);
|
||||
}
|
||||
|
||||
public static Integer add2(Adder a, Integer n) {
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
public RayActor<Adder> getAdder() {
|
||||
return adder;
|
||||
}
|
||||
@@ -148,7 +148,5 @@ public class ActorTest {
|
||||
this.adderList = adderList;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private Integer sum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,25 @@ import org.ray.api.RayRemote;
|
||||
@RunWith(MyRunner.class)
|
||||
public class EchoTest {
|
||||
|
||||
@RayRemote
|
||||
public static String hi() {
|
||||
return "hi";
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String who(String who) {
|
||||
return who;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String recho(String pre, String who) {
|
||||
return pre + ", " + who + "!";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
long startTime, endTime;
|
||||
long startTime = 0;
|
||||
long endTime = 0;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
startTime = System.nanoTime();
|
||||
String ret = echo("Ray++" + i);
|
||||
@@ -19,28 +35,12 @@ public class EchoTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String echo(String who) {
|
||||
|
||||
return Ray.call(
|
||||
EchoTest::recho,
|
||||
Ray.call(EchoTest::Hi),
|
||||
Ray.call(EchoTest::Who, who)
|
||||
Ray.call(EchoTest::hi),
|
||||
Ray.call(EchoTest::who, who)
|
||||
).get();
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String Hi() {
|
||||
return "Hi";
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String Who(String who) {
|
||||
return who;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String recho(String pre, String who) {
|
||||
return pre + ", " + who + "!";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,25 +9,11 @@ import org.ray.api.RayRemote;
|
||||
import org.ray.util.logger.RayLog;
|
||||
|
||||
/**
|
||||
* Hello world
|
||||
* Hello world.
|
||||
*/
|
||||
@RunWith(MyRunner.class)
|
||||
public class HelloWorldTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String helloWorld = sayHelloWorld();
|
||||
RayLog.rapp.info(helloWorld);
|
||||
Assert.assertEquals("hello,world!", helloWorld);
|
||||
Assert.assertTrue(Ray.call(TypesTest::sayBool).get());
|
||||
}
|
||||
|
||||
public String sayHelloWorld() {
|
||||
RayObject<String> hello = Ray.call(HelloWorldTest::sayHello);
|
||||
RayObject<String> world = Ray.call(HelloWorldTest::sayWorld);
|
||||
return Ray.call(HelloWorldTest::merge, hello, world).get();
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String sayHello() {
|
||||
String ret = "he";
|
||||
@@ -48,4 +34,18 @@ public class HelloWorldTest {
|
||||
public static String merge(String hello, String world) {
|
||||
return hello + "," + world;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
String helloWorld = sayHelloWorld();
|
||||
RayLog.rapp.info(helloWorld);
|
||||
Assert.assertEquals("hello,world!", helloWorld);
|
||||
Assert.assertTrue(Ray.call(TypesTest::sayBool).get());
|
||||
}
|
||||
|
||||
public String sayHelloWorld() {
|
||||
RayObject<String> hello = Ray.call(HelloWorldTest::sayHello);
|
||||
RayObject<String> world = Ray.call(HelloWorldTest::sayWorld);
|
||||
return Ray.call(HelloWorldTest::merge, hello, world).get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,26 +10,11 @@ import org.junit.runner.RunWith;
|
||||
import org.ray.api.experiment.mr.MemoryMapReduce;
|
||||
|
||||
/**
|
||||
* test the MapReduce interface
|
||||
* test the MapReduce interface.
|
||||
*/
|
||||
@RunWith(MyRunner.class)
|
||||
public class MemoryWordCountTest {
|
||||
|
||||
public static class MemoryWordCount extends MemoryMapReduce<String, String, Integer, Integer> {
|
||||
|
||||
public List<Pair<String, Integer>> Map(String input) {
|
||||
ArrayList<Pair<String, Integer>> counts = new ArrayList<>();
|
||||
for (String s : input.split(" ")) {
|
||||
counts.add(Pair.of(s, 1));
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
public Integer Reduce(String k, List<Integer> values) {
|
||||
return values.size();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
List<List<String>> iinputs = new ArrayList<>();
|
||||
@@ -55,7 +40,7 @@ public class MemoryWordCountTest {
|
||||
iinputs.add(inputs);
|
||||
|
||||
MemoryWordCount wc = new MemoryWordCount();
|
||||
SortedMap<String, Integer> result = wc.Run(iinputs, 2, 2);
|
||||
SortedMap<String, Integer> result = wc.run(iinputs, 2, 2);
|
||||
|
||||
Assert.assertEquals(6, (int) result.get("0"));
|
||||
Assert.assertEquals(6, (int) result.get("1"));
|
||||
@@ -68,4 +53,19 @@ public class MemoryWordCountTest {
|
||||
Assert.assertEquals(6, (int) result.get("8"));
|
||||
Assert.assertEquals(6, (int) result.get("9"));
|
||||
}
|
||||
|
||||
public static class MemoryWordCount extends MemoryMapReduce<String, String, Integer, Integer> {
|
||||
|
||||
public List<Pair<String, Integer>> map(String input) {
|
||||
ArrayList<Pair<String, Integer>> counts = new ArrayList<>();
|
||||
for (String s : input.split(" ")) {
|
||||
counts.add(Pair.of(s, 1));
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
public Integer reduce(String k, List<Integer> values) {
|
||||
return values.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,29 +24,27 @@ public class RayMethodsTest {
|
||||
RayObject<String> s2Id = Ray.put(String.valueOf("World!"));
|
||||
RayObject<Object> n1Id = Ray.put(null);
|
||||
|
||||
RayList<String> wIds = new RayList<>();
|
||||
wIds.add(s1Id);
|
||||
wIds.add(s2Id);
|
||||
WaitResult<String> readys = Ray.wait(wIds, 2);
|
||||
RayList<String> waitIds = new RayList<>();
|
||||
waitIds.add(s1Id);
|
||||
waitIds.add(s2Id);
|
||||
WaitResult<String> readys = Ray.wait(waitIds, 2);
|
||||
|
||||
List<String> ss = readys.getReadyOnes().get();
|
||||
int i1 = i1Id.get();
|
||||
double f1 = f1Id.get();
|
||||
Object n1 = n1Id.get();
|
||||
|
||||
RayLog.rapp.info("Strings: " + ss.get(0) + ss.get(1) +
|
||||
" int: " + i1 +
|
||||
" double: " + f1 +
|
||||
" null: " + n1);
|
||||
RayLog.rapp.info("Strings: " + ss.get(0) + ss.get(1) + " int: " + i1 + " double: " + f1
|
||||
+ " null: " + n1);
|
||||
Assert.assertEquals("Hello World!", ss.get(0) + ss.get(1));
|
||||
Assert.assertEquals(1, i1);
|
||||
Assert.assertEquals(3.14, f1, Double.MIN_NORMAL);
|
||||
Assert.assertNull(n1);
|
||||
|
||||
// metadata test
|
||||
RayObject<Integer> vId = Ray.put(643, "test metadata");
|
||||
Integer v = vId.get();
|
||||
String m = vId.getMeta();
|
||||
RayObject<Integer> vid = Ray.put(643, "test metadata");
|
||||
Integer v = vid.get();
|
||||
String m = vid.getMeta();
|
||||
|
||||
Assert.assertEquals(643L, v.longValue());
|
||||
Assert.assertEquals("test metadata", m);
|
||||
|
||||
@@ -9,20 +9,19 @@ import org.ray.util.RemoteFunction;
|
||||
@RunWith(MyRunner.class)
|
||||
public class RemoteLambdaTest {
|
||||
|
||||
public static <T> String RemoteToString(T o) {
|
||||
public static <T> String remoteToString(T o) {
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
RemoteFunction<String, String> f0 = RemoteLambdaTest::RemoteToString;
|
||||
RemoteFunction<String, String> f0 = RemoteLambdaTest::remoteToString;
|
||||
byte[] bytes = SerializationUtils.serialize(f0);
|
||||
//System.out.println(new String(bytes));
|
||||
//Object m = SerializationUtils.deserialize(bytes);
|
||||
|
||||
RemoteFunction<Integer, Integer> f = x ->
|
||||
{
|
||||
RemoteFunction<Integer, Integer> f = x -> {
|
||||
System.out.println("remote function " + x);
|
||||
return x + 1;
|
||||
};
|
||||
@@ -31,8 +30,7 @@ public class RemoteLambdaTest {
|
||||
Assert.assertEquals(101, (int) f2.apply(100));
|
||||
|
||||
Integer y = 100;
|
||||
RemoteFunction<Integer, Integer> f3 = x ->
|
||||
{
|
||||
RemoteFunction<Integer, Integer> f3 = x -> {
|
||||
System.out.println("remote function " + x);
|
||||
return x + y + 1;
|
||||
};
|
||||
|
||||
@@ -9,14 +9,6 @@ import org.ray.api.RayRemote;
|
||||
@RunWith(MyRunner.class)
|
||||
public class RpcTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals(0, (int) Ray.call(RpcTest::with0Params).get());
|
||||
Assert.assertEquals(1, (int) Ray.call(RpcTest::with1Params, 1).get());
|
||||
Assert.assertEquals(3, (int) Ray.call(RpcTest::with2Params, 1, 2).get());
|
||||
Assert.assertEquals(6, (int) Ray.call(RpcTest::with3Params, 1, 2, 3).get());
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Integer with0Params() {
|
||||
return 0;
|
||||
@@ -36,4 +28,12 @@ public class RpcTest {
|
||||
public static Integer with3Params(Integer x, Integer y, Integer z) {
|
||||
return x + y + z;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals(0, (int) Ray.call(RpcTest::with0Params).get());
|
||||
Assert.assertEquals(1, (int) Ray.call(RpcTest::with1Params, 1).get());
|
||||
Assert.assertEquals(3, (int) Ray.call(RpcTest::with2Params, 1, 2).get());
|
||||
Assert.assertEquals(6, (int) Ray.call(RpcTest::with3Params, 1, 2, 3).get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.junit.runner.RunWith;
|
||||
import org.ray.api.Ray;
|
||||
|
||||
/**
|
||||
* local test in IDE, for class lazy load
|
||||
* local test in IDE, for class lazy load.
|
||||
*/
|
||||
@RunWith(MyRunner.class)
|
||||
public class TwoClassTest {
|
||||
|
||||
@@ -19,11 +19,114 @@ import org.ray.api.returns.MultipleReturns2;
|
||||
import org.ray.api.returns.RayObjects2;
|
||||
|
||||
/**
|
||||
* types test
|
||||
* types test.
|
||||
*/
|
||||
@RunWith(MyRunner.class)
|
||||
public class TypesTest {
|
||||
|
||||
@RayRemote
|
||||
public static int sayInt() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static byte sayByte() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static short sayShort() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static long sayLong() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static double sayDouble() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static float sayFloat() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static boolean sayBool() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Object sayReference() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static MultipleReturns2<Integer, String> sayReferences() {
|
||||
return new MultipleReturns2<>(123, "123");
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Map<Integer, String> sayReferencesN(Collection<Integer> userReturnIds,
|
||||
String prefix, String suffix) {
|
||||
Map<Integer, String> ret = new HashMap<>();
|
||||
for (Integer returnid : userReturnIds) {
|
||||
ret.put(returnid, prefix + returnid + suffix);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static List<Integer> sayArray(Integer returnCount) {
|
||||
ArrayList<Integer> rets = new ArrayList<>();
|
||||
for (int i = 0; i < returnCount; i++) {
|
||||
rets.add(i);
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
@RayRemote(externalIo = true)
|
||||
public static Integer sayRayFuture() {
|
||||
return 123;
|
||||
}
|
||||
|
||||
@RayRemote(externalIo = true)
|
||||
public static MultipleReturns2<Integer, String> sayRayFutures() {
|
||||
return new MultipleReturns2<>(123, "123");
|
||||
}
|
||||
|
||||
@RayRemote(externalIo = true)
|
||||
public static Map<Integer, String> sayRayFuturesN(
|
||||
Collection<Integer/*user's custom return_id*/> userReturnIds,
|
||||
String prefix) {
|
||||
Map<Integer, String> ret = new HashMap<>();
|
||||
for (int id : userReturnIds) {
|
||||
ret.put(id, prefix + id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static int sayReadRayList(List<Integer> ints) {
|
||||
int sum = 0;
|
||||
for (Integer i : ints) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static int sayReadRayMap(Map<String, Integer> ints) {
|
||||
int sum = 0;
|
||||
for (Integer i : ints.values()) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
sayTypes();
|
||||
@@ -83,7 +186,7 @@ public class TypesTest {
|
||||
ints.add(Ray.call(TypesTest::sayInt));
|
||||
ints.add(Ray.call(TypesTest::sayInt));
|
||||
// TODO: when RayParameters.use_remote_lambda is on, we have to explicitly
|
||||
// cast RayList and RayMap to List and Map explicitly, so that the parameter
|
||||
// cast RayList and RayMap to List and map explicitly, so that the parameter
|
||||
// types of the lambdas can be correctly deducted.
|
||||
RayObject<Integer> collection = Ray.call(TypesTest::sayReadRayList, (List<Integer>) ints);
|
||||
Assert.assertEquals(3, (int) collection.get());
|
||||
@@ -96,107 +199,4 @@ public class TypesTest {
|
||||
.call(TypesTest::sayReadRayMap, (Map<String, Integer>) namedInts);
|
||||
Assert.assertEquals(3, (int) collection2.get());
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static int sayInt() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static byte sayByte() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static short sayShort() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static long sayLong() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static double sayDouble() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static float sayFloat() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static boolean sayBool() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Object sayReference() {
|
||||
return "object";
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static MultipleReturns2<Integer, String> sayReferences() {
|
||||
return new MultipleReturns2<>(123, "123");
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Map<Integer, String> sayReferencesN(Collection<Integer> userReturnIds,
|
||||
String prefix, String suffix) {
|
||||
Map<Integer, String> ret = new HashMap<>();
|
||||
for (Integer returnid : userReturnIds) {
|
||||
ret.put(returnid, prefix + returnid + suffix);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static List<Integer> sayArray(Integer returnCount) {
|
||||
ArrayList<Integer> rets = new ArrayList<>();
|
||||
for (int i = 0; i < returnCount; i++) {
|
||||
rets.add(i);
|
||||
}
|
||||
return rets;
|
||||
}
|
||||
|
||||
@RayRemote(externalIO = true)
|
||||
public static Integer sayRayFuture() {
|
||||
return 123;
|
||||
}
|
||||
|
||||
@RayRemote(externalIO = true)
|
||||
public static MultipleReturns2<Integer, String> sayRayFutures() {
|
||||
return new MultipleReturns2<>(123, "123");
|
||||
}
|
||||
|
||||
@RayRemote(externalIO = true)
|
||||
public static Map<Integer, String> sayRayFuturesN(
|
||||
Collection<Integer/*user's custom return_id*/> userReturnIds,
|
||||
String prefix) {
|
||||
Map<Integer, String> ret = new HashMap<>();
|
||||
for (int id : userReturnIds) {
|
||||
ret.put(id, prefix + id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static int sayReadRayList(List<Integer> ints) {
|
||||
int sum = 0;
|
||||
for (Integer i : ints) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static int sayReadRayMap(Map<String, Integer> ints) {
|
||||
int sum = 0;
|
||||
for (Integer i : ints.values()) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -11,14 +11,20 @@ import org.ray.core.RayRuntime;
|
||||
import org.ray.core.UniqueIdHelper;
|
||||
|
||||
@RunWith(MyRunner.class)
|
||||
public class UniqueIDTest {
|
||||
public class UIdTest {
|
||||
|
||||
|
||||
@RayRemote
|
||||
public static String hi(Integer i) {
|
||||
return "hi" + i;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
UniqueID tid = UniqueIdHelper.nextTaskId(0xdeadbeefL);
|
||||
UniqueIdHelper.setTest(tid, true);
|
||||
System.out.println("Tested task id = " + tid);
|
||||
RayFunc_1_1<Integer, String> f = UniqueIDTest::hi;
|
||||
RayFunc_1_1<Integer, String> f = UIdTest::hi;
|
||||
RayObject<String> result = new RayObject<>(
|
||||
RayRuntime.getInstance().call(
|
||||
tid,
|
||||
@@ -30,9 +36,4 @@ public class UniqueIDTest {
|
||||
System.out.println("Tested task return object id = " + result.getId());
|
||||
Assert.assertEquals("hi1", result.get());
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static String hi(Integer i) {
|
||||
return "hi" + i;
|
||||
}
|
||||
}
|
||||
@@ -11,30 +11,10 @@ import org.ray.util.FileUtil;
|
||||
|
||||
/**
|
||||
* given a directory of document files on each "machine", we would like to count the appearance of
|
||||
* some word
|
||||
* some word.
|
||||
*/
|
||||
public class WordCountTest {
|
||||
|
||||
//@Test
|
||||
public void test() {
|
||||
int sum = mapReduce();
|
||||
Assert.assertEquals(sum, 143);
|
||||
}
|
||||
|
||||
public int mapReduce() {
|
||||
RayObject<List<String>> machines = Ray.call(WordCountTest::getMachineList);
|
||||
RayObject<Integer> total = null;
|
||||
for (String machine : machines.get()) {
|
||||
RayObject<Integer> wordcount = Ray.call(WordCountTest::countWord, machine, "ray");
|
||||
if (total == null) {
|
||||
total = wordcount;
|
||||
} else {
|
||||
total = Ray.call(WordCountTest::sum, total, wordcount);
|
||||
}
|
||||
}
|
||||
return total.get();
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static List<String> getMachineList() {
|
||||
return Arrays.asList("A", "B", "C");
|
||||
@@ -71,4 +51,24 @@ public class WordCountTest {
|
||||
public static Integer sum(Integer a, Integer/*TODO modify int to Integer in ASM hook*/ b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void test() {
|
||||
int sum = mapReduce();
|
||||
Assert.assertEquals(sum, 143);
|
||||
}
|
||||
|
||||
public int mapReduce() {
|
||||
RayObject<List<String>> machines = Ray.call(WordCountTest::getMachineList);
|
||||
RayObject<Integer> total = null;
|
||||
for (String machine : machines.get()) {
|
||||
RayObject<Integer> wordcount = Ray.call(WordCountTest::countWord, machine, "ray");
|
||||
if (total == null) {
|
||||
total = wordcount;
|
||||
} else {
|
||||
total = Ray.call(WordCountTest::sum, total, wordcount);
|
||||
}
|
||||
}
|
||||
return total.get();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user