mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 07:23:55 +08:00
[Java] Remove java api sub package from test module (#8853)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package io.ray.runtime;
|
||||
|
||||
import io.ray.api.id.UniqueId;
|
||||
import io.ray.runtime.util.IdUtil;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class UniqueIdTest {
|
||||
|
||||
@Test
|
||||
public void testConstructUniqueId() {
|
||||
// Test `fromHexString()`
|
||||
UniqueId id1 = UniqueId.fromHexString("00000000123456789ABCDEF123456789ABCDEF00");
|
||||
Assert.assertEquals("00000000123456789abcdef123456789abcdef00", id1.toString());
|
||||
Assert.assertFalse(id1.isNil());
|
||||
|
||||
try {
|
||||
UniqueId id2 = UniqueId.fromHexString("000000123456789ABCDEF123456789ABCDEF00");
|
||||
// This shouldn't be happened.
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
try {
|
||||
UniqueId id3 = UniqueId.fromHexString("GGGGGGGGGGGGG");
|
||||
// This shouldn't be happened.
|
||||
Assert.assertTrue(false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
// Test `fromByteBuffer()`
|
||||
byte[] bytes = DatatypeConverter.parseHexBinary("0123456789ABCDEF0123456789ABCDEF01234567");
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes, 0, 20);
|
||||
UniqueId id4 = UniqueId.fromByteBuffer(byteBuffer);
|
||||
Assert.assertTrue(Arrays.equals(bytes, id4.getBytes()));
|
||||
Assert.assertEquals("0123456789abcdef0123456789abcdef01234567", id4.toString());
|
||||
|
||||
|
||||
// Test `genNil()`
|
||||
UniqueId id6 = UniqueId.NIL;
|
||||
Assert.assertEquals("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".toLowerCase(), id6.toString());
|
||||
Assert.assertTrue(id6.isNil());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMurmurHash() {
|
||||
UniqueId id = UniqueId.fromHexString("3131313131313131313132323232323232323232");
|
||||
long remainder = Long.remainderUnsigned(IdUtil.murmurHashCode(id), 1000000000);
|
||||
Assert.assertEquals(remainder, 787616861);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.ray.runtime.config;
|
||||
|
||||
import io.ray.runtime.generated.Common.WorkerType;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class RayConfigTest {
|
||||
|
||||
public static final int NUM_RETRIES = 5;
|
||||
|
||||
@Test
|
||||
public void testCreateRayConfig() {
|
||||
try {
|
||||
System.setProperty("ray.job.resource-path", "path/to/ray/job/resource/path");
|
||||
RayConfig rayConfig = RayConfig.create();
|
||||
Assert.assertEquals(WorkerType.DRIVER, rayConfig.workerMode);
|
||||
Assert.assertEquals("path/to/ray/job/resource/path", rayConfig.jobResourcePath);
|
||||
} finally {
|
||||
// Unset system properties.
|
||||
System.clearProperty("ray.job.resource-path");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateHeadPortRandomly() {
|
||||
boolean isSame = true;
|
||||
final int port1 = RayConfig.create().headRedisPort;
|
||||
// If we the 2 ports are the same, let's retry.
|
||||
// This is used to avoid any flaky chance.
|
||||
for (int i = 0; i < NUM_RETRIES; ++i) {
|
||||
final int port2 = RayConfig.create().headRedisPort;
|
||||
if (port1 != port2) {
|
||||
isSame = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.assertFalse(isSame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecifyHeadPort() {
|
||||
System.setProperty("ray.redis.head-port", "11111");
|
||||
Assert.assertEquals(RayConfig.create().headRedisPort, 11111);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.ray.runtime.serializer;
|
||||
|
||||
import io.ray.runtime.serializer.Serializer;
|
||||
import java.util.ArrayList;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.testng.Assert;
|
||||
|
||||
Reference in New Issue
Block a user