當前位置: 首頁>>代碼示例>>Java>>正文


Java PowerMock.expectLastCall方法代碼示例

本文整理匯總了Java中org.powermock.api.easymock.PowerMock.expectLastCall方法的典型用法代碼示例。如果您正苦於以下問題:Java PowerMock.expectLastCall方法的具體用法?Java PowerMock.expectLastCall怎麽用?Java PowerMock.expectLastCall使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.powermock.api.easymock.PowerMock的用法示例。


在下文中一共展示了PowerMock.expectLastCall方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: expectOffsetFlush

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void expectOffsetFlush(boolean succeed) throws Exception {
    EasyMock.expect(offsetWriter.beginFlush()).andReturn(true);
    Future<Void> flushFuture = PowerMock.createMock(Future.class);
    EasyMock.expect(offsetWriter.doFlush(EasyMock.anyObject(Callback.class))).andReturn(flushFuture);
    // Should throw for failure
    IExpectationSetters<Void> futureGetExpect = EasyMock.expect(
            flushFuture.get(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class)));
    if (succeed) {
        sourceTask.commit();
        EasyMock.expectLastCall();
        futureGetExpect.andReturn(null);
    } else {
        futureGetExpect.andThrow(new TimeoutException());
        offsetWriter.cancelFlush();
        PowerMock.expectLastCall();
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:19,代碼來源:WorkerSourceTaskTest.java

示例2: testCreateConnectorAlreadyExists

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCreateConnectorAlreadyExists() throws Exception {
    connector = PowerMock.createMock(BogusSourceConnector.class);
    // First addition should succeed
    expectAdd(SourceSink.SOURCE);

    Map<String, String> config = connectorConfig(SourceSink.SOURCE);
    Connector connectorMock = PowerMock.createMock(Connector.class);
    expectConfigValidation(connectorMock, true, config, config);

    EasyMock.expect(worker.getPlugins()).andReturn(plugins).times(2);
    EasyMock.expect(plugins.compareAndSwapLoaders(connectorMock)).andReturn(delegatingLoader);
    // No new connector is created
    EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader)).andReturn(pluginLoader);
    // Second should fail
    createCallback.onCompletion(EasyMock.<AlreadyExistsException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);
    herder.putConnectorConfig(CONNECTOR_NAME, config, false, createCallback);

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:26,代碼來源:StandaloneHerderTest.java

示例3: testStartPaused

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testStartPaused() throws Exception {
    workerTask = PowerMock.createPartialMock(
            WorkerSinkTask.class, new String[]{"createConsumer"},
            taskId, sinkTask, statusListener, TargetState.PAUSED, workerConfig, keyConverter, valueConverter, transformationChain, pluginLoader, time);

    expectInitializeTask();
    expectPollInitialAssignment();

    Set<TopicPartition> partitions = new HashSet<>(asList(TOPIC_PARTITION, TOPIC_PARTITION2));
    EasyMock.expect(consumer.assignment()).andReturn(partitions);
    consumer.pause(partitions);
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();
    workerTask.iteration();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:WorkerSinkTaskTest.java

示例4: testCreateConnectorAlreadyExists

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCreateConnectorAlreadyExists() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);

    member.wakeup();
    PowerMock.expectLastCall();
    // CONN1 already exists
    putConnectorCallback.onCompletion(EasyMock.<AlreadyExistsException>anyObject(), EasyMock.<Herder.Created<ConnectorInfo>>isNull());
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // No immediate action besides this -- change will be picked up via the config log

    PowerMock.replayAll();

    herder.putConnectorConfig(CONN1, CONN1_CONFIG, false, putConnectorCallback);
    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:DistributedHerderTest.java

