// Path: src/performance/java/com/lmax/disruptor/support/ValueAdditionEventHandler.java
// public final class ValueAdditionEventHandler implements EventHandler<ValueEvent>
// {
//     private final PaddedLong value = new PaddedLong();
//     private long count;
//     private CountDownLatch latch;
// 
//     public long getValue()
//     {
//         return value.get();
//     }
// 
//     public void reset(final CountDownLatch latch, final long expectedCount)
//     {
//         value.set(0L);
//         this.latch = latch;
//         count = expectedCount;
//     }
// 
//     @Override
//     public void onEvent(final ValueEvent event, final long sequence, final boolean endOfBatch) throws Exception
//     {
//         value.set(value.get() + event.getValue());
// 
//         if (count == sequence)
//         {
//             latch.countDown();
//         }
//     }
// }
// 
// Path: src/performance/java/com/lmax/disruptor/support/ValueEvent.java
// public final class ValueEvent
// {
//     private long value;
// 
//     public long getValue()
//     {
//         return value;
//     }
// 
//     public void setValue(final long value)
//     {
//         this.value = value;
//     }
// 
//     public final static EventFactory<ValueEvent> EVENT_FACTORY = new EventFactory<ValueEvent>()
//     {
//         public ValueEvent newInstance()
//         {
//             return new ValueEvent();
//         }
//     };
// }


import com.lmax.disruptor.support.PerfTestUtil;
import com.lmax.disruptor.support.ValueAdditionEventHandler;
import com.lmax.disruptor.support.ValueEvent;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.*;
/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor;



/**
 * <pre>
 * UniCast a series of items between 1 publisher and 1 event processor.
 * This test illustrates the benefits of writing batches of 10 events
 * for exchange at a time.
 *
 * +----+    +-----+
 * | P1 |--->| EP1 |
 * +----+    +-----+
 *
 *
 * Queue Based:
 * ============
 *
 *        put      take
 * +----+    +====+    +-----+
 * | P1 |--->| Q1 |<---| EP1 |
 * +----+    +====+    +-----+
 *
 * P1  - Publisher 1
 * Q1  - Queue 1
 * EP1 - EventProcessor 1
 *
 *
 * Disruptor:
 * ==========
 *              track to prevent wrap
 *              +------------------+
 *              |                  |
 *              |                  v
 * +----+    +====+    +====+   +-----+
 * | P1 |--->| RB |<---| SB |   | EP1 |
 * +----+    +====+    +====+   +-----+
 *      claim      get    ^        |
 *                        |        |
 *                        +--------+
 *                          waitFor
 *
 * P1  - Publisher 1
 * RB  - RingBuffer
 * SB  - SequenceBarrier
 * EP1 - EventProcessor 1
 * </pre>
 */
public final class OnePublisherToOneProcessorUniCastBatchThroughputTest extends AbstractPerfTestQueueVsDisruptor
{
    private static final int BUFFER_SIZE = 1024 * 8;
    private static final long ITERATIONS = 1000L * 1000L * 100L;
    private final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
    private final long expectedResult = PerfTestUtil.accumulatedAddition(ITERATIONS);

    ///////////////////////////////////////////////////////////////////////////////////////////////

    private final RingBuffer<ValueEvent> ringBuffer =
        new RingBuffer<ValueEvent>(ValueEvent.EVENT_FACTORY,
                                   new SingleThreadedClaimStrategy(BUFFER_SIZE),
                                   new YieldingWaitStrategy());
    private final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
// Path: src/performance/java/com/lmax/disruptor/support/ValueAdditionEventHandler.java
// public final class ValueAdditionEventHandler implements EventHandler<ValueEvent>
// {
//     private final PaddedLong value = new PaddedLong();
//     private long count;
//     private CountDownLatch latch;
// 
//     public long getValue()
//     {
//         return value.get();
//     }
// 
//     public void reset(final CountDownLatch latch, final long expectedCount)
//     {
//         value.set(0L);
//         this.latch = latch;
//         count = expectedCount;
//     }
// 
//     @Override
//     public void onEvent(final ValueEvent event, final long sequence, final boolean endOfBatch) throws Exception
//     {
//         value.set(value.get() + event.getValue());
// 
//         if (count == sequence)
//         {
//             latch.countDown();
//         }
//     }
// }
// 
// Path: src/performance/java/com/lmax/disruptor/support/ValueEvent.java
// public final class ValueEvent
// {
//     private long value;
// 
//     public long getValue()
//     {
//         return value;
//     }
// 
//     public void setValue(final long value)
//     {
//         this.value = value;
//     }
// 
//     public final static EventFactory<ValueEvent> EVENT_FACTORY = new EventFactory<ValueEvent>()
//     {
//         public ValueEvent newInstance()
//         {
//             return new ValueEvent();
//         }
//     };
// }


// Path: src/performance/java/com/lmax/disruptor/OnePublisherToOneProcessorUniCastBatchThroughputTest.java
import com.lmax.disruptor.support.PerfTestUtil;
import com.lmax.disruptor.support.ValueAdditionEventHandler;
import com.lmax.disruptor.support.ValueEvent;
import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.*;

/*
 * Copyright 2011 LMAX Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lmax.disruptor;



/**
 * <pre>
 * UniCast a series of items between 1 publisher and 1 event processor.
 * This test illustrates the benefits of writing batches of 10 events
 * for exchange at a time.
 *
 * +----+    +-----+
 * | P1 |--->| EP1 |
 * +----+    +-----+
 *
 *
 * Queue Based:
 * ============
 *
 *        put      take
 * +----+    +====+    +-----+
 * | P1 |--->| Q1 |<---| EP1 |
 * +----+    +====+    +-----+
 *
 * P1  - Publisher 1
 * Q1  - Queue 1
 * EP1 - EventProcessor 1
 *
 *
 * Disruptor:
 * ==========
 *              track to prevent wrap
 *              +------------------+
 *              |                  |
 *              |                  v
 * +----+    +====+    +====+   +-----+
 * | P1 |--->| RB |<---| SB |   | EP1 |
 * +----+    +====+    +====+   +-----+
 *      claim      get    ^        |
 *                        |        |
 *                        +--------+
 *                          waitFor
 *
 * P1  - Publisher 1
 * RB  - RingBuffer
 * SB  - SequenceBarrier
 * EP1 - EventProcessor 1
 * </pre>
 */
public final class OnePublisherToOneProcessorUniCastBatchThroughputTest extends AbstractPerfTestQueueVsDisruptor
{
    private static final int BUFFER_SIZE = 1024 * 8;
    private static final long ITERATIONS = 1000L * 1000L * 100L;
    private final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor();
    private final long expectedResult = PerfTestUtil.accumulatedAddition(ITERATIONS);

    ///////////////////////////////////////////////////////////////////////////////////////////////

    private final RingBuffer<ValueEvent> ringBuffer =
        new RingBuffer<ValueEvent>(ValueEvent.EVENT_FACTORY,
                                   new SingleThreadedClaimStrategy(BUFFER_SIZE),
                                   new YieldingWaitStrategy());
    private final SequenceBarrier sequenceBarrier = ringBuffer.newBarrier();
    private final ValueAdditionEventHandler handler = new ValueAdditionEventHandler();