use of com.lmax.disruptor.support.TestEvent in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldMakeEntriesAvailableToFirstHandlersImmediately.
@Test
public void shouldMakeEntriesAvailableToFirstHandlersImmediately() throws Exception {
CountDownLatch countDownLatch = new CountDownLatch(2);
EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
disruptor.handleEventsWith(createDelayedEventHandler(), eventHandler);
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
use of com.lmax.disruptor.support.TestEvent in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately.
@Test
public void shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(2);
final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
disruptor.handleEventsWith(new EventProcessorFactory<TestEvent>() {
@Override
public EventProcessor createEventProcessor(final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences) {
assertEquals("Should not have had any barrier sequences", 0, barrierSequences.length);
return new BatchEventProcessor<TestEvent>(disruptor.getRingBuffer(), ringBuffer.newBarrier(barrierSequences), eventHandler);
}
});
ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
use of com.lmax.disruptor.support.TestEvent 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));
}
use of com.lmax.disruptor.support.TestEvent in project disruptor by LMAX-Exchange.
the class DisruptorTest method shouldProcessMessagesPublishedBeforeStartIsCalled.
@Test
public void shouldProcessMessagesPublishedBeforeStartIsCalled() throws Exception {
final CountDownLatch eventCounter = new CountDownLatch(0);
disruptor.handleEventsWith(new EventHandler<TestEvent>() {
@Override
public void onEvent(final TestEvent event, final long sequence, final boolean endOfBatch) throws Exception {
eventCounter.countDown();
}
});
disruptor.publishEvent(new EventTranslator<TestEvent>() {
@Override
public void translateTo(final TestEvent event, final long sequence) {
lastPublishedEvent = event;
}
});
disruptor.start();
disruptor.publishEvent(new EventTranslator<TestEvent>() {
@Override
public void translateTo(final TestEvent event, final long sequence) {
lastPublishedEvent = event;
}
});
if (!eventCounter.await(5, TimeUnit.SECONDS)) {
fail("Did not process event published before start was called. Missed events: " + eventCounter.getCount());
}
}
use of com.lmax.disruptor.support.TestEvent 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();
}
Aggregations