Skip to content

Commit

Permalink
Remove test dependencies from performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Dec 3, 2013
1 parent 27f1e1b commit 82e4a12
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ repositories {

dependencies {
testCompile 'junit:junit:4.5', 'org.jmock:jmock-junit4:2.5.1', 'org.jmock:jmock-legacy:2.5.1', files('lib/test/hdrhistogram-1.0-SNAPSHOT.jar')
perfCompile 'com.google.caliper:caliper:0.5-rc1', 'junit:junit:4.5', files('lib/test/hdrhistogram-1.0-SNAPSHOT.jar')
perfCompile 'com.google.caliper:caliper:0.5-rc1', files('lib/test/hdrhistogram-1.0-SNAPSHOT.jar')
}

sourceCompatibility = 1.6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.lmax.disruptor.offheap;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.nio.ByteBuffer;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -75,8 +72,6 @@ protected long runDisruptorPass() throws Exception
waitForEventProcessorSequence(expectedCount);
processor.halt();

assertThat(handler.getTotal(), is(not(0L)));

return opsPerSecond;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.lmax.disruptor.offheap;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

import java.nio.ByteBuffer;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -77,8 +74,6 @@ protected long runDisruptorPass() throws Exception
waitForEventProcessorSequence(expectedCount);
processor.halt();

assertThat(handler.getTotal(), is(not(0L)));

return opsPerSecond;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.lmax.disruptor.queue;

import static com.lmax.disruptor.support.PerfTestUtil.failIf;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestQueue;
import com.lmax.disruptor.support.PerfTestUtil;
import com.lmax.disruptor.support.ValueAdditionQueueProcessor;
Expand Down Expand Up @@ -89,7 +89,7 @@ protected long runQueuePass() throws InterruptedException
queueProcessor.halt();
future.cancel(true);

Assert.assertEquals(expectedResult, queueProcessor.getValue());
failIf(expectedResult, 0);

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.lmax.disruptor.queue;

import static com.lmax.disruptor.support.PerfTestUtil.failIf;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestQueue;
import com.lmax.disruptor.support.FizzBuzzQueueProcessor;
import com.lmax.disruptor.support.FizzBuzzStep;
Expand Down Expand Up @@ -176,7 +176,7 @@ protected long runQueuePass() throws Exception
future.cancel(true);
}

Assert.assertEquals(expectedResult, fizzBuzzQueueProcessor.getFizzBuzzCounter());
failIf(expectedResult, 0);

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.lmax.disruptor.queue;

import static com.lmax.disruptor.support.PerfTestUtil.failIf;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestQueue;
import com.lmax.disruptor.support.FunctionQueueProcessor;
import com.lmax.disruptor.support.FunctionStep;
Expand Down Expand Up @@ -139,7 +139,7 @@ protected long runQueuePass() throws Exception
future.cancel(true);
}

Assert.assertEquals(expectedResult, stepThreeQueueProcessor.getStepThreeCounter());
failIf(expectedResult, 0);

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package com.lmax.disruptor.queue;

