Remove RAY_CHECK from JNI code (#3978)

* Remove RAY_CHECK in JNI

* Try to add mvn test to test the exception.

* Refine

* Address comments
This commit is contained in:
Yuhong Guo
2019-02-09 18:10:22 +08:00
committed by GitHub
parent 728031a972
commit 3a66d47a3a
4 changed files with 83 additions and 29 deletions
@@ -106,11 +106,8 @@ public class RayletClientImpl implements RayletClient {
LOGGER.debug("Blocked on objects for task {}, object IDs are {}",
UniqueIdUtil.computeTaskId(objectIds.get(0)), objectIds);
}
int ret = nativeFetchOrReconstruct(client, UniqueIdUtil.getIdBytes(objectIds),
nativeFetchOrReconstruct(client, UniqueIdUtil.getIdBytes(objectIds),
fetchOnly, currentTaskId.getBytes());
if (ret != 0) {
throw new RayException("Connection closed by Raylet");
}
}
@Override
@@ -302,27 +299,28 @@ public class RayletClientImpl implements RayletClient {
boolean isWorker, byte[] driverTaskId);
private static native void nativeSubmitTask(long client, byte[] cursorId, ByteBuffer taskBuff,
int pos, int taskSize);
int pos, int taskSize) throws RayException;
// return TaskInfo (in FlatBuffer)
private static native byte[] nativeGetTask(long client);
private static native byte[] nativeGetTask(long client) throws RayException;
private static native void nativeDestroy(long client);
private static native void nativeDestroy(long client) throws RayException;
private static native int nativeFetchOrReconstruct(long client, byte[][] objectIds,
boolean fetchOnly, byte[] currentTaskId);
private static native void nativeFetchOrReconstruct(long client, byte[][] objectIds,
boolean fetchOnly, byte[] currentTaskId) throws RayException;
private static native void nativeNotifyUnblocked(long client, byte[] currentTaskId);
private static native void nativeNotifyUnblocked(long client, byte[] currentTaskId)
throws RayException;
private static native void nativePutObject(long client, byte[] taskId, byte[] objectId);
private static native boolean[] nativeWaitObject(long conn, byte[][] objectIds,
int numReturns, int timeout, boolean waitLocal, byte[] currentTaskId);
int numReturns, int timeout, boolean waitLocal, byte[] currentTaskId) throws RayException;
private static native byte[] nativeGenerateTaskId(byte[] driverId, byte[] parentTaskId,
int taskIndex);
private static native void nativeFreePlasmaObjects(long conn, byte[][] objectIds,
boolean localOnly);
boolean localOnly) throws RayException;
}
@@ -0,0 +1,46 @@
package org.ray.api.test;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.TimeUnit;
import org.ray.api.Ray;
import org.ray.api.RayObject;
import org.ray.api.exception.RayException;
import org.ray.api.id.UniqueId;
import org.ray.runtime.RayObjectImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ClientExceptionTest extends BaseTest {
private static final Logger LOGGER = LoggerFactory.getLogger(ClientExceptionTest.class);
@Test
public void testWaitAndCrash() {
UniqueId randomId = UniqueId.randomId();
RayObject<String> notExisting = new RayObjectImpl(randomId);
Thread thread = new Thread(() -> {
try {
TimeUnit.SECONDS.sleep(1);
Ray.shutdown();
} catch (InterruptedException e) {
LOGGER.error("Got InterruptedException when sleeping, exit right now.");
throw new RuntimeException("Got InterruptedException when sleeping.", e);
}
});
thread.start();
try {
Ray.wait(ImmutableList.of(notExisting), 1, 2000);
Assert.fail("Should not reach here");
} catch (RayException e) {
LOGGER.debug(String.format("Expected runtime exception: {}", e));
}
try {
thread.join();
} catch (Exception e) {
LOGGER.error(String.format("Excpetion caught: {}", e));
}
}
}