use of io.servicetalk.concurrent.test.internal.TestPublisherSubscriber in project servicetalk by apple.
the class ScanWithPublisherTest method terminalThrowsHandled.
private static void terminalThrowsHandled(boolean onComplete, boolean withLifetime) {
final AtomicInteger finalizations = new AtomicInteger(0);
PublisherSource.Processor<Integer, Integer> processor = newPublisherProcessor();
TestPublisherSubscriber<Integer> subscriber = new TestPublisherSubscriber<>();
toSource(scanWithOperator(fromSource(processor), withLifetime, new ScanWithLifetimeMapper<Integer, Integer>() {
@Nullable
@Override
public Integer mapOnNext(@Nullable final Integer next) {
return next;
}
@Nullable
@Override
public Integer mapOnError(final Throwable cause) throws Throwable {
throw cause;
}
@Nullable
@Override
public Integer mapOnComplete() {
throw DELIBERATE_EXCEPTION;
}
@Override
public boolean mapTerminal() {
return true;
}
@Override
public void afterFinally() {
finalizations.incrementAndGet();
}
})).subscribe(subscriber);
subscriber.awaitSubscription().request(1);
if (onComplete) {
processor.onComplete();
} else {
processor.onError(DELIBERATE_EXCEPTION);
}
assertThat(subscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
if (withLifetime) {
assertThat(finalizations.get(), is(1));
}
}
use of io.servicetalk.concurrent.test.internal.TestPublisherSubscriber in project servicetalk by apple.
the class ScanWithPublisherTest method terminalConcatWithDemand.
private static void terminalConcatWithDemand(boolean demandUpFront, boolean onComplete, boolean withLifetime) {
final AtomicInteger finalizations = new AtomicInteger(0);
PublisherSource.Processor<Integer, Integer> processor = newPublisherProcessor();
TestPublisherSubscriber<Integer> subscriber = new TestPublisherSubscriber<>();
toSource(scanWithOperator(fromSource(processor), withLifetime, new ScanWithLifetimeMapper<Integer, Integer>() {
private int sum;
@Override
public Integer mapOnNext(@Nullable final Integer next) {
if (next != null) {
sum += next;
}
return sum;
}
@Override
public Integer mapOnError(final Throwable cause) {
return ++sum;
}
@Override
public Integer mapOnComplete() {
return ++sum;
}
@Override
public boolean mapTerminal() {
return true;
}
@Override
public void afterFinally() {
finalizations.incrementAndGet();
}
})).subscribe(subscriber);
Subscription s = subscriber.awaitSubscription();
s.request(demandUpFront ? 4 : 3);
processor.onNext(1);
assertThat(subscriber.takeOnNext(), is(1));
processor.onNext(2);
assertThat(subscriber.takeOnNext(), is(3));
processor.onNext(3);
assertThat(subscriber.takeOnNext(), is(6));
if (onComplete) {
processor.onComplete();
} else {
processor.onError(DELIBERATE_EXCEPTION);
}
if (!demandUpFront) {
assertThat(subscriber.pollOnNext(10, MILLISECONDS), is(nullValue()));
s.request(1);
}
assertThat(subscriber.takeOnNext(), is(7));
subscriber.awaitOnComplete();
if (withLifetime) {
assertThat(finalizations.get(), is(1));
}
}
use of io.servicetalk.concurrent.test.internal.TestPublisherSubscriber in project servicetalk by apple.
the class ScanWithPublisherTest method scanWithNoTerminalMapper.
private static void scanWithNoTerminalMapper(boolean onComplete) {
PublisherSource.Processor<Integer, Integer> processor = newPublisherProcessor();
TestPublisherSubscriber<Integer> subscriber = new TestPublisherSubscriber<>();
toSource(fromSource(processor).scanWith(() -> 0, Integer::sum)).subscribe(subscriber);
Subscription s = subscriber.awaitSubscription();
s.request(3);
processor.onNext(1);
assertThat(subscriber.takeOnNext(), is(1));
processor.onNext(2);
assertThat(subscriber.takeOnNext(), is(3));
processor.onNext(3);
assertThat(subscriber.takeOnNext(), is(6));
if (onComplete) {
processor.onComplete();
subscriber.awaitOnComplete();
} else {
processor.onError(DELIBERATE_EXCEPTION);
assertThat(subscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
}
}
use of io.servicetalk.concurrent.test.internal.TestPublisherSubscriber in project servicetalk by apple.
the class ScanWithPublisherTest method mapTerminalSignalThrows.
private static void mapTerminalSignalThrows(boolean onComplete, boolean withLifetime) {
final AtomicInteger finalizations = new AtomicInteger(0);
PublisherSource.Processor<Integer, Integer> processor = newPublisherProcessor();
TestPublisherSubscriber<Integer> subscriber = new TestPublisherSubscriber<>();
toSource(scanWithOperator(fromSource(processor), withLifetime, new ScanWithLifetimeMapper<Integer, Integer>() {
@Nullable
@Override
public Integer mapOnNext(@Nullable final Integer next) {
return null;
}
@Nullable
@Override
public Integer mapOnError(final Throwable cause) {
return null;
}
@Nullable
@Override
public Integer mapOnComplete() {
return null;
}
@Override
public boolean mapTerminal() {
throw DELIBERATE_EXCEPTION;
}
@Override
public void afterFinally() {
finalizations.incrementAndGet();
}
})).subscribe(subscriber);
subscriber.awaitSubscription();
if (onComplete) {
processor.onComplete();
} else {
processor.onError(new DeliberateException());
}
assertThat(subscriber.awaitOnError(), is(DELIBERATE_EXCEPTION));
if (withLifetime) {
assertThat(finalizations.get(), is(1));
}
}
use of io.servicetalk.concurrent.test.internal.TestPublisherSubscriber in project servicetalk by apple.
the class CompletableToPublisherTest method publishOnOriginalIsPreservedOnInvalidRequestN.
@Test
@Disabled("The Publisher subscriber is now not offloaded")
void publishOnOriginalIsPreservedOnInvalidRequestN() throws Exception {
ConcurrentLinkedQueue<AssertionError> errors = new ConcurrentLinkedQueue<>();
TestPublisherSubscriber<String> subscriber = new TestPublisherSubscriber<>();
TestCompletable completable = new TestCompletable();
CountDownLatch analyzed = publishOnOriginalIsPreserved0(errors, subscriber, completable);
subscriber.awaitSubscription().request(-1);
analyzed.await();
assertThat("Unexpected errors observed: " + errors, errors, hasSize(0));
Throwable err = subscriber.awaitOnError();
assertThat("Wrong error received.", err, is(instanceOf(IllegalArgumentException.class)));
}
Aggregations