Search in sources :

Example 1 with SleepingEventHandler

use of com.lmax.disruptor.dsl.stubs.SleepingEventHandler in project disruptor by LMAX-Exchange.

the class ConsumerRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    consumerRepository = new ConsumerRepository<TestEvent>();
    eventProcessor1 = new DummyEventProcessor(new Sequence());
    eventProcessor2 = new DummyEventProcessor(new Sequence());
    eventProcessor1.run();
    eventProcessor2.run();
    handler1 = new SleepingEventHandler();
    handler2 = new SleepingEventHandler();
    barrier1 = new DummySequenceBarrier();
    barrier2 = new DummySequenceBarrier();
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) DummyEventProcessor(com.lmax.disruptor.support.DummyEventProcessor) DummySequenceBarrier(com.lmax.disruptor.support.DummySequenceBarrier) TestEvent(com.lmax.disruptor.support.TestEvent) Sequence(com.lmax.disruptor.Sequence) Before(org.junit.Before)

Example 2 with SleepingEventHandler

use of com.lmax.disruptor.dsl.stubs.SleepingEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldThrowExceptionWhenAddingEventProcessorsAfterTheProducerBarrierHasBeenCreated.

@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionWhenAddingEventProcessorsAfterTheProducerBarrierHasBeenCreated() throws Exception {
    executor.ignoreExecutions();
    disruptor.handleEventsWith(new SleepingEventHandler());
    disruptor.start();
    disruptor.handleEventsWith(new SleepingEventHandler());
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) Test(org.junit.Test)

Example 3 with SleepingEventHandler

use of com.lmax.disruptor.dsl.stubs.SleepingEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldAddEventProcessorsAfterPublishing.

@Test
public void shouldAddEventProcessorsAfterPublishing() throws Exception {
    RingBuffer<TestEvent> rb = disruptor.getRingBuffer();
    BatchEventProcessor<TestEvent> b1 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(), new SleepingEventHandler());
    BatchEventProcessor<TestEvent> b2 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(b1.getSequence()), new SleepingEventHandler());
    BatchEventProcessor<TestEvent> b3 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(b2.getSequence()), new SleepingEventHandler());
    assertThat(b1.getSequence().get(), is(-1L));
    assertThat(b2.getSequence().get(), is(-1L));
    assertThat(b3.getSequence().get(), is(-1L));
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    rb.publish(rb.next());
    disruptor.handleEventsWith(b1, b2, b3);
    assertThat(b1.getSequence().get(), is(5L));
    assertThat(b2.getSequence().get(), is(5L));
    assertThat(b3.getSequence().get(), is(5L));
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) TestEvent(com.lmax.disruptor.support.TestEvent) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) Test(org.junit.Test)

Example 4 with SleepingEventHandler

use of com.lmax.disruptor.dsl.stubs.SleepingEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method should.

@Test
public void should() throws Exception {
    RingBuffer<TestEvent> rb = disruptor.getRingBuffer();
    BatchEventProcessor<TestEvent> b1 = new BatchEventProcessor<TestEvent>(rb, rb.newBarrier(), new SleepingEventHandler());
    EventProcessorFactory<TestEvent> b2 = new EventProcessorFactory<TestEvent>() {

        @Override
        public EventProcessor createEventProcessor(RingBuffer<TestEvent> ringBuffer, Sequence[] barrierSequences) {
            return new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(barrierSequences), new SleepingEventHandler());
        }
    };
    disruptor.handleEventsWith(b1).then(b2);
    disruptor.start();
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) TestEvent(com.lmax.disruptor.support.TestEvent) BatchEventProcessor(com.lmax.disruptor.BatchEventProcessor) RingBuffer(com.lmax.disruptor.RingBuffer) Test(org.junit.Test)

Example 5 with SleepingEventHandler

use of com.lmax.disruptor.dsl.stubs.SleepingEventHandler in project disruptor by LMAX-Exchange.

the class DisruptorTest method shouldThrowExceptionIfStartIsCalledTwice.

@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionIfStartIsCalledTwice() throws Exception {
    executor.ignoreExecutions();
    disruptor.handleEventsWith(new SleepingEventHandler());
    disruptor.start();
    disruptor.start();
}
Also used : SleepingEventHandler(com.lmax.disruptor.dsl.stubs.SleepingEventHandler) Test(org.junit.Test)

Aggregations

SleepingEventHandler (com.lmax.disruptor.dsl.stubs.SleepingEventHandler)5 Test (org.junit.Test)4 TestEvent (com.lmax.disruptor.support.TestEvent)3 BatchEventProcessor (com.lmax.disruptor.BatchEventProcessor)2 RingBuffer (com.lmax.disruptor.RingBuffer)1 Sequence (com.lmax.disruptor.Sequence)1 DummyEventProcessor (com.lmax.disruptor.support.DummyEventProcessor)1 DummySequenceBarrier (com.lmax.disruptor.support.DummySequenceBarrier)1 Before (org.junit.Before)1