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 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));
}
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 AutoOnSubscribeCompletableSubscriberFunction method apply.
@Override
public Subscriber apply(final Subscriber subscriber) {
final DelayedCancellable subscription = new DelayedCancellable();
subscriber.onSubscribe(subscription);
return new DelegatingCompletableSubscriber(subscriber) {
@Override
public void onSubscribe(final Cancellable s) {
subscription.delayedCancellable(s);
}
};
}
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();
}
Aggregations