Test that we return correct result for Futures that are returned from UnorderedThreadPoolExecutor (#11074)
Motivation:
Add test to validate we are not affected by the regression introduced by fd8c1874b4
Modifications:
- Add unit test
Result:
Verify code works as expected
This commit is contained in:
parent
2e9557c51c
commit
29a4dd6ea7
@ -18,6 +18,7 @@ package io.netty.util.concurrent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -63,4 +64,40 @@ public class UnorderedThreadPoolEventExecutorTest {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReturnsCorrectValueOnSuccess() throws Exception {
|
||||
UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
|
||||
try {
|
||||
final String expected = "expected";
|
||||
Future<String> f = executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
return expected;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(expected, f.get());
|
||||
} finally {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetReturnsCorrectValueOnFailure() throws Exception {
|
||||
UnorderedThreadPoolEventExecutor executor = new UnorderedThreadPoolEventExecutor(1);
|
||||
try {
|
||||
final RuntimeException cause = new RuntimeException();
|
||||
Future<String> f = executor.submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
throw cause;
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertSame(cause, f.await().cause());
|
||||
} finally {
|
||||
executor.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user