Skip to content

Commit

Permalink
Fix Java CI failure (ray-project#4995)
Browse files Browse the repository at this point in the history
  • Loading branch information
jovany-wang authored and raulchen committed Jun 19, 2019
1 parent 2bf92e0 commit 7bda5ed
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion java/api/src/main/java/org/ray/api/id/BaseId.java
Expand Up @@ -48,7 +48,7 @@ public boolean isNil() {
break;
}
}
isNilCache = localIsNil;
isNilCache = localIsNil;
}
return isNilCache;
}
Expand Down
15 changes: 15 additions & 0 deletions java/test/src/main/java/org/ray/api/TestUtils.java
@@ -1,8 +1,10 @@
package org.ray.api;

import java.util.function.Supplier;
import org.ray.api.annotation.RayRemote;
import org.ray.runtime.AbstractRayRuntime;
import org.ray.runtime.config.RunMode;
import org.testng.Assert;
import org.testng.SkipException;

public class TestUtils {
Expand Down Expand Up @@ -42,4 +44,17 @@ public static boolean waitForCondition(Supplier<Boolean> condition, int timeoutM
}
return false;
}

@RayRemote
private static String hi() {
return "hi";
}

/**
* Warm up the cluster.
*/
public static void warmUpCluster() {
RayObject<String> obj = Ray.call(TestUtils::hi);
Assert.assertEquals(obj.get(), "hi");
}
}
17 changes: 13 additions & 4 deletions java/test/src/main/java/org/ray/api/test/DynamicResourceTest.java
Expand Up @@ -23,23 +23,32 @@ public static String sayHi() {
@Test
public void testSetResource() {
TestUtils.skipTestUnderSingleProcess();

// 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();
RayObject<String> obj = Ray.call(DynamicResourceTest::sayHi, op1);
WaitResult<String> result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(result.getReady().size(), 0);

Ray.setResource("A", 10.0);
boolean resourceReady = TestUtils.waitForCondition(() -> {
List<NodeInfo> nodes = Ray.getRuntimeContext().getAllNodeInfo();
if (nodes.size() != 1) {
return false;
}
return (0 == Double.compare(10.0, nodes.get(0).resources.get("A")));
}, 2000);

// Assert node info.
List<NodeInfo> nodes = Ray.getRuntimeContext().getAllNodeInfo();
Assert.assertEquals(nodes.size(), 1);
Assert.assertEquals(nodes.get(0).resources.get("A"), 10.0);
Assert.assertTrue(resourceReady);

// Assert ray call result.
result = Ray.wait(ImmutableList.of(obj), 1, 1000);
Assert.assertEquals(result.getReady().size(), 1);
Assert.assertEquals(Ray.get(obj.getId()), "hi");

}

}
5 changes: 5 additions & 0 deletions java/test/src/main/java/org/ray/api/test/WaitTest.java
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.TestUtils;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;
import org.testng.Assert;
Expand All @@ -28,6 +29,9 @@ private static String delayedHi() {
}

private static void testWait() {
// Call a task in advance to warm up the cluster to avoid being too slow to start workers.
TestUtils.warmUpCluster();

RayObject<String> obj1 = Ray.call(WaitTest::hi);
RayObject<String> obj2 = Ray.call(WaitTest::delayedHi);

Expand Down Expand Up @@ -71,4 +75,5 @@ public void testWaitForEmpty() {
Assert.assertTrue(true);
}
}

}

0 comments on commit 7bda5ed

Please sign in to comment.