use of com.lmax.disruptor.support.DummyEventProcessor 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);
}
use of com.lmax.disruptor.support.DummyEventProcessor in project disruptor by LMAX-Exchange.
the class SequenceBarrierTest method shouldWaitForWorkCompleteWhereCompleteWorkThresholdIsBehind.
@Test
public void shouldWaitForWorkCompleteWhereCompleteWorkThresholdIsBehind() throws Exception {
long expectedNumberMessages = 10;
fillRingBuffer(expectedNumberMessages);
final DummyEventProcessor[] eventProcessors = new DummyEventProcessor[3];
for (int i = 0, size = eventProcessors.length; i < size; i++) {
eventProcessors[i] = new DummyEventProcessor();
eventProcessors[i].setSequence(expectedNumberMessages - 2);
}
final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier(Util.getSequencesFor(eventProcessors));
Runnable runnable = new Runnable() {
public void run() {
for (DummyEventProcessor stubWorker : eventProcessors) {
stubWorker.setSequence(stubWorker.getSequence().get() + 1L);
}
}
};
Thread thread = new Thread(runnable);
thread.start();
thread.join();
long expectedWorkSequence = expectedNumberMessages - 1;
long completedWorkSequence = sequenceBarrier.waitFor(expectedWorkSequence);
assertTrue(completedWorkSequence >= expectedWorkSequence);
}
use of com.lmax.disruptor.support.DummyEventProcessor 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();
}
Aggregations