use of com.lmax.disruptor.support.StubEvent in project disruptor by LMAX-Exchange.
the class BatchEventProcessorTest method shouldCallMethodsInLifecycleOrderForBatch.
@Test
public void shouldCallMethodsInLifecycleOrderForBatch() throws Exception {
CountDownLatch eventLatch = new CountDownLatch(3);
LatchEventHandler eventHandler = new LatchEventHandler(eventLatch);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessor<StubEvent>(ringBuffer, sequenceBarrier, eventHandler);
ringBuffer.addGatingSequences(batchEventProcessor.getSequence());
ringBuffer.publish(ringBuffer.next());
ringBuffer.publish(ringBuffer.next());
ringBuffer.publish(ringBuffer.next());
Thread thread = new Thread(batchEventProcessor);
thread.start();
assertTrue(eventLatch.await(2, TimeUnit.SECONDS));
batchEventProcessor.halt();
thread.join();
}
use of com.lmax.disruptor.support.StubEvent in project disruptor by LMAX-Exchange.
the class BatchEventProcessorTest method shouldCallExceptionHandlerOnUncaughtException.
@Test
public void shouldCallExceptionHandlerOnUncaughtException() throws Exception {
CountDownLatch exceptionLatch = new CountDownLatch(1);
LatchExceptionHandler latchExceptionHandler = new LatchExceptionHandler(exceptionLatch);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessor<StubEvent>(ringBuffer, sequenceBarrier, new ExceptionEventHandler());
ringBuffer.addGatingSequences(batchEventProcessor.getSequence());
batchEventProcessor.setExceptionHandler(latchExceptionHandler);
Thread thread = new Thread(batchEventProcessor);
thread.start();
ringBuffer.publish(ringBuffer.next());
assertTrue(exceptionLatch.await(2, TimeUnit.SECONDS));
batchEventProcessor.halt();
thread.join();
}
use of com.lmax.disruptor.support.StubEvent in project disruptor by LMAX-Exchange.
the class EventTranslatorTest method shouldTranslateOtherDataIntoAnEvent.
@Test
public void shouldTranslateOtherDataIntoAnEvent() {
StubEvent event = StubEvent.EVENT_FACTORY.newInstance();
EventTranslator<StubEvent> eventTranslator = new ExampleEventTranslator(TEST_VALUE);
eventTranslator.translateTo(event, 0);
Assert.assertEquals(TEST_VALUE, event.getTestString());
}
use of com.lmax.disruptor.support.StubEvent in project disruptor by LMAX-Exchange.
the class SequenceBarrierTest method fillRingBuffer.
private void fillRingBuffer(long expectedNumberMessages) throws InterruptedException {
for (long i = 0; i < expectedNumberMessages; i++) {
long sequence = ringBuffer.next();
StubEvent event = ringBuffer.get(sequence);
event.setValue((int) i);
ringBuffer.publish(sequence);
}
}
use of com.lmax.disruptor.support.StubEvent in project disruptor by LMAX-Exchange.
the class SequenceBarrierTest method shouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer.
@Test
public void shouldWaitForWorkCompleteWhereAllWorkersAreBlockedOnRingBuffer() throws Exception {
long expectedNumberMessages = 10;
fillRingBuffer(expectedNumberMessages);
final DummyEventProcessor[] workers = new DummyEventProcessor[3];
for (int i = 0, size = workers.length; i < size; i++) {
workers[i] = new DummyEventProcessor();
workers[i].setSequence(expectedNumberMessages - 1);
}
final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(Util.getSequencesFor(workers));
Runnable runnable = new Runnable() {
public void run() {
long sequence = ringBuffer.next();
StubEvent event = ringBuffer.get(sequence);
event.setValue((int) sequence);
ringBuffer.publish(sequence);
for (DummyEventProcessor stubWorker : workers) {
stubWorker.setSequence(sequence);
}
}
};
new Thread(runnable).start();
long expectedWorkSequence = expectedNumberMessages;
long completedWorkSequence = sequenceBarrier.waitFor(expectedNumberMessages);
assertTrue(completedWorkSequence >= expectedWorkSequence);
}
Aggregations