Search in sources :

Example 1 with InOrder

use of org.mockito.InOrder in project che by eclipse.

the class CheEnvironmentEngineTest method destroyOfMachineOnEnvStopShouldNotPreventStopOfOthers.

@Test
public void destroyOfMachineOnEnvStopShouldNotPreventStopOfOthers() throws Exception {
    // given
    List<Instance> instances = startEnv();
    assertTrue(instances.size() > 1, "This test requires at least 2 instances in environment");
    Instance instance = instances.get(0);
    doThrow(new MachineException("test exception")).when(instance).destroy();
    // when
    engine.stop(instance.getWorkspaceId());
    // then
    InOrder inOrder = inOrder(instances.toArray());
    for (Instance instance1 : instances) {
        inOrder.verify(instance1).destroy();
    }
}
Also used : InOrder(org.mockito.InOrder) Instance(org.eclipse.che.api.machine.server.spi.Instance) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Test(org.testng.annotations.Test)

Example 2 with InOrder

use of org.mockito.InOrder in project che by eclipse.

the class WorkspaceManagerTest method shouldBeAbleToRemoveMachinesSnapshots.

@Test
public void shouldBeAbleToRemoveMachinesSnapshots() throws Exception {
    // given
    String testWsId = "testWsId";
    String testNamespace = "testNamespace";
    WorkspaceImpl workspaceMock = mock(WorkspaceImpl.class);
    when(workspaceDao.get(testWsId)).thenReturn(workspaceMock);
    when(workspaceMock.getNamespace()).thenReturn(testNamespace);
    SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(testWsId).setType("docker").setMachineSource(new MachineSourceImpl("image"));
    SnapshotImpl snapshot1 = snapshotBuilder.build();
    SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
    when(snapshotDao.findSnapshots(testWsId)).thenReturn(asList(snapshot1, snapshot2));
    // when
    workspaceManager.removeSnapshots(testWsId);
    // then
    captureExecuteCallsAndRunSynchronously();
    verify(runtimes).removeBinaries(asList(snapshot1, snapshot2));
    InOrder snapshotDaoInOrder = inOrder(snapshotDao);
    snapshotDaoInOrder.verify(snapshotDao).removeSnapshot(snapshot1.getId());
    snapshotDaoInOrder.verify(snapshotDao).removeSnapshot(snapshot2.getId());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) InOrder(org.mockito.InOrder) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 3 with InOrder

use of org.mockito.InOrder in project hbase by apache.

the class TestClientScanner method testNoResultsHint.