示例5: testJoinLeaderCatchUpFails

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testJoinLeaderCatchUpFails() throws Exception {
    // Join group and as leader fail to do assignment
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(),
            ConnectProtocol.Assignment.CONFIG_MISMATCH, 1, Collections.<String>emptyList(),
            Collections.<ConnectorTaskId>emptyList());
    // Reading to end of log times out
    configBackingStore.refresh(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
    EasyMock.expectLastCall().andThrow(new TimeoutException());
    member.maybeLeaveGroup();
    EasyMock.expectLastCall();
    PowerMock.expectPrivate(herder, "backoff", DistributedConfig.WORKER_UNSYNC_BACKOFF_MS_DEFAULT);
    member.requestRejoin();

    // After backoff, restart the process and this time succeed
    expectRebalance(1, Arrays.asList(CONN1), Arrays.asList(TASK1));
    expectPostRebalanceCatchup(SNAPSHOT);

    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.getPlugins()).andReturn(plugins);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);
    worker.startTask(EasyMock.eq(TASK1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Map<String, String>>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick();
    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:39,代碼來源:DistributedHerderTest.java

示例6: expectSuccessfulGetCallback

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Callback<Map<ByteBuffer, ByteBuffer>> expectSuccessfulGetCallback() {
    Callback<Map<ByteBuffer, ByteBuffer>> getCallback = PowerMock.createMock(Callback.class);
    getCallback.onCompletion(EasyMock.isNull(Throwable.class), EasyMock.anyObject(Map.class));
    PowerMock.expectLastCall();
    return getCallback;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:8,代碼來源:FileOffsetBackingStoreTest.java

示例7: testDestroyConnector

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testDestroyConnector() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    // Start with one connector
    EasyMock.expect(worker.getPlugins()).andReturn(plugins);
    expectRebalance(1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);

    // And delete the connector
    member.wakeup();
    PowerMock.expectLastCall();
    configBackingStore.removeConnectorConfig(CONN1);
    PowerMock.expectLastCall();
    putConnectorCallback.onCompletion(null, new Herder.Created<ConnectorInfo>(false, null));
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();
    // No immediate action besides this -- change will be picked up via the config log

    PowerMock.replayAll();

    herder.deleteConnectorConfig(CONN1, putConnectorCallback);
    herder.tick();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:32,代碼來源:DistributedHerderTest.java

示例8: testRestartConnectorRedirectToLeader

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRestartConnectorRedirectToLeader() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    // now handle the connector restart
    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick();
    FutureCallback<Void> callback = new FutureCallback<>();
    herder.restartConnector(CONN1, callback);
    herder.tick();

    try {
        callback.get(1000L, TimeUnit.MILLISECONDS);
        fail("Expected NotLeaderException to be raised");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotLeaderException);
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:34,代碼來源:DistributedHerderTest.java

示例9: testRestartUnknownTask

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRestartUnknownTask() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("member");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    FutureCallback<Void> callback = new FutureCallback<>();
    herder.tick();
    herder.restartTask(new ConnectorTaskId("blah", 0), callback);
    herder.tick();

    try {
        callback.get(1000L, TimeUnit.MILLISECONDS);
        fail("Expected NotLeaderException to be raised");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotFoundException);
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:33,代碼來源:DistributedHerderTest.java

示例10: testConnectorConfigAdded

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testConnectorConfigAdded() {
    // If a connector was added, we need to rebalance
    EasyMock.expect(member.memberId()).andStubReturn("member");

    // join, no configs so no need to catch up on config topic
    expectRebalance(-1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    // apply config
    member.wakeup();
    member.ensureActive();
    PowerMock.expectLastCall();
    // Checks for config updates and starts rebalance
    EasyMock.expect(configBackingStore.snapshot()).andReturn(SNAPSHOT);
    member.requestRejoin();
    PowerMock.expectLastCall();
    // Performs rebalance and gets new assignment
    expectRebalance(Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList(),
            ConnectProtocol.Assignment.NO_ERROR, 1, Arrays.asList(CONN1), Collections.<ConnectorTaskId>emptyList());
    worker.startConnector(EasyMock.eq(CONN1), EasyMock.<Map<String, String>>anyObject(), EasyMock.<ConnectorContext>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    EasyMock.expect(worker.getPlugins()).andReturn(plugins);
    EasyMock.expect(worker.isRunning(CONN1)).andReturn(true);
    EasyMock.expect(worker.connectorTaskConfigs(CONN1, MAX_TASKS, null)).andReturn(TASK_CONFIGS);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick(); // join
    configUpdateListener.onConnectorConfigUpdate(CONN1); // read updated config
    herder.tick(); // apply config
    herder.tick(); // do rebalance

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:40,代碼來源:DistributedHerderTest.java

示例11: testCommitSuccessFollowedByFailure

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testCommitSuccessFollowedByFailure() throws Exception {
    // Validate that we rewind to the correct offsets if a task's preCommit() method throws an exception

    expectInitializeTask();
    expectPollInitialAssignment();
    Capture<Collection<SinkRecord>> capturedRecords = expectPolls(WorkerConfig.OFFSET_COMMIT_INTERVAL_MS_DEFAULT);
    expectOffsetCommit(1L, null, null, 0, true);
    expectOffsetCommit(2L, new RuntimeException(), null, 0, true);
    // Should rewind to last known committed positions
    consumer.seek(TOPIC_PARTITION, FIRST_OFFSET + 1);
    PowerMock.expectLastCall();
    consumer.seek(TOPIC_PARTITION2, FIRST_OFFSET);
    PowerMock.expectLastCall();
    consumer.seek(TOPIC_PARTITION3, FIRST_OFFSET);
    PowerMock.expectLastCall();
    expectStopTask();

    PowerMock.replayAll();

    workerTask.initialize(TASK_CONFIG);
    workerTask.initializeAndStart();

    // Initialize partition assignment
    workerTask.iteration();
    // Fetch some data
    workerTask.iteration();
    // Trigger first commit,
    workerTask.iteration();
    // Trigger second (failing) commit
    workerTask.iteration();

    assertEquals(1, workerTask.commitFailures());
    assertEquals(false, Whitebox.getInternalState(workerTask, "committing"));
    workerTask.stop();
    workerTask.close();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:40,代碼來源:WorkerSinkTaskThreadedTest.java

示例12: expectStopTask

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
private void expectStopTask() throws Exception {
    sinkTask.stop();
    PowerMock.expectLastCall();

    // No offset commit since it happens in the mocked worker thread, but the main thread does need to wake up the
    // consumer so it exits quickly
    consumer.wakeup();
    PowerMock.expectLastCall();

    consumer.close();
    PowerMock.expectLastCall();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:13,代碼來源:WorkerSinkTaskThreadedTest.java

示例13: expectOffsetCommit

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
private Capture<OffsetCommitCallback> expectOffsetCommit(final long expectedMessages,
                                                         final RuntimeException error,
                                                         final Exception consumerCommitError,
                                                         final long consumerCommitDelayMs,
                                                         final boolean invokeCallback)
        throws Exception {
    final long finalOffset = FIRST_OFFSET + expectedMessages;

    // All assigned partitions will have offsets committed, but we've only processed messages/updated offsets for one
    final Map<TopicPartition, OffsetAndMetadata> offsetsToCommit = new HashMap<>();
    offsetsToCommit.put(TOPIC_PARTITION, new OffsetAndMetadata(finalOffset));
    offsetsToCommit.put(TOPIC_PARTITION2, new OffsetAndMetadata(FIRST_OFFSET));
    offsetsToCommit.put(TOPIC_PARTITION3, new OffsetAndMetadata(FIRST_OFFSET));
    sinkTask.preCommit(offsetsToCommit);
    IExpectationSetters<Object> expectation = PowerMock.expectLastCall();
    if (error != null) {
        expectation.andThrow(error).once();
        return null;
    } else {
        expectation.andReturn(offsetsToCommit);
    }

    final Capture<OffsetCommitCallback> capturedCallback = EasyMock.newCapture();
    consumer.commitAsync(EasyMock.eq(offsetsToCommit),
            EasyMock.capture(capturedCallback));
    PowerMock.expectLastCall().andAnswer(new IAnswer<Object>() {
        @Override
        public Object answer() throws Throwable {
            time.sleep(consumerCommitDelayMs);
            if (invokeCallback)
                capturedCallback.getValue().onComplete(offsetsToCommit, consumerCommitError);
            return null;
        }
    });
    return capturedCallback;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:37,代碼來源:WorkerSinkTaskThreadedTest.java

示例14: testUnknownConnectorPaused

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testUnknownConnectorPaused() throws Exception {
    EasyMock.expect(member.memberId()).andStubReturn("member");
    EasyMock.expect(worker.connectorNames()).andStubReturn(Collections.singleton(CONN1));

    // join
    expectRebalance(1, Collections.<String>emptyList(), singletonList(TASK0));
    expectPostRebalanceCatchup(SNAPSHOT);
    worker.startTask(EasyMock.eq(TASK0), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Map<String, String>>anyObject(),
            EasyMock.eq(herder), EasyMock.eq(TargetState.STARTED));
    PowerMock.expectLastCall().andReturn(true);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    // state change is ignored since we have no target state
    member.wakeup();
    member.ensureActive();
    PowerMock.expectLastCall();

    EasyMock.expect(configBackingStore.snapshot()).andReturn(SNAPSHOT);
    PowerMock.expectLastCall();

    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick(); // join
    configUpdateListener.onConnectorTargetStateChange("unknown-connector");
    herder.tick(); // continue

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:34,代碼來源:DistributedHerderTest.java

示例15: testRestartTaskRedirectToOwner

import org.powermock.api.easymock.PowerMock; //導入方法依賴的package包/類
@Test
public void testRestartTaskRedirectToOwner() throws Exception {
    // get the initial assignment
    EasyMock.expect(member.memberId()).andStubReturn("leader");
    expectRebalance(1, Collections.<String>emptyList(), Collections.<ConnectorTaskId>emptyList());
    expectPostRebalanceCatchup(SNAPSHOT);
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    // now handle the task restart
    String ownerUrl = "ownerUrl";
    EasyMock.expect(member.ownerUrl(TASK0)).andReturn(ownerUrl);
    member.wakeup();
    PowerMock.expectLastCall();
    member.ensureActive();
    PowerMock.expectLastCall();
    member.poll(EasyMock.anyInt());
    PowerMock.expectLastCall();

    PowerMock.replayAll();

    herder.tick();
    FutureCallback<Void> callback = new FutureCallback<>();
    herder.restartTask(TASK0, callback);
    herder.tick();

    try {
        callback.get(1000L, TimeUnit.MILLISECONDS);
        fail("Expected NotLeaderException to be raised");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof NotAssignedException);
        NotAssignedException notAssignedException = (NotAssignedException) e.getCause();
        assertEquals(ownerUrl, notAssignedException.forwardUrl());
    }

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:38,代碼來源:DistributedHerderTest.java


注:本文中的org.powermock.api.easymock.PowerMock.expectLastCall方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。