use of org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher in project camel by apache.
the class DelayedMonoPublisherTest method testMultipleSubscribersMixedArrivalException.
@Test
public void testMultipleSubscribersMixedArrivalException() throws Exception {
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
Exception ex = new RuntimeException("An exception");
ConcurrentLinkedDeque<Throwable> exceptions = new ConcurrentLinkedDeque<>();
CountDownLatch latch = new CountDownLatch(2);
Flowable.fromPublisher(pub).doOnError(exceptions::add).doOnError(e -> latch.countDown()).subscribe();
Thread.sleep(200);
pub.setException(ex);
Flowable.fromPublisher(pub).doOnError(exceptions::add).doOnError(e -> latch.countDown()).subscribe();
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(2, exceptions.size());
for (Throwable t : exceptions) {
assertEquals(ex, t);
}
}
use of org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher in project camel by apache.
the class DelayedMonoPublisherTest method testAvailableSoon.
@Test
public void testAvailableSoon() throws Exception {
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
LinkedList<Integer> data = new LinkedList<>();
CountDownLatch latch = new CountDownLatch(1);
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
Thread.yield();
pub.setData(5);
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(1, data.size());
assertEquals(5, data.get(0).intValue());
}
use of org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher in project camel by apache.
the class DelayedMonoPublisherTest method testMultipleSubscribers.
@Test
public void testMultipleSubscribers() throws Exception {
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
ConcurrentLinkedDeque<Integer> data = new ConcurrentLinkedDeque<>();
CountDownLatch latch = new CountDownLatch(2);
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
Thread.sleep(200);
pub.setData(5);
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(2, data.size());
for (Integer n : data) {
assertEquals(5, n.intValue());
}
}
use of org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher in project camel by apache.
the class DelayedMonoPublisherTest method testAlreadyAvailable.
@Test
public void testAlreadyAvailable() throws Exception {
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
pub.setData(5);
LinkedList<Integer> data = new LinkedList<>();
CountDownLatch latch = new CountDownLatch(1);
Flowable.fromPublisher(pub).doOnNext(data::add).doOnComplete(latch::countDown).subscribe();
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(1, data.size());
assertEquals(5, data.get(0).intValue());
}
use of org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher in project camel by apache.
the class DelayedMonoPublisherTest method testExceptionAlreadyAvailable.
@Test
public void testExceptionAlreadyAvailable() throws Exception {
Exception ex = new RuntimeException("An exception");
DelayedMonoPublisher<Integer> pub = new DelayedMonoPublisher<>(service);
pub.setException(ex);
LinkedList<Throwable> exceptions = new LinkedList<>();
CountDownLatch latch = new CountDownLatch(1);
Flowable.fromPublisher(pub).doOnError(exceptions::add).doOnError(e -> latch.countDown()).subscribe();
assertTrue(latch.await(1, TimeUnit.SECONDS));
assertEquals(1, exceptions.size());
assertEquals(ex, exceptions.get(0));
}
Aggregations