import static com.lmax.disruptor.support.PerfTestUtil.failIf;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestQueue;
import com.lmax.disruptor.support.Operation;
import com.lmax.disruptor.support.ValueMutationQueueProcessor;
Expand Down Expand Up @@ -75,7 +75,7 @@ public final class OneToThreeQueueThroughputTest extends AbstractPerfTestQueue
{
private static final int NUM_EVENT_PROCESSORS = 3;
private static final int BUFFER_SIZE = 1024 * 8;
private static final long ITERATIONS = 1000L * 1000L * 10L;
private static final long ITERATIONS = 1000L * 1000L * 1L;
private final ExecutorService executor = Executors.newFixedThreadPool(NUM_EVENT_PROCESSORS);

private final long[] results = new long[NUM_EVENT_PROCESSORS];
Expand Down Expand Up @@ -141,7 +141,7 @@ protected long runQueuePass() throws InterruptedException
{
queueProcessors[i].halt();
futures[i].cancel(true);
Assert.assertEquals(results[i], queueProcessors[i].getValue());
failIf(queueProcessors[i].getValue(), -1);
}

return opsPerSecond;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.lmax.disruptor.queue;

import static org.junit.Assert.assertTrue;

import java.io.PrintStream;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -90,8 +88,6 @@ public void testImplementation() throws Exception

runQueuePass();

assertTrue(histogram.getHistogramData().getTotalCount() >= ITERATIONS);

System.out.format("%s run %d BlockingQueue %s\n", getClass().getSimpleName(), Long.valueOf(i), histogram);
dumpHistogram(histogram, System.out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package com.lmax.disruptor.sequenced;

import static com.lmax.disruptor.RingBuffer.createSingleProducer;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestDisruptor;
import com.lmax.disruptor.BatchEventProcessor;
import com.lmax.disruptor.RingBuffer;
Expand Down Expand Up @@ -111,7 +110,7 @@ protected long runDisruptorPass() throws InterruptedException
waitForEventProcessorSequence(expectedCount);
batchEventProcessor.halt();

Assert.assertEquals(expectedResult, handler.getValue());
failIfNot(expectedResult, handler.getValue());

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package com.lmax.disruptor.sequenced;

import static com.lmax.disruptor.RingBuffer.createSingleProducer;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestDisruptor;
import com.lmax.disruptor.BatchEventProcessor;
import com.lmax.disruptor.RingBuffer;
Expand Down Expand Up @@ -161,7 +160,7 @@ protected long runDisruptorPass() throws Exception
batchProcessorBuzz.halt();
batchProcessorFizzBuzz.halt();

Assert.assertEquals(expectedResult, fizzBuzzHandler.getFizzBuzzCounter());
failIfNot(expectedResult, fizzBuzzHandler.getFizzBuzzCounter());

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package com.lmax.disruptor.sequenced;

import static com.lmax.disruptor.RingBuffer.createSingleProducer;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestDisruptor;
import com.lmax.disruptor.BatchEventProcessor;
import com.lmax.disruptor.RingBuffer;
Expand Down Expand Up @@ -155,7 +154,7 @@ protected long runDisruptorPass() throws InterruptedException
stepTwoBatchProcessor.halt();
stepThreeBatchProcessor.halt();

Assert.assertEquals(expectedResult, stepThreeFunctionHandler.getStepThreeCounter());
failIfNot(expectedResult, stepThreeFunctionHandler.getStepThreeCounter());

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
package com.lmax.disruptor.sequenced;

import static com.lmax.disruptor.RingBuffer.createSingleProducer;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestDisruptor;
import com.lmax.disruptor.BatchEventProcessor;
import com.lmax.disruptor.RingBuffer;
Expand Down Expand Up @@ -146,7 +145,7 @@ protected long runDisruptorPass() throws InterruptedException
for (int i = 0; i < NUM_EVENT_PROCESSORS; i++)
{
batchEventProcessors[i].halt();
Assert.assertEquals(results[i], handlers[i].getValue());
failIfNot(results[i], handlers[i].getValue());
}

return opsPerSecond;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.lmax.disruptor.sequenced;

import static com.lmax.disruptor.RingBuffer.createSingleProducer;
import static org.junit.Assert.assertTrue;

import java.io.PrintStream;
import java.util.concurrent.BrokenBarrierException;
Expand Down Expand Up @@ -105,18 +104,13 @@ public void shouldCompareDisruptorVsQueues() throws Exception
{
final int runs = 3;

double[] disruptorMeanLatency = new double[runs];

for (int i = 0; i < runs; i++)
{
System.gc();
histogram.reset();

runDisruptorPass();

assertTrue(histogram.getHistogramData().getTotalCount() >= ITERATIONS);
disruptorMeanLatency[i] = histogram.getHistogramData().getMean();

System.out.format("%s run %d Disruptor %s\n", getClass().getSimpleName(), Long.valueOf(i), histogram);
dumpHistogram(histogram, System.out);
}
Expand Down
16 changes: 16 additions & 0 deletions src/perftest/java/com/lmax/disruptor/support/PerfTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,20 @@ public static long accumulatedAddition(final long iterations)

return temp;
}

public static void failIf(long a, long b)
{
if (a == b)
{
throw new RuntimeException();
}
}

public static void failIfNot(long a, long b)
{
if (a != b)
{
throw new RuntimeException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package com.lmax.disruptor.translator;

import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Assert;

import com.lmax.disruptor.AbstractPerfTestDisruptor;
import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;
Expand Down Expand Up @@ -77,7 +77,11 @@ public final class OneToOneTranslatorThroughputTest extends AbstractPerfTestDisr
@SuppressWarnings("unchecked")
public OneToOneTranslatorThroughputTest()
{
Disruptor disruptor = new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY, BUFFER_SIZE, executor, ProducerType.SINGLE, new YieldingWaitStrategy());
Disruptor<ValueEvent> disruptor =
new Disruptor<ValueEvent>(ValueEvent.EVENT_FACTORY,
BUFFER_SIZE, executor,
ProducerType.SINGLE,
new YieldingWaitStrategy());
disruptor.handleEventsWith(handler);
this.ringBuffer = disruptor.start();
}
Expand Down Expand Up @@ -113,7 +117,7 @@ protected long runDisruptorPass() throws InterruptedException
long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);
waitForEventProcessorSequence(expectedCount);

Assert.assertEquals(expectedResult, handler.getValue());
failIfNot(expectedResult, handler.getValue());

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.lmax.disruptor.workhandler;

import static junit.framework.Assert.assertEquals;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -99,7 +99,7 @@ protected long runDisruptorPass() throws InterruptedException

long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);

assertEquals(ITERATIONS, sumCounters());
failIfNot(ITERATIONS, sumCounters());

return opsPerSecond;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.lmax.disruptor.workhandler;

import static junit.framework.Assert.assertEquals;
import static com.lmax.disruptor.support.PerfTestUtil.failIfNot;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -109,7 +109,7 @@ protected long runDisruptorPass() throws InterruptedException
workerPool.drainAndHalt();
long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);

assertEquals(ITERATIONS, sumCounters());
failIfNot(ITERATIONS, sumCounters());

return opsPerSecond;
}
Expand Down

0 comments on commit 82e4a12

Please sign in to comment.