add callBrokenPromise test

This commit is contained in:
Vaci Koblizek 2020-11-09 21:28:43 +00:00
parent f05c994c06
commit c30dba3e9f
2 changed files with 64 additions and 2 deletions

View file

@ -30,6 +30,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
public class RpcTest {
@ -472,5 +474,36 @@ public class RpcTest {
Assert.assertEquals(4, call4.join().getN());
Assert.assertEquals(5, call5.join().getN());
}
@org.junit.Test
public void testCallBrokenPromise() throws ExecutionException, InterruptedException {
var context = new TestContext(bootstrapFactory);
var client = new Test.TestMoreStuff.Client(context.connect(Test.TestSturdyRefObjectId.Tag.TEST_MORE_STUFF));
var paf = new CompletableFuture<Test.TestInterface.Client>();
{
var req = client.holdRequest();
req.getParams().setCap(new Test.TestInterface.Client(paf));
req.send().join();
}
AtomicBoolean returned = new AtomicBoolean(false);
var req = client.callHeldRequest().send().exceptionallyCompose(exc -> {
returned.set(true);
return CompletableFuture.failedFuture(exc);
}).thenAccept(results -> {
returned.set(true);
});
Assert.assertFalse(returned.get());
paf.completeExceptionally(new Exception("foo"));
Assert.assertTrue(returned.get());
// Verify that we are still connected
getCallSequence(client, 1).get();
}
}

View file

@ -102,8 +102,9 @@ class RpcTestUtil {
static class TestMoreStuffImpl extends Test.TestMoreStuff.Server {
final Counter callCount;
final Counter handleCount;
private final Counter callCount;
private final Counter handleCount;
private Test.TestInterface.Client clientToHold;
public TestMoreStuffImpl(Counter callCount, Counter handleCount) {
this.callCount = callCount;
@ -164,6 +165,34 @@ class RpcTestUtil {
});
});
}
@Override
protected CompletableFuture<java.lang.Void> hold(CallContext<Test.TestMoreStuff.HoldParams.Reader, Test.TestMoreStuff.HoldResults.Builder> context) {
this.callCount.inc();
var params = context.getParams();
this.clientToHold = params.getCap();
return READY_NOW;
}
@Override
protected CompletableFuture<java.lang.Void> callHeld(CallContext<Test.TestMoreStuff.CallHeldParams.Reader, Test.TestMoreStuff.CallHeldResults.Builder> context) {
this.callCount.inc();
var request = this.clientToHold.fooRequest();
request.getParams().setI(123);
request.getParams().setJ(true);
return request.send().thenAccept(response -> {
Assert.assertEquals("foo", response.getX().toString());
context.getResults().setS("bar");
});
}
@Override
protected CompletableFuture<java.lang.Void> getHeld(CallContext<Test.TestMoreStuff.GetHeldParams.Reader, Test.TestMoreStuff.GetHeldResults.Builder> context) {
this.callCount.inc();
var result = context.getResults();
result.setCap(this.clientToHold);
return READY_NOW;
}
}
static class TestTailCalleeImpl extends Test.TestTailCallee.Server {