use of io.servicetalk.concurrent.api.LegacyTestSingle in project servicetalk by apple.
the class BeforeFinallyHttpOperatorTest method payloadComplete.
@ParameterizedTest(name = "{displayName} [{index}] discardEventsAfterCancel={0}")
@ValueSource(booleans = { false, true })
void payloadComplete(boolean discardEventsAfterCancel) {
TestPublisher<Buffer> payload = new TestPublisher<>();
LegacyTestSingle<StreamingHttpResponse> responseSingle = new LegacyTestSingle<>(true);
final ResponseSubscriber subscriber = new ResponseSubscriber();
toSource(responseSingle.liftSync(new BeforeFinallyHttpOperator(beforeFinally, discardEventsAfterCancel))).subscribe(subscriber);
assertThat("onSubscribe not called.", subscriber.cancellable, is(notNullValue()));
final StreamingHttpResponse response = reqRespFactory.ok().payloadBody(payload);
responseSingle.onSuccess(response);
verifyNoInteractions(beforeFinally);
responseSingle.verifyNotCancelled();
subscriber.verifyResponseReceived();
assert subscriber.response != null;
subscriber.response.payloadBody().forEach(chunk -> {
// ignore
});
payload.onComplete();
verify(beforeFinally).onComplete();
}
use of io.servicetalk.concurrent.api.LegacyTestSingle in project servicetalk by apple.
the class AbstractWhenCancelTest method testCallbackThrowsError.
@Test
void testCallbackThrowsError() {
LegacyTestSingle<String> single = new LegacyTestSingle<>();
Exception e = assertThrows(DeliberateException.class, () -> {
try {
toSource(doCancel(single, () -> {
throw DELIBERATE_EXCEPTION;
})).subscribe(listener);
listener.awaitSubscription().cancel();
} finally {
single.verifyCancelled();
}
});
assertThat(e, is(sameInstance(DELIBERATE_EXCEPTION)));
}
use of io.servicetalk.concurrent.api.LegacyTestSingle in project servicetalk by apple.
the class AbstractWhenFinallyTest method testCallbackThrowsErrorOnCancel.
@Test
void testCallbackThrowsErrorOnCancel() {
SingleTerminalSignalConsumer<String> mock = throwableMock(DELIBERATE_EXCEPTION);
LegacyTestSingle<String> single = new LegacyTestSingle<>();
try {
toSource(doFinally(single, mock)).subscribe(listener);
Exception e = assertThrows(DeliberateException.class, () -> listener.awaitSubscription().cancel());
assertThat(e, is(sameInstance(DELIBERATE_EXCEPTION)));
} finally {
single.verifyCancelled();
verify(mock).cancel();
verifyNoMoreInteractions(mock);
}
}
Aggregations