mirror of
https://github.com/wassname/ray.git
synced 2026-07-03 01:43:14 +08:00
[Java] Implement GcsClient (#4601)
This commit is contained in:
@@ -20,7 +20,6 @@ public class BaseTest {
|
||||
public void setUpBase(Method method) {
|
||||
LOGGER.info("===== Running test: "
|
||||
+ method.getDeclaringClass().getName() + "." + method.getName());
|
||||
System.setProperty("ray.resources", "CPU:4,RES-A:4");
|
||||
Ray.init();
|
||||
// These files need to be deleted after each test case.
|
||||
filesToDelete = ImmutableList.of(
|
||||
@@ -38,9 +37,6 @@ public class BaseTest {
|
||||
for (File file : filesToDelete) {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
// Unset system properties.
|
||||
System.clearProperty("ray.resources");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.ray.api.test;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.List;
|
||||
import org.ray.api.Ray;
|
||||
import org.ray.api.TestUtils;
|
||||
import org.ray.api.gcs.GcsClient;
|
||||
import org.ray.api.gcs.NodeInfo;
|
||||
import org.ray.runtime.AbstractRayRuntime;
|
||||
import org.ray.runtime.config.RayConfig;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class GcsClientTest extends BaseTest {
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() {
|
||||
System.setProperty("ray.resources", "A:8");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
System.clearProperty("ray.resources");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllNodeInfo() {
|
||||
TestUtils.skipTestUnderSingleProcess();
|
||||
RayConfig config = ((AbstractRayRuntime)Ray.internal()).getRayConfig();
|
||||
|
||||
Preconditions.checkNotNull(config);
|
||||
GcsClient gcsClient = Ray.getGcsClient();
|
||||
List<NodeInfo> allNodeInfo = gcsClient.getAllNodeInfo();
|
||||
Assert.assertEquals(allNodeInfo.size(), 1);
|
||||
Assert.assertEquals(allNodeInfo.get(0).nodeAddress, config.nodeIp);
|
||||
Assert.assertTrue(allNodeInfo.get(0).isAlive);
|
||||
Assert.assertEquals(allNodeInfo.get(0).resources.get("A"), 8.0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import org.ray.api.RayObject;
|
||||
import org.ray.api.TestUtils;
|
||||
import org.ray.api.annotation.RayRemote;
|
||||
import org.ray.runtime.AbstractRayRuntime;
|
||||
import org.ray.runtime.RayNativeRuntime;
|
||||
import org.ray.runtime.gcs.GcsClientImpl;
|
||||
import org.ray.runtime.util.UniqueIdUtil;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -37,7 +37,7 @@ public class PlasmaFreeTest extends BaseTest {
|
||||
Assert.assertEquals("hello", helloId.get());
|
||||
Ray.internal().free(ImmutableList.of(helloId.getId()), true, true);
|
||||
|
||||
final boolean result = TestUtils.waitForCondition(() -> !((RayNativeRuntime) Ray.internal())
|
||||
final boolean result = TestUtils.waitForCondition(() -> !((GcsClientImpl) Ray.getGcsClient())
|
||||
.rayletTaskExistsInGcs(UniqueIdUtil.computeTaskId(helloId.getId())), 50);
|
||||
Assert.assertTrue(result);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.ray.api.annotation.RayRemote;
|
||||
import org.ray.api.options.ActorCreationOptions;
|
||||
import org.ray.api.options.CallOptions;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
@@ -18,6 +20,16 @@ import org.testng.annotations.Test;
|
||||
*/
|
||||
public class ResourcesManagementTest extends BaseTest {
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() {
|
||||
System.setProperty("ray.resources", "CPU:4,RES-A:4");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
System.clearProperty("ray.resources");
|
||||
}
|
||||
|
||||
@RayRemote
|
||||
public static Integer echo(Integer number) {
|
||||
return number;
|
||||
|
||||
@@ -95,4 +95,11 @@ public class UniqueIdTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMurmurHash() {
|
||||
UniqueId id = UniqueId.fromHexString("3131313131313131313132323232323232323232");
|
||||
long remainder = Long.remainderUnsigned(UniqueIdUtil.murmurHashCode(id), 1000000000);
|
||||
Assert.assertEquals(remainder, 787616861);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user