Search in sources :

Example 36 with Theory

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

the class AutoClosingDoubleStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.

@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") DoubleermediateOperation 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 37 with Theory

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

the class AutoClosingDoubleStreamTest 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 38 with Theory

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

the class AutoClosingIntStreamTest 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 39 with Theory

use of org.junit.experimental.theories.Theory in project sling by apache.

the class ContentFileCacheTest method testCache.

@Theory
public void testCache(int cacheSize) {
    ContentFileCache underTest = new ContentFileCache(cacheSize);
    ContentElement content1 = underTest.get("/fs-test/folder2/content", new File("src/test/resources/fs-test/folder2/content.json"));
    assertNotNull(content1);
    switch(cacheSize) {
        case NO_CACHE:
            assertEquals(0, underTest.size());
            break;
        case SMALL_CACHE:
        case HUGE_CACHE:
            assertEquals(1, underTest.size());
            break;
    }
    ContentElement content2 = underTest.get("/fs-test/folder1/file1a", new File("src/test/resources/fs-test/folder1/file1a.txt"));
    assertNull(content2);
    switch(cacheSize) {
        case NO_CACHE:
            assertEquals(0, underTest.size());
            break;
        case SMALL_CACHE:
            assertEquals(1, underTest.size());
            break;
        case HUGE_CACHE:
            assertEquals(2, underTest.size());
            break;
    }
    underTest.remove("/fs-test/folder1/file1a");
    switch(cacheSize) {
        case NO_CACHE:
        case SMALL_CACHE:
            assertEquals(0, underTest.size());
            break;
        case HUGE_CACHE:
            assertEquals(1, underTest.size());
            break;
    }
    underTest.clear();
    assertEquals(0, underTest.size());
}
Also used : File(java.io.File) Theory(org.junit.experimental.theories.Theory)

Example 40 with Theory

use of org.junit.experimental.theories.Theory in project helios by spotify.

the class DeploymentGroupTest method testStopDeploymentGroup.

// A test that...
// * Verifies that the state in ZK is correct after running stop
// * Verifies that the correct exception is thrown when the DG does not exist or there is a
//   race condition
@Theory
public void testStopDeploymentGroup(@TestedOn(ints = { 0, 1 }) final int dgExistsInt, @TestedOn(ints = { 0, 1 }) final int tasksExistInt, @TestedOn(ints = { 0, 1 }) final int tasksExistWhenCommittingInt) throws Exception {
    final boolean dgExists = dgExistsInt != 0;
    final boolean tasksExist = tasksExistInt != 0;
    final boolean tasksExistWhenCommitting = tasksExistWhenCommittingInt != 0;
    // To be able to simulate triggering the race condition in stopDeploymentGroup we need to do
    // some mocking, relying on that the implementation uses client.exists() to check for the
    // presence of tasks.
    final ZooKeeperClient client = spy(this.client);
    when(client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME))).thenReturn(tasksExist ? mock(Stat.class) : null);
    final ZooKeeperMasterModel masterModel = newMasterModel(client);
    if (dgExists) {
        final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).build();
        masterModel.addDeploymentGroup(dg);
    }
    if (tasksExistWhenCommitting) {
        client.ensurePath(Paths.statusDeploymentGroupTasks());
        client.create(Paths.statusDeploymentGroupTasks(GROUP_NAME));
    }
    if (!dgExists) {
        exception.expect(DeploymentGroupDoesNotExistException.class);
    } else if (tasksExist != tasksExistWhenCommitting) {
        exception.expect(HeliosRuntimeException.class);
    }
    masterModel.stopDeploymentGroup(GROUP_NAME);
    // Verify that the state in ZK is correct:
    // * tasks are not present
    // * the status is set to FAILED
    //
    // When checking for the existence of the tasks make sure we use the client that doesn't have
    // the exists() method mocked out!
    assertNull(this.client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME)));
    final DeploymentGroupStatus status = masterModel.getDeploymentGroupStatus(GROUP_NAME);
    assertEquals(FAILED, status.getState());
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) DeploymentGroupStatus(com.spotify.helios.common.descriptors.DeploymentGroupStatus) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) 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