mirror of
https://github.com/wassname/ray.git
synced 2026-07-19 11:27:32 +08:00
[Java] Fix the issue when waiting an empty list or a null pointer (#3632)
This commit is contained in:
@@ -50,6 +50,11 @@ public class RayletClientImpl implements RayletClient {
|
||||
@Override
|
||||
public <T> WaitResult<T> wait(List<RayObject<T>> waitFor, int numReturns, int
|
||||
timeoutMs, UniqueId currentTaskId) {
|
||||
Preconditions.checkNotNull(waitFor);
|
||||
if (waitFor.isEmpty()) {
|
||||
return new WaitResult<>(new ArrayList<>(), new ArrayList<>());
|
||||
}
|
||||
|
||||
List<UniqueId> ids = new ArrayList<>();
|
||||
for (RayObject<T> element : waitFor) {
|
||||
ids.add(element.getId());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.ray.api.test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -56,4 +57,18 @@ public class WaitTest extends BaseTest {
|
||||
RayObject<Object> res = Ray.call(WaitTest::waitInWorker);
|
||||
res.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWaitForEmpty() {
|
||||
WaitResult<String> result = Ray.wait(new ArrayList<>());
|
||||
Assert.assertTrue(result.getReady().isEmpty());
|
||||
Assert.assertTrue(result.getUnready().isEmpty());
|
||||
|
||||
try {
|
||||
Ray.wait(null);
|
||||
Assert.fail();
|
||||
} catch (NullPointerException e) {
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user