Search in sources :

Example 1 with DelayedMonoPublisher

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);
    }
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) Assert.assertTrue(org.junit.Assert.assertTrue) BlockingQueue(java.util.concurrent.BlockingQueue) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Test(org.junit.Test) DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) TimeUnit(java.util.concurrent.TimeUnit) TestSubscriber(org.apache.camel.component.reactive.streams.support.TestSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) Flowable(io.reactivex.Flowable) After(org.junit.After) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Example 2 with DelayedMonoPublisher

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());
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 3 with DelayedMonoPublisher

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());
    }
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) Test(org.junit.Test)

Example 4 with DelayedMonoPublisher

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());
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with DelayedMonoPublisher

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));
}
Also used : DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) Assert.assertTrue(org.junit.Assert.assertTrue) BlockingQueue(java.util.concurrent.BlockingQueue) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Test(org.junit.Test) DelayedMonoPublisher(org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) TimeUnit(java.util.concurrent.TimeUnit) TestSubscriber(org.apache.camel.component.reactive.streams.support.TestSubscriber) CountDownLatch(java.util.concurrent.CountDownLatch) Flowable(io.reactivex.Flowable) After(org.junit.After) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)7 DelayedMonoPublisher (org.apache.camel.component.reactive.streams.engine.DelayedMonoPublisher)7 Test (org.junit.Test)7 LinkedList (java.util.LinkedList)5 ConcurrentLinkedDeque (java.util.concurrent.ConcurrentLinkedDeque)4 Flowable (io.reactivex.Flowable)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 ExecutorService (java.util.concurrent.ExecutorService)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 TimeUnit (java.util.concurrent.TimeUnit)2 TestSubscriber (org.apache.camel.component.reactive.streams.support.TestSubscriber)2 After (org.junit.After)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2