本文整理汇总了Java中org.easymock.EasyMock.expectLastCall方法的典型用法代码示例。如果您正苦于以下问题:Java EasyMock.expectLastCall方法的具体用法?Java EasyMock.expectLastCall怎么用?Java EasyMock.expectLastCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.easymock.EasyMock
的用法示例。
在下文中一共展示了EasyMock.expectLastCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJoinLeaderCatchUpFails
import org.easymock.EasyMock; //导入方法依赖的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();
}
示例2: expectRebalanceAssignmentError
import org.easymock.EasyMock; //导入方法依赖的package包/类
private void expectRebalanceAssignmentError(RuntimeException e) {
final List<TopicPartition> partitions = asList(TOPIC_PARTITION, TOPIC_PARTITION2);
sinkTask.close(new HashSet<>(partitions));
EasyMock.expectLastCall();
sinkTask.preCommit(EasyMock.<Map<TopicPartition, OffsetAndMetadata>>anyObject());
EasyMock.expectLastCall().andReturn(Collections.emptyMap());
EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);
sinkTask.open(partitions);
EasyMock.expectLastCall().andThrow(e);
EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(
new IAnswer<ConsumerRecords<byte[], byte[]>>() {
@Override
public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
rebalanceListener.getValue().onPartitionsRevoked(partitions);
rebalanceListener.getValue().onPartitionsAssigned(partitions);
return ConsumerRecords.empty();
}
});
}
示例3: expectOffsetFlush
import org.easymock.EasyMock; //导入方法依赖的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();
}
}
示例4: testCreateAndStop
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testCreateAndStop() throws Exception {
connector = PowerMock.createMock(BogusSourceConnector.class);
expectAdd(SourceSink.SOURCE);
Map<String, String> connectorConfig = connectorConfig(SourceSink.SOURCE);
expectConfigValidation(connectorConfig);
// herder.stop() should stop any running connectors and tasks even if destroyConnector was not invoked
expectStop();
statusBackingStore.stop();
EasyMock.expectLastCall();
worker.stop();
EasyMock.expectLastCall();
PowerMock.replayAll();
herder.putConnectorConfig(CONNECTOR_NAME, connectorConfig, false, createCallback);
herder.stop();
PowerMock.verifyAll();
}
示例5: expectPollInitialAssignment
import org.easymock.EasyMock; //导入方法依赖的package包/类
private void expectPollInitialAssignment() {
final List<TopicPartition> partitions = asList(TOPIC_PARTITION, TOPIC_PARTITION2);
sinkTask.open(partitions);
EasyMock.expectLastCall();
EasyMock.expect(consumer.poll(EasyMock.anyLong())).andAnswer(new IAnswer<ConsumerRecords<byte[], byte[]>>() {
@Override
public ConsumerRecords<byte[], byte[]> answer() throws Throwable {
rebalanceListener.getValue().onPartitionsAssigned(partitions);
return ConsumerRecords.empty();
}
});
EasyMock.expect(consumer.position(TOPIC_PARTITION)).andReturn(FIRST_OFFSET);
EasyMock.expect(consumer.position(TOPIC_PARTITION2)).andReturn(FIRST_OFFSET);
sinkTask.put(Collections.<SinkRecord>emptyList());
EasyMock.expectLastCall();
}
示例6: prepareForInstallTest
import org.easymock.EasyMock; //导入方法依赖的package包/类
private Capture<OFFlowMod> prepareForInstallTest() {
Capture<OFFlowMod> capture = EasyMock.newCapture();
expect(ofSwitchService.getSwitch(dpid)).andStubReturn(iofSwitch);
expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
expect(iofSwitch.getSwitchDescription()).andStubReturn(switchDescription);
expect(switchDescription.getManufacturerDescription()).andStubReturn("");
expect(iofSwitch.write(capture(capture))).andReturn(true);
EasyMock.expectLastCall();
replay(ofSwitchService);
replay(iofSwitch);
replay(switchDescription);
return capture;
}
示例7: stopBeforeStarting
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void stopBeforeStarting() {
ConnectorTaskId taskId = new ConnectorTaskId("foo", 0);
TaskStatus.Listener statusListener = EasyMock.createMock(TaskStatus.Listener.class);
ClassLoader loader = EasyMock.createMock(ClassLoader.class);
WorkerTask workerTask = partialMockBuilder(WorkerTask.class)
.withConstructor(
ConnectorTaskId.class,
TaskStatus.Listener.class,
TargetState.class,
ClassLoader.class
)
.withArgs(taskId, statusListener, TargetState.STARTED, loader)
.addMockedMethod("initialize")
.addMockedMethod("execute")
.addMockedMethod("close")
.createStrictMock();
workerTask.initialize(TASK_CONFIG);
EasyMock.expectLastCall();
workerTask.close();
EasyMock.expectLastCall();
replay(workerTask);
workerTask.initialize(TASK_CONFIG);
workerTask.stop();
workerTask.awaitStop(1000L);
// now run should not do anything
workerTask.run();
verify(workerTask);
}
示例8: testStartTaskFailure
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testStartTaskFailure() throws Exception {
expectConverters();
expectStartStorage();
Map<String, String> origProps = new HashMap<>();
origProps.put(TaskConfig.TASK_CLASS_CONFIG, "missing.From.This.Workers.Classpath");
EasyMock.expect(plugins.currentThreadLoader()).andReturn(delegatingLoader);
EasyMock.expect(plugins.delegatingLoader()).andReturn(delegatingLoader);
EasyMock.expect(delegatingLoader.connectorLoader(WorkerTestConnector.class.getName()))
.andReturn(pluginLoader);
// We would normally expect this since the plugin loader would have been swapped in. However, since we mock out
// all classloader changes, the call actually goes to the normal default classloader. However, this works out
// fine since we just wanted a ClassNotFoundException anyway.
// EasyMock.expect(pluginLoader.loadClass(origProps.get(TaskConfig.TASK_CLASS_CONFIG)))
// .andThrow(new ClassNotFoundException());
EasyMock.expect(Plugins.compareAndSwapLoaders(pluginLoader))
.andReturn(delegatingLoader);
EasyMock.expect(Plugins.compareAndSwapLoaders(delegatingLoader))
.andReturn(pluginLoader);
taskStatusListener.onFailure(EasyMock.eq(TASK_ID), EasyMock.<ConfigException>anyObject());
EasyMock.expectLastCall();
PowerMock.replayAll();
worker = new Worker(WORKER_ID, new MockTime(), plugins, config, offsetBackingStore);
worker.start();
assertFalse(worker.startTask(TASK_ID, anyConnectorConfigMap(), origProps, taskStatusListener, TargetState.STARTED));
assertEquals(Collections.emptySet(), worker.taskIds());
PowerMock.verifyAll();
}
示例9: expectPostRebalanceCatchup
import org.easymock.EasyMock; //导入方法依赖的package包/类
private void expectPostRebalanceCatchup(final ClusterConfigState readToEndSnapshot) throws TimeoutException {
configBackingStore.refresh(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
EasyMock.expect(configBackingStore.snapshot()).andReturn(readToEndSnapshot);
}
示例10: testPause
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testPause() throws Exception {
createWorkerTask();
sourceTask.initialize(EasyMock.anyObject(SourceTaskContext.class));
EasyMock.expectLastCall();
sourceTask.start(TASK_PROPS);
EasyMock.expectLastCall();
statusListener.onStartup(taskId);
EasyMock.expectLastCall();
AtomicInteger count = new AtomicInteger(0);
CountDownLatch pollLatch = expectPolls(10, count);
// In this test, we don't flush, so nothing goes any further than the offset writer
statusListener.onPause(taskId);
EasyMock.expectLastCall();
sourceTask.stop();
EasyMock.expectLastCall();
expectOffsetFlush(true);
statusListener.onShutdown(taskId);
EasyMock.expectLastCall();
producer.close(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
transformationChain.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
Future<?> taskFuture = executor.submit(workerTask);
assertTrue(awaitLatch(pollLatch));
workerTask.transitionTo(TargetState.PAUSED);
int priorCount = count.get();
Thread.sleep(100);
// since the transition is observed asynchronously, the count could be off by one loop iteration
assertTrue(count.get() - priorCount <= 1);
workerTask.stop();
assertTrue(workerTask.awaitStop(1000));
taskFuture.get();
PowerMock.verifyAll();
}
示例11: testFailureInPoll
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testFailureInPoll() throws Exception {
createWorkerTask();
sourceTask.initialize(EasyMock.anyObject(SourceTaskContext.class));
EasyMock.expectLastCall();
sourceTask.start(TASK_PROPS);
EasyMock.expectLastCall();
statusListener.onStartup(taskId);
EasyMock.expectLastCall();
final CountDownLatch pollLatch = new CountDownLatch(1);
final RuntimeException exception = new RuntimeException();
EasyMock.expect(sourceTask.poll()).andAnswer(new IAnswer<List<SourceRecord>>() {
@Override
public List<SourceRecord> answer() throws Throwable {
pollLatch.countDown();
throw exception;
}
});
statusListener.onFailure(taskId, exception);
EasyMock.expectLastCall();
sourceTask.stop();
EasyMock.expectLastCall();
expectOffsetFlush(true);
producer.close(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
transformationChain.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
Future<?> taskFuture = executor.submit(workerTask);
assertTrue(awaitLatch(pollLatch));
workerTask.stop();
assertTrue(workerTask.awaitStop(1000));
taskFuture.get();
PowerMock.verifyAll();
}
示例12: testCommit
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testCommit() throws Exception {
// Test that the task commits properly when prompted
createWorkerTask();
sourceTask.initialize(EasyMock.anyObject(SourceTaskContext.class));
EasyMock.expectLastCall();
sourceTask.start(TASK_PROPS);
EasyMock.expectLastCall();
statusListener.onStartup(taskId);
EasyMock.expectLastCall();
// We'll wait for some data, then trigger a flush
final CountDownLatch pollLatch = expectPolls(1);
expectOffsetFlush(true);
sourceTask.stop();
EasyMock.expectLastCall();
expectOffsetFlush(true);
statusListener.onShutdown(taskId);
EasyMock.expectLastCall();
producer.close(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
transformationChain.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
Future<?> taskFuture = executor.submit(workerTask);
assertTrue(awaitLatch(pollLatch));
assertTrue(workerTask.commitOffsets());
workerTask.stop();
assertTrue(workerTask.awaitStop(1000));
taskFuture.get();
PowerMock.verifyAll();
}
示例13: testCommitFailure
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testCommitFailure() throws Exception {
// Test that the task commits properly when prompted
createWorkerTask();
sourceTask.initialize(EasyMock.anyObject(SourceTaskContext.class));
EasyMock.expectLastCall();
sourceTask.start(TASK_PROPS);
EasyMock.expectLastCall();
statusListener.onStartup(taskId);
EasyMock.expectLastCall();
// We'll wait for some data, then trigger a flush
final CountDownLatch pollLatch = expectPolls(1);
expectOffsetFlush(true);
sourceTask.stop();
EasyMock.expectLastCall();
expectOffsetFlush(false);
statusListener.onShutdown(taskId);
EasyMock.expectLastCall();
producer.close(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
transformationChain.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
Future<?> taskFuture = executor.submit(workerTask);
assertTrue(awaitLatch(pollLatch));
assertTrue(workerTask.commitOffsets());
workerTask.stop();
assertTrue(workerTask.awaitStop(1000));
taskFuture.get();
PowerMock.verifyAll();
}
示例14: testSlowTaskStart
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testSlowTaskStart() throws Exception {
final CountDownLatch startupLatch = new CountDownLatch(1);
final CountDownLatch finishStartupLatch = new CountDownLatch(1);
createWorkerTask();
sourceTask.initialize(EasyMock.anyObject(SourceTaskContext.class));
EasyMock.expectLastCall();
sourceTask.start(TASK_PROPS);
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
startupLatch.countDown();
assertTrue(awaitLatch(finishStartupLatch));
return null;
}
});
statusListener.onStartup(taskId);
EasyMock.expectLastCall();
sourceTask.stop();
EasyMock.expectLastCall();
expectOffsetFlush(true);
statusListener.onShutdown(taskId);
EasyMock.expectLastCall();
producer.close(EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class));
EasyMock.expectLastCall();
transformationChain.close();
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
Future<?> workerTaskFuture = executor.submit(workerTask);
// Stopping immediately while the other thread has work to do should result in no polling, no offset commits,
// exiting the work thread immediately, and the stop() method will be invoked in the background thread since it
// cannot be invoked immediately in the thread trying to stop the task.
assertTrue(awaitLatch(startupLatch));
workerTask.stop();
finishStartupLatch.countDown();
assertTrue(workerTask.awaitStop(1000));
workerTaskFuture.get();
PowerMock.verifyAll();
}
示例15: testPause
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testPause() throws Exception {
expectInitializeTask();
expectPollInitialAssignment();
expectConsumerPoll(1);
expectConversionAndTransformation(1);
sinkTask.put(EasyMock.<Collection<SinkRecord>>anyObject());
EasyMock.expectLastCall();
Set<TopicPartition> partitions = new HashSet<>(asList(TOPIC_PARTITION, TOPIC_PARTITION2));
// Pause
statusListener.onPause(taskId);
EasyMock.expectLastCall();
expectConsumerWakeup();
EasyMock.expect(consumer.assignment()).andReturn(partitions);
consumer.pause(partitions);
PowerMock.expectLastCall();
// Offset commit as requested when pausing; No records returned by consumer.poll()
sinkTask.preCommit(EasyMock.<Map<TopicPartition, OffsetAndMetadata>>anyObject());
EasyMock.expectLastCall().andStubReturn(Collections.emptyMap());
expectConsumerPoll(0);
sinkTask.put(Collections.<SinkRecord>emptyList());
EasyMock.expectLastCall();
// And unpause
statusListener.onResume(taskId);
EasyMock.expectLastCall();
expectConsumerWakeup();
EasyMock.expect(consumer.assignment()).andReturn(new HashSet<>(asList(TOPIC_PARTITION, TOPIC_PARTITION2)));
consumer.resume(singleton(TOPIC_PARTITION));
PowerMock.expectLastCall();
consumer.resume(singleton(TOPIC_PARTITION2));
PowerMock.expectLastCall();
expectConsumerPoll(1);
expectConversionAndTransformation(1);
sinkTask.put(EasyMock.<Collection<SinkRecord>>anyObject());
EasyMock.expectLastCall();
PowerMock.replayAll();
workerTask.initialize(TASK_CONFIG);
workerTask.initializeAndStart();
workerTask.iteration(); // initial assignment
workerTask.iteration(); // fetch some data
workerTask.transitionTo(TargetState.PAUSED);
workerTask.iteration(); // wakeup
workerTask.iteration(); // now paused
workerTask.transitionTo(TargetState.STARTED);
workerTask.iteration(); // wakeup
workerTask.iteration(); // now unpaused
PowerMock.verifyAll();
}