Java Code Examples for org.easymock.Capture.newInstance()

The following are Jave code examples for showing how to use newInstance() of the org.easymock.Capture class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 6 votes
@Test
public void testRestartTaskLeaderRedirect() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);

    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    expectAndCallbackNotLeaderException(cb);

    EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=true"),
            EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
            .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));

    PowerMock.replayAll();

    connectorsResource.restartTask(CONNECTOR_NAME, 0, null);

    PowerMock.verifyAll();
}
 
Example 2
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 6 votes
@Test
public void testRestartTaskOwnerRedirect() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);

    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    String ownerUrl = "http://owner:8083";
    expectAndCallbackException(cb, new NotAssignedException("not owner test", ownerUrl));

    EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://owner:8083/connectors/" + CONNECTOR_NAME + "/tasks/0/restart?forward=false"),
            EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
            .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));

    PowerMock.replayAll();

    connectorsResource.restartTask(CONNECTOR_NAME, 0, true);

    PowerMock.verifyAll();
}
 
Example 3
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 6 votes
@Test
public void testRestartConnectorLeaderRedirect() throws Throwable {
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackNotLeaderException(cb);

    EasyMock.expect(RestServer.httpRequest(EasyMock.eq("http://leader:8083/connectors/" + CONNECTOR_NAME + "/restart?forward=true"),
            EasyMock.eq("POST"), EasyMock.isNull(), EasyMock.<TypeReference>anyObject()))
            .andReturn(new RestServer.HttpResponse<>(202, new HashMap<String, List<String>>(), null));

    PowerMock.replayAll();

    connectorsResource.restartConnector(CONNECTOR_NAME, null);

    PowerMock.verifyAll();
}
 
Example 4
Project: grox   File: StoreTest.java   View Source Code Vote up 5 votes
@Test
public void testDispatchAction_withMiddleWare_shouldTriggerMiddleWareAndChangeState() {
  //GIVEN
  Middleware<Integer> mockMiddleWare = createStrictMock(Middleware.class);
  final Action<Integer> action = createStrictMock(Action.class);
  Store<Integer> store = new Store<>(0, mockMiddleWare);

  Capture<Middleware.Chain<Integer>> capturedChain = Capture.newInstance();
  mockMiddleWare.intercept(capture(capturedChain));
  expectLastCall()
      .andAnswer(
          () -> {
            final Middleware.Chain<Integer> chain =
                (Middleware.Chain<Integer>) getCurrentArguments()[0];
            chain.proceed(chain.action());
            return null;
          });
  expect(action.newState(0)).andReturn(1);
  replay(mockMiddleWare, action);

  //WHEN
  store.dispatch(action);

  //THEN
  verify(mockMiddleWare, action);
  assertThat(capturedChain.getValue().action(), is(action));
  assertThat(store.getState(), is(1));
}
 
Example 5
Project: grox   File: StoreTest.java   View Source Code Vote up 5 votes
@Test
public void
    testDispatchAction_withMiddleWares_shouldTriggerMiddleWareAndChangeStateUsingNewAction() {
  //GIVEN
  Middleware<Integer> mockMiddleWare = createMock(Middleware.class);
  final Action<Integer> action = createMock(Action.class);
  Store<Integer> store = new Store<>(0, mockMiddleWare);

  Capture<Middleware.Chain<Integer>> capturedChain = Capture.newInstance();
  mockMiddleWare.intercept(capture(capturedChain));
  expectLastCall()
      .andAnswer(
          () -> {
            final Middleware.Chain<Integer> chain =
                (Middleware.Chain<Integer>) getCurrentArguments()[0];
            final Action<Integer> decrementAction = integer -> integer - 1;
            chain.proceed(decrementAction);
            return null;
          });
  replay(mockMiddleWare, action);

  //WHEN
  store.dispatch(action);

  //THEN
  verify(mockMiddleWare, action);
  assertThat(store.getState(), is(-1));
}
 
