use of io.servicetalk.concurrent.SingleSource.Subscriber in project servicetalk by apple.
the class BeforeFinallyHttpOperatorTest method duplicateOnSuccess.
@ParameterizedTest(name = "{displayName} [{index}] discardEventsAfterCancel={0}")
@ValueSource(booleans = { false, true })
void duplicateOnSuccess(boolean discardEventsAfterCancel) {
AtomicReference<SingleSource.Subscriber<? super StreamingHttpResponse>> subRef = new AtomicReference<>();
Single<StreamingHttpResponse> original = new Single<StreamingHttpResponse>() {
@Override
protected void handleSubscribe(final Subscriber<? super StreamingHttpResponse> subscriber) {
subRef.set(subscriber);
subscriber.onSubscribe(IGNORE_CANCEL);
}
};
final ResponseSubscriber subscriber = new ResponseSubscriber();
toSource(original.liftSync(new BeforeFinallyHttpOperator(beforeFinally, discardEventsAfterCancel))).subscribe(subscriber);
assertThat("Original Single not subscribed.", subRef.get(), is(notNullValue()));
assertThat("onSubscribe not called.", subscriber.cancellable, is(notNullValue()));
final StreamingHttpResponse response = reqRespFactory.newResponse(OK);
subRef.get().onSuccess(response);
final StreamingHttpResponse received = subscriber.verifyResponseReceived();
verifyNoInteractions(beforeFinally);
final StreamingHttpResponse response2 = reqRespFactory.newResponse(OK);
try {
subRef.get().onSuccess(response2);
} catch (AssertionError e) {
// silence assert on dupe success when not canceled
}
final StreamingHttpResponse received2 = subscriber.verifyResponseReceived();
// Old response should be preserved.
assertThat("Duplicate response received.", received2, is(received));
verifyNoInteractions(beforeFinally);
}
Aggregations