use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class CompletableConcatWithPublisherTest method setUp.
@BeforeEach
void setUp() {
subscriber = new TestPublisherSubscriber<>();
cancellable = new TestCancellable();
source = new TestCompletable.Builder().disableAutoOnSubscribe().build();
next = new TestPublisher.Builder<Integer>().disableAutoOnSubscribe().build();
subscription = new TestSubscription();
toSource(source.concat(next)).subscribe(subscriber);
source.onSubscribe(cancellable);
subscriber.awaitSubscription();
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class RetryTest method testCancel.
@Test
void testCancel() {
final TestSubscription subscription = new TestSubscription();
source.onSubscribe(subscription);
subscriber.awaitSubscription().request(2);
source.onNext(1, 2);
assertThat(subscriber.takeOnNext(2), contains(1, 2));
subscriber.awaitSubscription().cancel();
source.onError(DELIBERATE_EXCEPTION);
assertTrue(subscription.isCancelled());
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByLeader.
@Test
void testPartitionByLeader() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_LEADER, true);
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, false, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, true, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/foo"));
final HttpResponse httpResponse2 = clt.request(clt.get("/bar"));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_2));
}
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class PartitionedHttpClientTest method testPartitionByHeader.
@Test
void testPartitionByHeader() throws Exception {
final Function<HttpRequestMetaData, PartitionAttributesBuilder> selector = req -> new DefaultPartitionAttributesBuilder(1).add(SRV_NAME, requireNonNull(req.headers().get(X_SERVER)).toString());
try (BlockingHttpClient clt = HttpClients.forPartitionedAddress(psd, "test-cluster", selector).initializer((pa, builder) -> builder.unresolvedAddressToHost(addr -> pa.get(SRV_NAME))).buildBlocking()) {
sdPublisher.onSubscribe(new TestSubscription());
sdPublisher.onNext(new TestPSDE(SRV_1, (InetSocketAddress) srv1.listenAddress()), new TestPSDE(SRV_2, (InetSocketAddress) srv2.listenAddress()));
final HttpResponse httpResponse1 = clt.request(clt.get("/").addHeader(X_SERVER, SRV_2));
final HttpResponse httpResponse2 = clt.request(clt.get("/").addHeader(X_SERVER, SRV_1));
MatcherAssert.assertThat(httpResponse1.headers().get(X_SERVER), hasToString(SRV_2));
MatcherAssert.assertThat(httpResponse2.headers().get(X_SERVER), hasToString(SRV_1));
}
}
use of io.servicetalk.concurrent.api.TestSubscription in project servicetalk by apple.
the class NettyPipelinedConnectionTest method channelCloseErrorsPendingReadCancelsPendingWrite.
@Test
void channelCloseErrorsPendingReadCancelsPendingWrite() throws Exception {
TestSubscription writePublisher1Subscription = new TestSubscription();
toSource(requester.write(writePublisher1.afterSubscription(() -> writePublisher1Subscription))).subscribe(readSubscriber);
Subscription readSubscription = readSubscriber.awaitSubscription();
readSubscription.request(1);
toSource(requester.write(writePublisher2)).subscribe(readSubscriber2);
assertTrue(writePublisher1.isSubscribed());
assertFalse(writePublisher2.isSubscribed());
channel.close();
assertThat(readSubscriber.awaitOnError(), is(instanceOf(ClosedChannelException.class)));
assertThat(readSubscriber2.awaitOnError(), is(instanceOf(ClosedChannelException.class)));
writePublisher1Subscription.awaitCancelled();
assertFalse(writePublisher2.isSubscribed());
}
Aggregations