Example 6
Project: kafka-0.11.0.0-src-with-comment   File: StandaloneHerderTest.java   View Source Code Vote up 5 votes
@Test
public void testCorruptConfig() {
    Map<String, String> config = new HashMap<>();
    config.put(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME);
    config.put(ConnectorConfig.CONNECTOR_CLASS_CONFIG, BogusSinkConnector.class.getName());
    Connector connectorMock = PowerMock.createMock(Connector.class);
    String error = "This is an error in your config!";
    List<String> errors = new ArrayList<>(singletonList(error));
    String key = "foo.invalid.key";
    EasyMock.expect(connectorMock.validate(config)).andReturn(
        new Config(
            Arrays.asList(new ConfigValue(key, null, Collections.emptyList(), errors))
        )
    );
    ConfigDef configDef = new ConfigDef();
    configDef.define(key, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "");
    EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(3);
    EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
    EasyMock.expect(worker.getPlugins()).andStubReturn(plugins);
    EasyMock.expect(plugins.newConnector(EasyMock.anyString())).andReturn(connectorMock);
    EasyMock.expect(connectorMock.config()).andStubReturn(configDef);
    EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
    Callback<Herder.Created<ConnectorInfo>> callback = PowerMock.createMock(Callback.class);
    Capture<BadRequestException> capture = Capture.newInstance();
    callback.onCompletion(
        EasyMock.capture(capture), EasyMock.isNull(Herder.Created.class)
    );

    PowerMock.replayAll();

    herder.putConnectorConfig(CONNECTOR_NAME, config, true, callback);
    assertEquals(
        capture.getValue().getMessage(),
        "Connector configuration is invalid and contains the following 1 error(s):\n" +
            error + "\n" +
            "You can also find the above list of errors at the endpoint `/{connectorType}/config/validate`"
    );

    PowerMock.verifyAll();
}
 
Example 7
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test
public void testGetConnectorTaskConfigs() throws Throwable {
    final Capture<Callback<List<TaskInfo>>> cb = Capture.newInstance();
    herder.taskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackResult(cb, TASK_INFOS);

    PowerMock.replayAll();

    List<TaskInfo> taskInfos = connectorsResource.getTaskConfigs(CONNECTOR_NAME, FORWARD);
    assertEquals(TASK_INFOS, taskInfos);

    PowerMock.verifyAll();
}
 
Example 8
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test
public void testPutConnectorTaskConfigs() throws Throwable {
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb));
    expectAndCallbackResult(cb, null);

    PowerMock.replayAll();

    connectorsResource.putTaskConfigs(CONNECTOR_NAME, FORWARD, TASK_CONFIGS);

    PowerMock.verifyAll();
}
 
Example 9
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test(expected = AlreadyExistsException.class)
public void testCreateConnectorExists() throws Throwable {
    CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));

    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackException(cb, new AlreadyExistsException("already exists"));

    PowerMock.replayAll();

    connectorsResource.createConnector(FORWARD, body);

    PowerMock.verifyAll();
}
 
Example 10
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test(expected = NotFoundException.class)
public void testRestartConnectorNotFound() throws Throwable {
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartConnector(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));

    PowerMock.replayAll();

    connectorsResource.restartConnector(CONNECTOR_NAME, FORWARD);

    PowerMock.verifyAll();
}
 
Example 11
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test
public void testPutConnectorConfig() throws Throwable {
    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(CONNECTOR_CONFIG), EasyMock.eq(true), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(false, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));

    PowerMock.replayAll();

    connectorsResource.putConnectorConfig(CONNECTOR_NAME, FORWARD, CONNECTOR_CONFIG);

    PowerMock.verifyAll();
}
 
Example 12
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test(expected = NotFoundException.class)
public void testRestartTaskNotFound() throws Throwable {
    ConnectorTaskId taskId = new ConnectorTaskId(CONNECTOR_NAME, 0);
    final Capture<Callback<Void>> cb = Capture.newInstance();
    herder.restartTask(EasyMock.eq(taskId), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));

    PowerMock.replayAll();

    connectorsResource.restartTask(CONNECTOR_NAME, 0, FORWARD);

    PowerMock.verifyAll();
}
 
Example 13
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test
public void testGetConnectorConfig() throws Throwable {
    final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();
    herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackResult(cb, CONNECTOR_CONFIG);

    PowerMock.replayAll();

    Map<String, String> connConfig = connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);
    assertEquals(CONNECTOR_CONFIG, connConfig);

    PowerMock.verifyAll();
}
 
Example 14
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 5 votes
@Test(expected = NotFoundException.class)
public void testGetConnectorConfigConnectorNotFound() throws Throwable {
    final Capture<Callback<Map<String, String>>> cb = Capture.newInstance();
    herder.connectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.capture(cb));
    expectAndCallbackException(cb, new NotFoundException("not found"));

    PowerMock.replayAll();

    connectorsResource.getConnectorConfig(CONNECTOR_NAME, FORWARD);

    PowerMock.verifyAll();
}
 
