Search in sources :

Example 6 with LegacyTestSingle

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();
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) TestPublisher(io.servicetalk.concurrent.api.TestPublisher) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse) LegacyTestSingle(io.servicetalk.concurrent.api.LegacyTestSingle) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with LegacyTestSingle

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)));
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) LegacyTestSingle(io.servicetalk.concurrent.api.LegacyTestSingle) Test(org.junit.jupiter.api.Test)

Example 8 with LegacyTestSingle

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);
    }
}
Also used : DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) LegacyTestSingle(io.servicetalk.concurrent.api.LegacyTestSingle) Test(org.junit.jupiter.api.Test)

Aggregations

LegacyTestSingle (io.servicetalk.concurrent.api.LegacyTestSingle)8 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Buffer (io.servicetalk.buffer.api.Buffer)5 TestSubscription (io.servicetalk.concurrent.api.TestSubscription)4 Test (org.junit.jupiter.api.Test)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 PublisherSource (io.servicetalk.concurrent.PublisherSource)2 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)2 DeliberateException (io.servicetalk.concurrent.internal.DeliberateException)2 TerminalNotification (io.servicetalk.concurrent.internal.TerminalNotification)2 TestPublisherSubscriber (io.servicetalk.concurrent.test.internal.TestPublisherSubscriber)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Nullable (javax.annotation.Nullable)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 TestPublisher (io.servicetalk.concurrent.api.TestPublisher)1 CancellationException (java.util.concurrent.CancellationException)1