Search in sources :

Example 31 with Theory

use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.

the class AutoClosingLongStreamTest method testTerminalOperationDelegatesToAndClosesDelegate.

@Theory
public void testTerminalOperationDelegatesToAndClosesDelegate(@FromDataPoints("terminalOperations") TerminalOperation terminalOperation) {
    Object expectedResult = terminalOperation.result();
    if (expectedResult != null) {
        when(terminalOperation.apply(delegate)).thenReturn(expectedResult);
    }
    Object result = terminalOperation.apply(inTest);
    InOrder inOrder = inOrder(delegate);
    assertThat(result, is(expectedResult));
    inOrder.verify(delegate).close();
}
Also used : InOrder(org.mockito.InOrder) Theory(org.junit.experimental.theories.Theory)

Example 32 with Theory

use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.

the class AutoClosingStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.

@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") IntermediateOperation intermediateOperation) {
    BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
    when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
    BaseStream result = intermediateOperation.apply(inTest);
    assertThat(result, isAutoClosing());
    verifyDelegate(result, newDelegate);
}
Also used : BaseStream(java.util.stream.BaseStream) Theory(org.junit.experimental.theories.Theory)

Example 33 with Theory

use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.

the class AutoClosingStreamTest method testTerminalOperationDelegatesToAndClosesDelegate.

@Theory
public void testTerminalOperationDelegatesToAndClosesDelegate(@FromDataPoints("terminalOperations") TerminalOperation terminalOperation) {
    Object expectedResult = terminalOperation.result();
    if (expectedResult != null) {
        when(terminalOperation.apply(delegate)).thenReturn(expectedResult);
    }
    Object result = terminalOperation.apply(inTest);
    InOrder inOrder = inOrder(delegate);
    assertThat(result, is(expectedResult));
    inOrder.verify(delegate).close();
}
Also used : InOrder(org.mockito.InOrder) Theory(org.junit.experimental.theories.Theory)

Example 34 with Theory

use of org.junit.experimental.theories.Theory in project HdrHistogram by HdrHistogram.

the class HistogramEncodingTest method testHistogramEncoding.

