Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Use BaseTest to instead of TestListener. #3577

Merged
merged 2 commits into from
Dec 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -38,15 +38,33 @@ public class RunManager {

private List<Process> processes;

private static final int KILL_PROCESS_WAIT_TIMEOUT_SECONDS = 1;

public RunManager(RayConfig rayConfig) {
this.rayConfig = rayConfig;
processes = new ArrayList<>();
random = new Random();
}

public void cleanup() {
for (Process p : processes) {
// Terminate the processes in the reversed order of creating them.
// Because raylet needs to exit before object store, otherwise it
// cannot exit gracefully.

for (int i = processes.size() - 1; i >= 0; --i) {
Process p = processes.get(i);
p.destroy();

try {
p.waitFor(KILL_PROCESS_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOGGER.warn("Got InterruptedException while waiting for process {}" +
" to be terminated.", processes.get(i));
}

if (p.isAlive()) {
p.destroyForcibly();
}
}
}

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.ray.api.benchmark;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.test.MyRunner;

@RunWith(MyRunner.class)
public class ActorPressTest extends RayBenchmarkTest {

@Test
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.ray.api.benchmark;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.test.MyRunner;

@RunWith(MyRunner.class)
public class MaxPressureTest extends RayBenchmarkTest {

public static final int clientNum = 2;
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.ray.api.benchmark;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.test.MyRunner;

@RunWith(MyRunner.class)
public class RateLimiterPressureTest extends RayBenchmarkTest {

public static final int clientNum = 2;
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.test.BaseTest;
import org.ray.runtime.util.logger.RayLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class RayBenchmarkTest<T> implements Serializable {
public abstract class RayBenchmarkTest<T> extends BaseTest implements Serializable {

private static final Logger LOGGER = LoggerFactory.getLogger(RayBenchmarkTest.class);
//not thread safe ,but we only have one thread here
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.ray.api.benchmark;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.test.MyRunner;

@RunWith(MyRunner.class)
public class SingleLatencyTest extends RayBenchmarkTest {

public static final int totalNum = 10;
Original file line number Diff line number Diff line change
@@ -7,14 +7,12 @@
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.annotation.RayRemote;
import org.ray.api.options.ActorCreationOptions;

@RunWith(MyRunner.class)
public class ActorReconstructionTest {
public class ActorReconstructionTest extends BaseTest {

@RayRemote()
public static class Counter {
4 changes: 1 addition & 3 deletions java/test/src/main/java/org/ray/api/test/ActorTest.java
Original file line number Diff line number Diff line change
@@ -2,16 +2,14 @@

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;
import org.ray.api.function.RayFunc2;
import org.ray.api.id.UniqueId;

@RunWith(MyRunner.class)
public class ActorTest {
public class ActorTest extends BaseTest {

@RayRemote
public static class Counter {
32 changes: 32 additions & 0 deletions java/test/src/main/java/org/ray/api/test/BaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.ray.api.test;

import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.ray.api.Ray;

public class BaseTest {

@Before
public void setUp() {
System.setProperty("ray.home", "../..");
System.setProperty("ray.resources", "CPU:4,RES-A:4");
Ray.init();
}

@After
public void tearDown() {
// TODO(qwang): This is double check to check that the socket file is removed actually.
// We could not enable this until `systemInfo` enabled.
//File rayletSocketFIle = new File(Ray.systemInfo().rayletSocketName());
Ray.shutdown();

//remove raylet socket file
//rayletSocketFIle.delete();

// unset system properties
System.clearProperty("ray.home");
System.clearProperty("ray.resources");
}

}
4 changes: 1 addition & 3 deletions java/test/src/main/java/org/ray/api/test/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -2,16 +2,14 @@

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.annotation.RayRemote;

/**
* Hello world.
*/
@RunWith(MyRunner.class)
public class HelloWorldTest {
public class HelloWorldTest extends BaseTest {

@RayRemote
private static String hello() {
19 changes: 0 additions & 19 deletions java/test/src/main/java/org/ray/api/test/MyRunner.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -13,8 +13,7 @@
/**
* Test putting and getting objects.
*/
@RunWith(MyRunner.class)
public class ObjectStoreTest {
public class ObjectStoreTest extends BaseTest {

@Test
public void testPutAndGet() {
3 changes: 1 addition & 2 deletions java/test/src/main/java/org/ray/api/test/PlasmaFreeTest.java
Original file line number Diff line number Diff line change
@@ -13,8 +13,7 @@
import org.ray.api.id.UniqueId;


@RunWith(MyRunner.class)
public class PlasmaFreeTest {
public class PlasmaFreeTest extends BaseTest {

@RayRemote
private static String hello() {
3 changes: 1 addition & 2 deletions java/test/src/main/java/org/ray/api/test/RayCallTest.java
Original file line number Diff line number Diff line change
@@ -15,8 +15,7 @@
/**
* Test Ray.call API
*/
@RunWith(MyRunner.class)
public class RayCallTest {
public class RayCallTest extends BaseTest {

@RayRemote
private static int testInt(int val) {
38 changes: 22 additions & 16 deletions java/test/src/main/java/org/ray/api/test/RayConfigTest.java
Original file line number Diff line number Diff line change
@@ -10,22 +10,28 @@ public class RayConfigTest {

@Test
public void testCreateRayConfig() {
System.setProperty("ray.home", "/path/to/ray");
System.setProperty("ray.driver.resource-path", "path/to/ray/driver/resource/path");
RayConfig rayConfig = RayConfig.create();

Assert.assertEquals("/path/to/ray", rayConfig.rayHome);
Assert.assertEquals(WorkerMode.DRIVER, rayConfig.workerMode);
Assert.assertEquals(RunMode.CLUSTER, rayConfig.runMode);

System.setProperty("ray.home", "");
rayConfig = RayConfig.create();

Assert.assertEquals(System.getProperty("user.dir"), rayConfig.rayHome);
Assert.assertEquals(System.getProperty("user.dir") +
"/build/src/ray/thirdparty/redis/src/redis-server", rayConfig.redisServerExecutablePath);

Assert.assertEquals("path/to/ray/driver/resource/path", rayConfig.driverResourcePath);
try {
System.setProperty("ray.home", "/path/to/ray");
System.setProperty("ray.driver.resource-path", "path/to/ray/driver/resource/path");
RayConfig rayConfig = RayConfig.create();

Assert.assertEquals("/path/to/ray", rayConfig.rayHome);
Assert.assertEquals(WorkerMode.DRIVER, rayConfig.workerMode);
Assert.assertEquals(RunMode.CLUSTER, rayConfig.runMode);

System.setProperty("ray.home", "");
rayConfig = RayConfig.create();

Assert.assertEquals(System.getProperty("user.dir"), rayConfig.rayHome);
Assert.assertEquals(System.getProperty("user.dir") +
"/build/src/ray/thirdparty/redis/src/redis-server", rayConfig.redisServerExecutablePath);

Assert.assertEquals("path/to/ray/driver/resource/path", rayConfig.driverResourcePath);
} finally {
//unset the system property
System.clearProperty("ray.home");
System.clearProperty("ray.driver.resource-path");
}

}
}
4 changes: 1 addition & 3 deletions java/test/src/main/java/org/ray/api/test/RayMethodsTest.java
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@
import java.util.stream.Collectors;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.WaitResult;
@@ -14,8 +13,7 @@
/**
* Integration test for Ray.*
*/
@RunWith(MyRunner.class)
public class RayMethodsTest {
public class RayMethodsTest extends BaseTest {

@Test
public void test() {
Original file line number Diff line number Diff line change
@@ -2,10 +2,8 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import jdk.nashorn.internal.ir.annotations.Immutable;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
@@ -17,8 +15,7 @@
/**
* Resources Management Test.
*/
@RunWith(MyRunner.class)
public class ResourcesManagementTest {
public class ResourcesManagementTest extends BaseTest {

@RayRemote
public static Integer echo(Integer number) {
4 changes: 1 addition & 3 deletions java/test/src/main/java/org/ray/api/test/StressTest.java
Original file line number Diff line number Diff line change
@@ -5,14 +5,12 @@
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayActor;
import org.ray.api.RayObject;
import org.ray.api.id.UniqueId;

@RunWith(MyRunner.class)
public class StressTest {
public class StressTest extends BaseTest {

public static int echo(int x) {
return x;
21 changes: 0 additions & 21 deletions java/test/src/main/java/org/ray/api/test/TestListener.java

This file was deleted.

4 changes: 1 addition & 3 deletions java/test/src/main/java/org/ray/api/test/WaitTest.java
Original file line number Diff line number Diff line change
@@ -4,14 +4,12 @@
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.WaitResult;
import org.ray.api.annotation.RayRemote;

@RunWith(MyRunner.class)
public class WaitTest {
public class WaitTest extends BaseTest {

@RayRemote
private static String hi() {