use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method nextCallbackBubbleError.
@Test
public void nextCallbackBubbleError() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
Throwable err = new Exception("test");
try {
Flux.just(1).doOnEach(s -> {
if (s.isOnNext()) {
state.increment();
throw Exceptions.bubble(err);
}
}).subscribe(ts);
fail();
} catch (Exception e) {
Assert.assertTrue(Exceptions.unwrap(e) == err);
Assert.assertEquals(1, state.intValue());
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class EmitterProcessorTest method test.
@Test
@Ignore
public void test() {
Scheduler asyncGroup = Schedulers.single();
FluxProcessor<String, String> emitter = EmitterProcessor.create();
CountDownLatch requestReceived = new CountDownLatch(1);
AtomicLong demand = new AtomicLong(0);
Publisher<String> publisher = s -> s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
System.out.println("request: " + n + " " + s);
demand.addAndGet(n);
requestReceived.countDown();
}
@Override
public void cancel() {
System.out.println("cancel");
}
});
Flux.from(publisher).subscribeOn(asyncGroup).subscribe(emitter);
AssertSubscriber<String> subscriber = AssertSubscriber.create();
emitter.subscribe(subscriber);
int i = 0;
for (; ; ) {
if (getAndSub(demand, 1) != 0) {
emitter.onNext("" + (i++));
} else {
System.out.println("NO REQUESTED: " + emitter);
LockSupport.parkNanos(100_000_000);
}
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class EmitterProcessorTest method testPerformance.
@Test
@Ignore
public void testPerformance() {
FluxProcessor<String, String> emitter = EmitterProcessor.create();
CountDownLatch requestReceived = new CountDownLatch(1);
AtomicLong maxDelay = new AtomicLong(0);
AtomicLong demand = new AtomicLong(0);
Publisher<String> publisher = new Publisher<String>() {
long lastTimeRequestReceivedNs = -1;
@Override
public void subscribe(Subscriber<? super String> s) {
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
requestReceived.countDown();
long now = System.nanoTime();
if (lastTimeRequestReceivedNs > 0) {
maxDelay.set(now - lastTimeRequestReceivedNs);
}
lastTimeRequestReceivedNs = now;
demand.addAndGet(n);
}
@Override
public void cancel() {
System.out.println("cancel");
}
});
}
};
publisher.subscribe(emitter);
AssertSubscriber<String> subscriber = AssertSubscriber.create();
emitter.subscribe(subscriber);
String buffer = "Hello";
int i = 0;
for (; ; ) {
if (getAndSub(demand, 1) > 0) {
emitter.onNext(buffer);
}
if (i++ % 1000000 == 0) {
System.out.println("maxDelay: " + TimeUnit.MICROSECONDS.toMillis(maxDelay.get()) + " µs");
}
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxPeekFuseableTest method resumeFuseable.
@Test
public void resumeFuseable() {
RuntimeException nextError = new IllegalStateException("next");
List<Throwable> resumedErrors = new ArrayList<>();
List<Object> resumedValues = new ArrayList<>();
Context context = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.resume((t, s) -> {
resumedErrors.add(t);
resumedValues.add(s);
}));
AssertSubscriber<Integer> actual = new AssertSubscriber<>(context, 0);
SignalPeekThrowNext<Integer> peekParent = new SignalPeekThrowNext<>(nextError);
AssertQueueSubscription<Integer> qs = new AssertQueueSubscription<>();
PeekFuseableSubscriber<Integer> test = new PeekFuseableSubscriber<>(actual, peekParent);
test.onSubscribe(qs);
test.onNext(1);
actual.assertNoValues();
assertThat(qs.requested).as("onNext requested more").isEqualTo(1);
qs.offer(3);
Integer polled = test.poll();
assertThat(polled).as("poll skips").isNull();
test.onComplete();
actual.assertNoValues();
actual.assertNoError();
actual.assertComplete();
assertThat(resumedErrors).containsExactly(nextError, nextError);
assertThat(resumedValues).containsExactly(1, 3);
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxPeekFuseableTest method asyncFusionAvailable.
@Test
public void asyncFusionAvailable() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
UnicastProcessor.create(Queues.<Integer>get(2).get()).doOnNext(v -> {
}).subscribe(ts);
Subscription s = ts.upstream();
Assert.assertTrue("Non-fuseable upstream" + s, s instanceof Fuseable.QueueSubscription);
}
Aggregations