use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.
the class ConcurrentSubscriptionTest method singleThreadMultipleRequest.
@Test
void singleThreadMultipleRequest() throws InterruptedException {
Subscription concurrent = ConcurrentSubscription.wrap(subscription);
final int demand = 100;
for (int i = 0; i < demand; ++i) {
concurrent.request(1);
}
subscription.awaitRequestN(demand);
assertFalse(subscription.isCancelled());
}
use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.
the class ConcurrentSubscriptionTest method singleThreadSingleRequest.
@Test
void singleThreadSingleRequest() throws InterruptedException {
Subscription concurrent = ConcurrentSubscription.wrap(subscription);
final long demand = Long.MAX_VALUE;
concurrent.request(demand);
subscription.awaitRequestN(demand);
assertFalse(subscription.isCancelled());
}
use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.
the class ConcurrentSubscriptionTest method singleThreadReentrant.
@Test
void singleThreadReentrant() {
final ReentrantSubscription reentrantSubscription = new ReentrantSubscription(50);
final Subscription concurrent = ConcurrentSubscription.wrap(reentrantSubscription);
reentrantSubscription.outerSubscription(concurrent);
concurrent.request(1);
assertEquals(reentrantSubscription.reentrantLimit, reentrantSubscription.innerSubscription.requested());
}
use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.
the class ConcurrentSubscriptionTest method singleThreadCancelDeliveredIfRequestThrows.
@Test
void singleThreadCancelDeliveredIfRequestThrows() throws InterruptedException {
CountDownLatch cancelledLatch = new CountDownLatch(1);
Subscription concurrent = ConcurrentSubscription.wrap(new Subscription() {
@Override
public void request(final long n) {
throw DELIBERATE_EXCEPTION;
}
@Override
public void cancel() {
cancelledLatch.countDown();
}
});
try {
concurrent.request(1);
fail();
} catch (DeliberateException e) {
assertSame(DELIBERATE_EXCEPTION, e);
}
concurrent.cancel();
cancelledLatch.await();
}
use of io.servicetalk.concurrent.PublisherSource.Subscription in project servicetalk by apple.
the class TimeoutPublisherTest method justSubscribeTimeout.
@ParameterizedTest(name = "{displayName} [{index}] {arguments}")
@EnumSource(TimerBehaviorParam.class)
void justSubscribeTimeout(TimerBehaviorParam params) {
DelayedOnSubscribePublisher<Integer> delayedPublisher = new DelayedOnSubscribePublisher<>();
init(delayedPublisher, params, Duration.ofNanos(1), false);
testExecutor.advanceTimeBy(1, NANOSECONDS);
assertThat(testExecutor.scheduledTasksPending(), is(0));
assertThat(testExecutor.scheduledTasksExecuted(), is(1));
Subscription mockSubscription = mock(Subscription.class);
Subscriber<? super Integer> subscriber = delayedPublisher.subscriber;
assertNotNull(subscriber);
subscriber.onSubscribe(mockSubscription);
verify(mockSubscription).cancel();
assertThat(this.subscriber.awaitOnError(), instanceOf(TimeoutException.class));
}
Aggregations