[Java] Generate head redis port randomly (#6879)

* Random head port

* address comments.
This commit is contained in:
Qing Wang
2020-01-23 23:37:41 +08:00
committed by GitHub
parent aa2a0cb6da
commit cfbde39ba8
3 changed files with 33 additions and 2 deletions
@@ -7,6 +7,8 @@ import org.testng.annotations.Test;
public class RayConfigTest {
public final static int NUM_RETRIES = 5;
@Test
public void testCreateRayConfig() {
try {
@@ -18,6 +20,27 @@ public class RayConfigTest {
// 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);
}
}