@Theory
public void testHistogramEncoding(BufferAllocator allocator) throws Exception {
    ShortCountsHistogram shortCountsHistogram = new ShortCountsHistogram(highestTrackableValue, 3);
    IntCountsHistogram intCountsHistogram = new IntCountsHistogram(highestTrackableValue, 3);
    Histogram histogram = new Histogram(highestTrackableValue, 3);
    AtomicHistogram atomicHistogram = new AtomicHistogram(highestTrackableValue, 3);
    ConcurrentHistogram concurrentHistogram = new ConcurrentHistogram(highestTrackableValue, 3);
    SynchronizedHistogram synchronizedHistogram = new SynchronizedHistogram(highestTrackableValue, 3);
    DoubleHistogram doubleHistogram = new DoubleHistogram(highestTrackableValue * 1000, 3);
    for (int i = 0; i < 10000; i++) {
        shortCountsHistogram.recordValue(1000 * i);
        intCountsHistogram.recordValue(2000 * i);
        histogram.recordValue(3000 * i);
        atomicHistogram.recordValue(4000 * i);
        concurrentHistogram.recordValue(4000 * i);
        synchronizedHistogram.recordValue(5000 * i);
        doubleHistogram.recordValue(5000 * i);
        // Makes some internal shifts happen.
        doubleHistogram.recordValue(0.001);
    }
    System.out.println("Testing encoding of a ShortHistogram:");
    ByteBuffer targetBuffer = allocator.allocate(shortCountsHistogram.getNeededByteBufferCapacity());
    shortCountsHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    ShortCountsHistogram shortCountsHistogram2 = ShortCountsHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(shortCountsHistogram, shortCountsHistogram2);
    ByteBuffer targetCompressedBuffer = allocator.allocate(shortCountsHistogram.getNeededByteBufferCapacity());
    shortCountsHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    ShortCountsHistogram shortCountsHistogram3 = ShortCountsHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(shortCountsHistogram, shortCountsHistogram3);
    System.out.println("Testing encoding of a IntHistogram:");
    targetBuffer = allocator.allocate(intCountsHistogram.getNeededByteBufferCapacity());
    intCountsHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    IntCountsHistogram intCountsHistogram2 = IntCountsHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(intCountsHistogram, intCountsHistogram2);
    targetCompressedBuffer = allocator.allocate(intCountsHistogram.getNeededByteBufferCapacity());
    intCountsHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    IntCountsHistogram intCountsHistogram3 = IntCountsHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(intCountsHistogram, intCountsHistogram3);
    System.out.println("Testing encoding of a Histogram:");
    targetBuffer = allocator.allocate(histogram.getNeededByteBufferCapacity());
    histogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    Histogram histogram2 = Histogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(histogram, histogram2);
    targetCompressedBuffer = allocator.allocate(histogram.getNeededByteBufferCapacity());
    histogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    Histogram histogram3 = Histogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(histogram, histogram3);
    System.out.println("Testing encoding of a AtomicHistogram:");
    targetBuffer = allocator.allocate(atomicHistogram.getNeededByteBufferCapacity());
    atomicHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    AtomicHistogram atomicHistogram2 = AtomicHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(atomicHistogram, atomicHistogram2);
    targetCompressedBuffer = allocator.allocate(atomicHistogram.getNeededByteBufferCapacity());
    atomicHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    AtomicHistogram atomicHistogram3 = AtomicHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(atomicHistogram, atomicHistogram3);
    System.out.println("Testing encoding of a ConcurrentHistogram:");
    targetBuffer = allocator.allocate(concurrentHistogram.getNeededByteBufferCapacity());
    concurrentHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    ConcurrentHistogram concurrentHistogram2 = ConcurrentHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(concurrentHistogram, concurrentHistogram2);
    targetCompressedBuffer = allocator.allocate(concurrentHistogram.getNeededByteBufferCapacity());
    concurrentHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    ConcurrentHistogram concurrentHistogram3 = ConcurrentHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(concurrentHistogram, concurrentHistogram3);
    System.out.println("Testing encoding of a SynchronizedHistogram:");
    targetBuffer = allocator.allocate(synchronizedHistogram.getNeededByteBufferCapacity());
    synchronizedHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    SynchronizedHistogram synchronizedHistogram2 = SynchronizedHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(synchronizedHistogram, synchronizedHistogram2);
    synchronizedHistogram.setIntegerToDoubleValueConversionRatio(5.0);
    targetCompressedBuffer = allocator.allocate(synchronizedHistogram.getNeededByteBufferCapacity());
    synchronizedHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    SynchronizedHistogram synchronizedHistogram3 = SynchronizedHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(synchronizedHistogram, synchronizedHistogram3);
    System.out.println("Testing encoding of a DoubleHistogram:");
    targetBuffer = allocator.allocate(doubleHistogram.getNeededByteBufferCapacity());
    doubleHistogram.encodeIntoByteBuffer(targetBuffer);
    targetBuffer.rewind();
    DoubleHistogram doubleHistogram2 = DoubleHistogram.decodeFromByteBuffer(targetBuffer, 0);
    Assert.assertEquals(doubleHistogram, doubleHistogram2);
    targetCompressedBuffer = allocator.allocate(doubleHistogram.getNeededByteBufferCapacity());
    doubleHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
    targetCompressedBuffer.rewind();
    DoubleHistogram doubleHistogram3 = DoubleHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
    Assert.assertEquals(doubleHistogram, doubleHistogram3);
}
Also used : ByteBuffer(java.nio.ByteBuffer) DataPoint(org.junit.experimental.theories.DataPoint) Theory(org.junit.experimental.theories.Theory)

Example 35 with Theory

use of org.junit.experimental.theories.Theory in project opennms by OpenNMS.

the class DurationTest method testStartAndEndSame.

@Theory
public void testStartAndEndSame(Date time) {
    Duration d = new Duration(time, time);
    assertThat(d.millis(), is(0L));
}
Also used : Duration(org.opennms.util.ilr.Duration) Theory(org.junit.experimental.theories.Theory)

Aggregations

Theory (org.junit.experimental.theories.Theory)107 DataPoint (org.junit.experimental.theories.DataPoint)23 Test (org.junit.Test)22 Header (io.aeron.logbuffer.Header)15 DirectBuffer (org.agrona.DirectBuffer)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DebugReceiveChannelEndpoint (io.aeron.driver.ext.DebugReceiveChannelEndpoint)11 DebugSendChannelEndpoint (io.aeron.driver.ext.DebugSendChannelEndpoint)11 UdpChannel (io.aeron.driver.media.UdpChannel)11 MediaDriver (io.aeron.driver.MediaDriver)8 Lock (java.util.concurrent.locks.Lock)7 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)7 LongAdder (java.util.concurrent.atomic.LongAdder)6 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)6 PrimitiveCollection (org.neo4j.collection.primitive.PrimitiveCollection)6 InOrder (org.mockito.InOrder)5 InputStream (java.io.InputStream)4 BaseStream (java.util.stream.BaseStream)4 InterpreterContext (org.apache.zeppelin.interpreter.InterpreterContext)4 Metric (org.springframework.boot.actuate.metrics.Metric)4