use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxRepeatWhenTest method repeatAlwaysScalar.
@Test
public void repeatAlwaysScalar() {
AssertSubscriber<Integer> ts = AssertSubscriber.create(0);
AtomicInteger count = new AtomicInteger();
Flux.just(1).map(d -> count.incrementAndGet()).repeatWhen(v -> v).subscribe(ts);
ts.request(8);
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8).assertNoError().assertNotComplete();
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxMergeSequentialTest method testPrefetchIsBounded.
@Test
public void testPrefetchIsBounded() {
final AtomicInteger count = new AtomicInteger();
AssertSubscriber<Object> ts = AssertSubscriber.create(0);
Flux.just(1).hide().flatMapSequential(t -> Flux.range(1, Queues.SMALL_BUFFER_SIZE * 2).doOnNext(t1 -> count.getAndIncrement()).hide()).subscribe(ts);
ts.assertNoError();
ts.assertNoValues();
ts.assertNotComplete();
Assert.assertEquals(Queues.XS_BUFFER_SIZE, count.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxExpandTest method depthCancelRace2.
@Test
public void depthCancelRace2() throws Exception {
for (int i = 0; i < 1000; i++) {
final TestPublisher<Integer> pp = TestPublisher.create();
Flux<Integer> source = Flux.just(0).expandDeep(it -> pp);
final CountDownLatch cdl = new CountDownLatch(1);
AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {
final AtomicInteger sync = new AtomicInteger(2);
@Override
public void onNext(Integer t) {
super.onNext(t);
Schedulers.single().schedule(() -> {
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
cancel();
cdl.countDown();
});
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
}
};
source.subscribe(ts);
assertThat(cdl.await(5, TimeUnit.SECONDS)).as("runs under 5s").isTrue();
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method resourceThrowsEager.
@Test
public void resourceThrowsEager() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Flux.using(() -> {
throw new RuntimeException("forced failure");
}, r -> Flux.range(1, 10), cleanup::set, false).subscribe(ts);
ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
Assert.assertEquals(0, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method checkCleanupExecutionTime.
void checkCleanupExecutionTime(boolean eager, boolean fail) {
AtomicInteger cleanup = new AtomicInteger();
AtomicBoolean before = new AtomicBoolean();
AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {
@Override
public void onError(Throwable t) {
super.onError(t);
before.set(cleanup.get() != 0);
}
@Override
public void onComplete() {
super.onComplete();
before.set(cleanup.get() != 0);
}
};
Flux.using(() -> 1, r -> {
if (fail) {
return Flux.error(new RuntimeException("forced failure"));
}
return Flux.range(r, 10);
}, cleanup::set, eager).subscribe(ts);
if (fail) {
ts.assertNoValues().assertError(RuntimeException.class).assertNotComplete().assertErrorMessage("forced failure");
} else {
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).assertComplete().assertNoError();
}
Assert.assertEquals(1, cleanup.get());
Assert.assertEquals(eager, before.get());
}
Aggregations