[Java] Add getAsyncContext and setAsyncContext API (#6439)

* Add getAsyncContext and setAsyncContext API

* address comment

* fix bug

* Add test case
This commit is contained in:
Kai Yang
2019-12-19 18:08:58 +08:00
committed by Hao Chen
parent 7e2addb424
commit 3bb680a719
6 changed files with 84 additions and 6 deletions
@@ -168,4 +168,32 @@ public class MultiThreadingTest extends BaseTest {
}
}
private static boolean testGetAsyncContextAndSetAsyncContext() throws Exception {
final Object asyncContext = Ray.getAsyncContext();
final Object[] result = new Object[1];
Thread thread = new Thread(() -> {
try {
Ray.setAsyncContext(asyncContext);
Ray.put(0);
} catch (Exception e) {
result[0] = e;
}
});
thread.start();
thread.join();
if (result[0] instanceof Exception) {
throw (Exception) result[0];
}
return true;
}
public void testGetAsyncContextAndSetAsyncContextInDriver() throws Exception {
Assert.assertTrue(testGetAsyncContextAndSetAsyncContext());
}
public void testGetAsyncContextAndSetAsyncContextInWorker() {
RayObject<Boolean> obj = Ray.call(MultiThreadingTest::testGetAsyncContextAndSetAsyncContext);
Assert.assertTrue(obj.get());
}
}