@Test
@SuppressWarnings("unchecked")
public void testNoResultsHint() throws IOException {
    final Result[] results = new Result[1];
    KeyValue kv1 = new KeyValue("row".getBytes(), "cf".getBytes(), "cq".getBytes(), 1, Type.Maximum);
    results[0] = Result.create(new Cell[] { kv1 });
    RpcRetryingCaller<Result[]> caller = Mockito.mock(RpcRetryingCaller.class);
    Mockito.when(rpcFactory.<Result[]>newCaller()).thenReturn(caller);
    Mockito.when(caller.callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt())).thenAnswer(new Answer<Result[]>() {

        private int count = 0;

        @Override
        public Result[] answer(InvocationOnMock invocation) throws Throwable {
            ScannerCallableWithReplicas callable = invocation.getArgumentAt(0, ScannerCallableWithReplicas.class);
            switch(count) {
                case // initialize
                0:
                    count++;
                    callable.currentScannerCallable.setMoreResultsInRegion(MoreResults.UNKNOWN);
                    return results;
                // detect no more results
                case 1:
                case // close
                2:
                    count++;
                    return new Result[0];
                default:
                    throw new RuntimeException("Expected only 2 invocations");
            }
        }
    });
    // Set a much larger cache and buffer size than we'll provide
    scan.setCaching(100);
    scan.setMaxResultSize(1000 * 1000);
    try (MockClientScanner scanner = new MockClientScanner(conf, scan, TableName.valueOf(name.getMethodName()), clusterConn, rpcFactory, controllerFactory, pool, Integer.MAX_VALUE)) {
        scanner.setRpcFinished(true);
        InOrder inOrder = Mockito.inOrder(caller);
        scanner.loadCache();
        // One for fetching the results
        // One for fetching empty results and quit as we do not have moreResults hint.
        inOrder.verify(caller, Mockito.times(2)).callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt());
        assertEquals(1, scanner.cache.size());
        Result r = scanner.cache.poll();
        assertNotNull(r);
        CellScanner cs = r.cellScanner();
        assertTrue(cs.advance());
        assertEquals(kv1, cs.current());
        assertFalse(cs.advance());
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) InOrder(org.mockito.InOrder) CellScanner(org.apache.hadoop.hbase.CellScanner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 4 with InOrder

use of org.mockito.InOrder in project hbase by apache.

the class TestClientScanner method testNoMoreResults.

@Test
@SuppressWarnings("unchecked")
public void testNoMoreResults() throws IOException {
    final Result[] results = new Result[1];
    KeyValue kv1 = new KeyValue("row".getBytes(), "cf".getBytes(), "cq".getBytes(), 1, Type.Maximum);
    results[0] = Result.create(new Cell[] { kv1 });
    RpcRetryingCaller<Result[]> caller = Mockito.mock(RpcRetryingCaller.class);
    Mockito.when(rpcFactory.<Result[]>newCaller()).thenReturn(caller);
    Mockito.when(caller.callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt())).thenAnswer(new Answer<Result[]>() {

        private int count = 0;

        @Override
        public Result[] answer(InvocationOnMock invocation) throws Throwable {
            ScannerCallableWithReplicas callable = invocation.getArgumentAt(0, ScannerCallableWithReplicas.class);
            switch(count) {
                case // initialize
                0:
                    count++;
                    callable.currentScannerCallable.setMoreResultsInRegion(MoreResults.NO);
                    return results;
                case // close
                1:
                    count++;
                    return null;
                default:
                    throw new RuntimeException("Expected only 2 invocations");
            }
        }
    });
    Mockito.when(rpcFactory.<Result[]>newCaller()).thenReturn(caller);
    // Set a much larger cache and buffer size than we'll provide
    scan.setCaching(100);
    scan.setMaxResultSize(1000 * 1000);
    try (MockClientScanner scanner = new MockClientScanner(conf, scan, TableName.valueOf(name.getMethodName()), clusterConn, rpcFactory, controllerFactory, pool, Integer.MAX_VALUE)) {
        scanner.setRpcFinished(true);
        InOrder inOrder = Mockito.inOrder(caller);
        scanner.loadCache();
        inOrder.verify(caller, Mockito.times(1)).callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt());
        assertEquals(1, scanner.cache.size());
        Result r = scanner.cache.poll();
        assertNotNull(r);
        CellScanner cs = r.cellScanner();
        assertTrue(cs.advance());
        assertEquals(kv1, cs.current());
        assertFalse(cs.advance());
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) InOrder(org.mockito.InOrder) CellScanner(org.apache.hadoop.hbase.CellScanner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 5 with InOrder

use of org.mockito.InOrder in project hbase by apache.

the class TestClientScanner method testSizeLimit.

@Test
@SuppressWarnings("unchecked")
public void testSizeLimit() throws IOException {
    final Result[] results = new Result[1];
    KeyValue kv1 = new KeyValue("row".getBytes(), "cf".getBytes(), "cq".getBytes(), 1, Type.Maximum);
    results[0] = Result.create(new Cell[] { kv1 });
    RpcRetryingCaller<Result[]> caller = Mockito.mock(RpcRetryingCaller.class);
    Mockito.when(rpcFactory.<Result[]>newCaller()).thenReturn(caller);
    Mockito.when(caller.callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt())).thenAnswer(new Answer<Result[]>() {

        private int count = 0;

        @Override
        public Result[] answer(InvocationOnMock invocation) throws Throwable {
            ScannerCallableWithReplicas callable = invocation.getArgumentAt(0, ScannerCallableWithReplicas.class);
            switch(count) {
                case // initialize
                0:
                    count++;
                    // if we set no here the implementation will trigger a close
                    callable.currentScannerCallable.setMoreResultsInRegion(MoreResults.YES);
                    return results;
                case // close
                1:
                    count++;
                    return null;
                default:
                    throw new RuntimeException("Expected only 2 invocations");
            }
        }
    });
    Mockito.when(rpcFactory.<Result[]>newCaller()).thenReturn(caller);
    // Set a much larger cache
    scan.setCaching(100);
    // The single key-value will exit the loop
    scan.setMaxResultSize(1);
    try (MockClientScanner scanner = new MockClientScanner(conf, scan, TableName.valueOf(name.getMethodName()), clusterConn, rpcFactory, controllerFactory, pool, Integer.MAX_VALUE)) {
        InOrder inOrder = Mockito.inOrder(caller);
        scanner.loadCache();
        inOrder.verify(caller, Mockito.times(1)).callWithoutRetries(Mockito.any(RetryingCallable.class), Mockito.anyInt());
        assertEquals(1, scanner.cache.size());
        Result r = scanner.cache.poll();
        assertNotNull(r);
        CellScanner cs = r.cellScanner();
        assertTrue(cs.advance());
        assertEquals(kv1, cs.current());
        assertFalse(cs.advance());
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) InOrder(org.mockito.InOrder) CellScanner(org.apache.hadoop.hbase.CellScanner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Aggregations

InOrder (org.mockito.InOrder)3292 Test (org.junit.Test)2308 Test (org.junit.jupiter.api.Test)377 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)108 HashMap (java.util.HashMap)104 ArrayList (java.util.ArrayList)98 Response (com.jayway.restassured.response.Response)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 IOException (java.io.IOException)64 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 SmallTest (org.mule.tck.size.SmallTest)62 List (java.util.List)57 CompletableFuture (java.util.concurrent.CompletableFuture)52 Cleanup (lombok.Cleanup)46 InvocationOnMock (org.mockito.invocation.InvocationOnMock)46 WireCommands (io.pravega.shared.protocol.netty.WireCommands)45 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)44 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)44 Metadata (io.grpc.Metadata)43 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)41