Skip to content

Commit

Permalink
Revert mistaken test reformatting
Browse files Browse the repository at this point in the history
An overly keen find & replace made more changes than necessary while changing from direct BatchEventProcessor construction to using the builder.
  • Loading branch information
Palmr committed Mar 18, 2023
1 parent ea61e82 commit 63d5af7
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 98 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/lmax/disruptor/dsl/Disruptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ EventHandlerGroup<T> createEventProcessors(
{
final EventHandler<? super T> eventHandler = eventHandlers[i];

final BatchEventProcessor<T> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, barrier, eventHandler);
final BatchEventProcessor<T> batchEventProcessor =
new BatchEventProcessorBuilder().build(ringBuffer, barrier, eventHandler);

if (exceptionHandler != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public EventAccessor<T> get(final long sequence)
public BatchEventProcessor<EventAccessor<T>> createHandler(final EventHandler<T> handler)
{
BatchEventProcessor<EventAccessor<T>> processor =
new BatchEventProcessorBuilder()
.build(this, sequencer.newBarrier(), new AccessorEventHandler<>(handler));
new BatchEventProcessorBuilder().build(
this,
sequencer.newBarrier(),
new AccessorEventHandler<>(handler));
sequencer.addGatingSequences(processor.getSequence());

return processor;
Expand Down
29 changes: 13 additions & 16 deletions src/test/java/com/lmax/disruptor/BatchEventProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public void shouldThrowExceptionOnSettingNullExceptionHandler()
{
assertThrows(NullPointerException.class, () ->
{
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, new ExceptionEventHandler());
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder().build(
ringBuffer, sequenceBarrier, new ExceptionEventHandler());
batchEventProcessor.setExceptionHandler(null);
});
}
Expand All @@ -56,8 +56,8 @@ public void shouldCallMethodsInLifecycleOrderForBatch()
{
CountDownLatch eventLatch = new CountDownLatch(3);
LatchEventHandler eventHandler = new LatchEventHandler(eventLatch);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, eventHandler);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder().build(
ringBuffer, sequenceBarrier, eventHandler);

ringBuffer.addGatingSequences(batchEventProcessor.getSequence());

Expand All @@ -80,8 +80,8 @@ public void shouldCallExceptionHandlerOnUncaughtException()
{
CountDownLatch exceptionLatch = new CountDownLatch(1);
LatchExceptionHandler latchExceptionHandler = new LatchExceptionHandler(exceptionLatch);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, new ExceptionEventHandler());
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder().build(
ringBuffer, sequenceBarrier, new ExceptionEventHandler());
ringBuffer.addGatingSequences(batchEventProcessor.getSequence());

batchEventProcessor.setExceptionHandler(latchExceptionHandler);
Expand Down Expand Up @@ -180,8 +180,8 @@ public void onEvent(final StubEvent event, final long sequence, final boolean en
}

final BatchEventProcessor<StubEvent> batchEventProcessor =
new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, new LoopbackEventHandler());
new BatchEventProcessorBuilder().build(
ringBuffer, sequenceBarrier, new LoopbackEventHandler());

ringBuffer.publish(ringBuffer.next());
ringBuffer.publish(ringBuffer.next());
Expand All @@ -207,8 +207,7 @@ public void shouldAlwaysHalt() throws InterruptedException
DataProvider<Object> dp = sequence -> null;

final LatchLifeCycleHandler h1 = new LatchLifeCycleHandler();
final BatchEventProcessor p1 = new BatchEventProcessorBuilder()
.build(dp, barrier, h1);
final BatchEventProcessor p1 = new BatchEventProcessorBuilder().build(dp, barrier, h1);

Thread t1 = new Thread(p1);
p1.halt();
Expand All @@ -220,8 +219,7 @@ public void shouldAlwaysHalt() throws InterruptedException
for (int i = 0; i < 1000; i++)
{
final LatchLifeCycleHandler h2 = new LatchLifeCycleHandler();
final BatchEventProcessor p2 = new BatchEventProcessorBuilder()
.build(dp, barrier, h2);
final BatchEventProcessor p2 = new BatchEventProcessorBuilder().build(dp, barrier, h2);
Thread t2 = new Thread(p2);
t2.start();
p2.halt();
Expand All @@ -233,8 +231,7 @@ public void shouldAlwaysHalt() throws InterruptedException
for (int i = 0; i < 1000; i++)
{
final LatchLifeCycleHandler h2 = new LatchLifeCycleHandler();
final BatchEventProcessor p2 = new BatchEventProcessorBuilder()
.build(dp, barrier, h2);
final BatchEventProcessor p2 = new BatchEventProcessorBuilder().build(dp, barrier, h2);
Thread t2 = new Thread(p2);
t2.start();
Thread.yield();
Expand Down Expand Up @@ -285,8 +282,8 @@ public void shouldNotPassZeroSizeToBatchStartAware() throws Exception
{
BatchAwareEventHandler eventHandler = new BatchAwareEventHandler();

final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, new DelegatingSequenceBarrier(this.sequenceBarrier), eventHandler);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder().build(
ringBuffer, new DelegatingSequenceBarrier(this.sequenceBarrier), eventHandler);

ringBuffer.addGatingSequences(batchEventProcessor.getSequence());

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/lmax/disruptor/LifecycleAwareTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public final class LifecycleAwareTest
private final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
private final LifecycleAwareEventHandler handler = new LifecycleAwareEventHandler();
private final BatchEventProcessor<StubEvent> batchEventProcessor =
new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, handler);
new BatchEventProcessorBuilder().build(ringBuffer, sequenceBarrier, handler);

@Test
public void shouldNotifyOfBatchProcessorLifecycle() throws Exception
Expand Down
38 changes: 23 additions & 15 deletions src/test/java/com/lmax/disruptor/RewindBatchEventProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void shouldRewindOnFirstEventOfBatchSizeOfOne()
fill(ringBuffer, 1);

final TestEventHandler eventHandler = new TestEventHandler(values, asList(rewind(0, 1)), 0, -1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -60,7 +60,7 @@ public void shouldRewindOnFirstEventOfBatch()
singletonList(rewind(0, 1)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -81,7 +81,7 @@ public void shouldRewindOnEventInMiddleOfBatch()
singletonList(rewind(8, 1)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -105,7 +105,7 @@ public void shouldRewindOnLastEventOfBatch()
-1
);

final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -126,7 +126,7 @@ public void shouldRunBatchCompleteOnLastEventOfBatch()
singletonList(rewind(4, 1)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -142,7 +142,7 @@ public void shouldRunBatchCompleteOnLastEventOfBatchOfOne()
fill(ringBuffer, 1);

final TestEventHandler eventHandler = new TestEventHandler(values, singletonList(rewind(0, 1)), 0, -1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -162,7 +162,7 @@ public void shouldRewindMultipleTimes()
singletonList(rewind(8, 3)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -185,7 +185,7 @@ public void shouldRewindMultipleTimesOnLastEventInBatch()
singletonList(rewind(lastSequenceNumber, 3)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -208,7 +208,7 @@ public void shouldRewindMultipleTimesInSameBatch()
asList(rewind(5, 3), rewind(7, 3)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -229,7 +229,7 @@ public void shouldRewindMultipleTimesOnBatchOfOne()
fill(ringBuffer, 1);

final TestEventHandler eventHandler = new TestEventHandler(values, singletonList(rewind(0, 3)), 0, -1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -247,7 +247,7 @@ public void shouldFallOverWhenNonRewindableExceptionIsThrown()
fill(ringBuffer, ringBufferEntries);

final TestEventHandler eventHandler = new TestEventHandler(values, emptyList(), lastSequenceNumber, 8);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

AtomicReference<Throwable> exceptionHandled = new AtomicReference<>();
Expand All @@ -264,7 +264,7 @@ public void shouldProcessUpToMaxBatchSizeForEachGivenBatch()
fill(ringBuffer, ringBufferEntries);

final TestEventHandler eventHandler = new TestEventHandler(values, emptyList(), lastSequenceNumber, -1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand All @@ -286,7 +286,7 @@ public void shouldOnlyRewindBatch()
singletonList(rewind(15, 3)),
lastSequenceNumber,
-1);
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler, new SimpleBatchRewindStrategy());
final BatchEventProcessor<LongEvent> eventProcessor = create(eventHandler);
eventHandler.setRewindable(eventProcessor);

eventProcessor.run();
Expand Down Expand Up @@ -427,10 +427,18 @@ private EventRangeExpectation event(final long sequenceStart, final long sequenc
return new EventRangeExpectation(sequenceStart, sequenceEnd, false);
}

private BatchEventProcessor<LongEvent> create(final TestEventHandler eventHandler)
{
return create(eventHandler, new SimpleBatchRewindStrategy());
}

private BatchEventProcessor<LongEvent> create(final TestEventHandler eventHandler, final BatchRewindStrategy batchRewindStrategy)
{
return new BatchEventProcessorBuilder()
.build(ringBuffer, ringBuffer.newBarrier(), eventHandler, batchRewindStrategy);
return new BatchEventProcessorBuilder().build(
ringBuffer,
ringBuffer.newBarrier(),
eventHandler,
batchRewindStrategy);
}

private final class TestEventHandler implements RewindableEventHandler<LongEvent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public void shouldReportProgressByUpdatingSequenceViaCallback()
final RingBuffer<StubEvent> ringBuffer = createMultiProducer(StubEvent.EVENT_FACTORY, 16);
final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
final EventHandler<StubEvent> handler = new TestSequenceReportingEventHandler();
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder()
.build(ringBuffer, sequenceBarrier, handler);
final BatchEventProcessor<StubEvent> batchEventProcessor = new BatchEventProcessorBuilder().build(
ringBuffer, sequenceBarrier, handler);
ringBuffer.addGatingSequences(batchEventProcessor.getSequence());

Thread thread = new Thread(batchEventProcessor);
Expand Down
Loading

0 comments on commit 63d5af7

Please sign in to comment.