use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class SequentialCancellableTest method testWithIgnoreCancel.
@Test
void testWithIgnoreCancel() {
SequentialCancellable sc = new SequentialCancellable();
sc.nextCancellable(Cancellable.IGNORE_CANCEL);
Cancellable next = mock(Cancellable.class);
sc.nextCancellable(next);
verifyNoInteractions(next);
sc.cancel();
verify(next).cancel();
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class WriteStreamSubscriberOutOfEventloopTest method testTerminalOrder.
@Test
void testTerminalOrder() throws Exception {
Processor subject = newCompletableProcessor();
CompletableSource.Subscriber subscriber = new CompletableSource.Subscriber() {
@Override
public void onSubscribe(Cancellable cancellable) {
// noop
}
@Override
public void onComplete() {
subject.onComplete();
}
@Override
public void onError(Throwable t) {
if (pendingFlush.contains(1)) {
subject.onError(t);
} else {
subject.onError(new IllegalStateException("The expected object wasn't written before termination!", t));
}
}
};
WriteDemandEstimator demandEstimator = mock(WriteDemandEstimator.class);
this.subscriber = new WriteStreamSubscriber(channel, demandEstimator, subscriber, UNSUPPORTED_PROTOCOL_CLOSE_HANDLER, NoopWriteObserver.INSTANCE, identity(), false, __ -> false);
this.subscriber.onNext(1);
this.subscriber.onError(DELIBERATE_EXCEPTION);
try {
fromSource(subject).toFuture().get();
fail();
} catch (ExecutionException cause) {
assertSame(DELIBERATE_EXCEPTION, cause.getCause());
}
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class DefaultNettyConnectionTest method testUpdateFlushStrategy.
@Test
void testUpdateFlushStrategy() {
toSource(conn.write(from(newBuffer("Hello"), TRAILER.duplicate()))).subscribe(writeListener);
writeListener.awaitOnComplete();
// Flush on each (default)
pollChannelAndVerifyWrites("Hello", TRAILER_MSG);
writeListener = new TestCompletableSubscriber();
Cancellable c = conn.updateFlushStrategy((old, __) -> batchFlush(3, never()));
toSource(conn.write(publisher)).subscribe(writeListener);
publisher.onNext(newBuffer("Hello1"));
// No flush
pollChannelAndVerifyWrites();
publisher.onNext(newBuffer("Hello2"));
publisher.onNext(TRAILER.duplicate());
// Batch flush of 2
pollChannelAndVerifyWrites("Hello1", "Hello2", TRAILER_MSG);
publisher.onComplete();
writeListener.awaitOnComplete();
c.cancel();
writeListener = new TestCompletableSubscriber();
toSource(conn.write(from(newBuffer("Hello3"), TRAILER.duplicate()))).subscribe(writeListener);
writeListener.awaitOnComplete();
// Reverted to flush on each
pollChannelAndVerifyWrites("Hello3", TRAILER_MSG);
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class FlushStrategyHolderTest method updateWhenOriginal.
@Test
void updateWhenOriginal() {
FlushStrategy prev = holder.currentStrategy();
FlushStrategy next = mock(FlushStrategy.class);
Cancellable revert = holder.updateFlushStrategy((current, isCurrentOriginal) -> isCurrentOriginal ? next : current);
assertThat("Unexpected strategy post update.", holder.currentStrategy(), equalTo(next));
revert.cancel();
assertThat("Unexpected strategy post revert.", holder.currentStrategy(), equalTo(prev));
}
use of io.servicetalk.concurrent.Cancellable in project servicetalk by apple.
the class FlushStrategyHolderTest method revertNoOpOnMismatch.
@Test
void revertNoOpOnMismatch() {
FlushStrategy prev = holder.currentStrategy();
FlushStrategy next1 = mock(FlushStrategy.class);
Cancellable revert1 = holder.updateFlushStrategy((current, isCurrentOriginal) -> isCurrentOriginal ? next1 : current);
assertThat("Unexpected strategy post update.", holder.currentStrategy(), equalTo(next1));
FlushStrategy next2 = mock(FlushStrategy.class);
Cancellable revert2 = holder.updateFlushStrategy((current, isCurrentOriginal) -> next2);
revert1.cancel();
// Cancel should be a noop since we have already updated
assertThat("Unexpected strategy post revert.", holder.currentStrategy(), equalTo(next2));
revert2.cancel();
// Cancel should revert to original
assertThat("Unexpected strategy post revert.", holder.currentStrategy(), equalTo(prev));
}
Aggregations