Example 15
Project: devops-cm-client   File: CMODataClientCreateTransportTest.java   View Source Code Vote up 4 votes
@Before
public void setup() throws Exception {
    super.setup();
    contentType = Capture.newInstance();
}
 
Example 16
Project: kafka-0.11.0.0-src-with-comment   File: OffsetStorageWriterTest.java   View Source Code Vote up 4 votes
/**
 * Expect a request to store data to the underlying OffsetBackingStore.
 *
 * @param key the key for the offset
 * @param keySerialized serialized version of the key
 * @param value the value for the offset
 * @param valueSerialized serialized version of the value
 * @param callback the callback to invoke when completed, or null if the callback isn't
 *                 expected to be invoked
 * @param fail if true, treat
 * @param waitForCompletion if non-null, a CountDownLatch that should be awaited on before
 *                          invoking the callback. A (generous) timeout is still imposed to
 *                          ensure tests complete.
 * @return the captured set of ByteBuffer key-value pairs passed to the storage layer
 */
private void expectStore(Map<String, String> key, byte[] keySerialized,
                         Map<String, Integer> value, byte[] valueSerialized,
                         final Callback<Void> callback,
                         final boolean fail,
                         final CountDownLatch waitForCompletion) {
    List<Object> keyWrapped = Arrays.asList(NAMESPACE, key);
    EasyMock.expect(keyConverter.fromConnectData(NAMESPACE, null, keyWrapped)).andReturn(keySerialized);
    EasyMock.expect(valueConverter.fromConnectData(NAMESPACE, null, value)).andReturn(valueSerialized);

    final Capture<Callback<Void>> storeCallback = Capture.newInstance();
    final Map<ByteBuffer, ByteBuffer> offsetsSerialized = Collections.singletonMap(
            keySerialized == null ? null : ByteBuffer.wrap(keySerialized),
            valueSerialized == null ? null : ByteBuffer.wrap(valueSerialized));
    EasyMock.expect(store.set(EasyMock.eq(offsetsSerialized), EasyMock.capture(storeCallback)))
            .andAnswer(new IAnswer<Future<Void>>() {
                @Override
                public Future<Void> answer() throws Throwable {
                    return service.submit(new Callable<Void>() {
                        @Override
                        public Void call() throws Exception {
                            if (waitForCompletion != null)
                                assertTrue(waitForCompletion.await(10000, TimeUnit.MILLISECONDS));

                            if (fail) {
                                storeCallback.getValue().onCompletion(exception, null);
                            } else {
                                storeCallback.getValue().onCompletion(null, null);
                            }
                            return null;
                        }
                    });
                }
            });
    if (callback != null) {
        if (fail) {
            callback.onCompletion(EasyMock.eq(exception), EasyMock.eq((Void) null));
        } else {
            callback.onCompletion(null, null);
        }
    }
    PowerMock.expectLastCall();
}
 
Example 17
Project: devops-cm-client   File: CMODataClientChangesTest.java   View Source Code Vote up 4 votes
@Before
public void setup() throws Exception {
    super.setup();
    contentType = Capture.newInstance();
}
 
Example 18
Project: devops-cm-client   File: ReleaseTransportTest.java   View Source Code Vote up 4 votes
@Before
public void setup() throws Exception {
    super.setup();
    transportId = Capture.newInstance();
}
 
Example 19
Project: devops-cm-client   File: CreateTransportTest.java   View Source Code Vote up 4 votes
@Before
public void setup() throws Exception {
    super.setup();
    owner = Capture.newInstance();
    description = Capture.newInstance();
}
 
Example 20
Project: kafka-0.11.0.0-src-with-comment   File: ConnectorsResourceTest.java   View Source Code Vote up 4 votes
@Test(expected = BadRequestException.class)
public void testCreateConnectorWithASlashInItsName() throws Throwable {
    String badConnectorName = CONNECTOR_NAME + "/" + "test";

    CreateConnectorRequest body = new CreateConnectorRequest(badConnectorName, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, badConnectorName));

    final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
    herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
    expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES)));

    PowerMock.replayAll();

    connectorsResource.createConnector(FORWARD, body);

    PowerMock.verifyAll();
}