本文整理匯總了Java中org.easymock.EasyMock.mock方法的典型用法代碼示例。如果您正苦於以下問題:Java EasyMock.mock方法的具體用法?Java EasyMock.mock怎麽用?Java EasyMock.mock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.easymock.EasyMock
的用法示例。
在下文中一共展示了EasyMock.mock方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doNotBlockIfPollConditionIsSatisfied
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void doNotBlockIfPollConditionIsSatisfied() {
NetworkClient mockNetworkClient = EasyMock.mock(NetworkClient.class);
ConsumerNetworkClient consumerClient = new ConsumerNetworkClient(mockNetworkClient, metadata, time, 100, 1000);
// expect poll, but with no timeout
EasyMock.expect(mockNetworkClient.poll(EasyMock.eq(0L), EasyMock.anyLong())).andReturn(Collections.<ClientResponse>emptyList());
EasyMock.replay(mockNetworkClient);
consumerClient.poll(Long.MAX_VALUE, time.milliseconds(), new ConsumerNetworkClient.PollCondition() {
@Override
public boolean shouldBlock() {
return false;
}
});
EasyMock.verify(mockNetworkClient);
}
示例2: blockWhenPollConditionNotSatisfied
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void blockWhenPollConditionNotSatisfied() {
long timeout = 4000L;
NetworkClient mockNetworkClient = EasyMock.mock(NetworkClient.class);
ConsumerNetworkClient consumerClient = new ConsumerNetworkClient(mockNetworkClient, metadata, time, 100, 1000);
EasyMock.expect(mockNetworkClient.inFlightRequestCount()).andReturn(1);
EasyMock.expect(mockNetworkClient.poll(EasyMock.eq(timeout), EasyMock.anyLong())).andReturn(Collections.<ClientResponse>emptyList());
EasyMock.replay(mockNetworkClient);
consumerClient.poll(timeout, time.milliseconds(), new ConsumerNetworkClient.PollCondition() {
@Override
public boolean shouldBlock() {
return true;
}
});
EasyMock.verify(mockNetworkClient);
}
示例3: blockOnlyForRetryBackoffIfNoInflightRequests
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void blockOnlyForRetryBackoffIfNoInflightRequests() {
long retryBackoffMs = 100L;
NetworkClient mockNetworkClient = EasyMock.mock(NetworkClient.class);
ConsumerNetworkClient consumerClient = new ConsumerNetworkClient(mockNetworkClient, metadata, time, retryBackoffMs, 1000L);
EasyMock.expect(mockNetworkClient.inFlightRequestCount()).andReturn(0);
EasyMock.expect(mockNetworkClient.poll(EasyMock.eq(retryBackoffMs), EasyMock.anyLong())).andReturn(Collections.<ClientResponse>emptyList());
EasyMock.replay(mockNetworkClient);
consumerClient.poll(Long.MAX_VALUE, time.milliseconds(), new ConsumerNetworkClient.PollCondition() {
@Override
public boolean shouldBlock() {
return true;
}
});
EasyMock.verify(mockNetworkClient);
}
示例4: createBrokerFailureDetector
import org.easymock.EasyMock; //導入方法依賴的package包/類
private BrokerFailureDetector createBrokerFailureDetector(Queue<Anomaly> anomalies, Time time) {
LoadMonitor mockLoadMonitor = EasyMock.mock(LoadMonitor.class);
EasyMock.expect(mockLoadMonitor.brokersWithPartitions(anyLong())).andAnswer(() -> new HashSet<>(Arrays.asList(0, 1))).anyTimes();
EasyMock.replay(mockLoadMonitor);
Properties props = CruiseControlUnitTestUtils.getCruiseControlProperties();
props.setProperty(KafkaCruiseControlConfig.ZOOKEEPER_CONNECT_CONFIG, zookeeper().getConnectionString());
KafkaCruiseControlConfig kafkaCruiseControlConfig = new KafkaCruiseControlConfig(props);
return new BrokerFailureDetector(kafkaCruiseControlConfig,
mockLoadMonitor,
anomalies,
time);
}
示例5: AssertStackManipulationsAreSame
import org.easymock.EasyMock; //導入方法依賴的package包/類
/**
* Ctor.
*
* @param sm Stack manipulation to assert on.
* @param sm2 Stack manipulation to compare with
*/
public AssertStackManipulationsAreSame(StackManipulation sm, StackManipulation sm2) {
super(
sm,
mv -> {
Implementation.Context ctx = EasyMock.mock(Implementation.Context.class);
sm2.apply(mv, ctx);
}
);
}
示例6: generatesTests
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public final void generatesTests() throws Throwable {
FactoryRunner.TestConsumer tc = EasyMock.mock(MockType.STRICT, FactoryRunner.TestConsumer.class);
{
tc.accept("foo", new FooTest("foo"));
tc.accept("bar", new FooTest("bar"));
tc.accept("baz", new FooTest("baz"));
EasyMock.replay(tc);
}
{
final TestsSuite suite = new TestsSuite(
new TestCase(
"foo",
new AssertFoo()
),
new TestCase(
"bar",
new AssertFoo()
),
new TestCase(
"baz",
new AssertFoo()
)
);
suite.produceTests(tc);
EasyMock.verify(tc);
}
}
示例7: testDelayedCheck
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testDelayedCheck() throws InterruptedException, KafkaCruiseControlException {
LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
EasyMock.expect(mockAnomalyNotifier.onBrokerFailure(EasyMock.isA(BrokerFailures.class)))
.andReturn(AnomalyNotificationResult.check(1000L));
// Starting periodic goal violation detection.
EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
EasyMock.anyLong(),
EasyMock.eq(3000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
// Starting anomaly handler
EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
.andDelegateTo(executorService);
// Schedule a delayed check
EasyMock.expect(mockDetectorScheduler.schedule(EasyMock.isA(Runnable.class),
EasyMock.eq(1000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
mockDetectorScheduler.shutdown();
EasyMock.expectLastCall().andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);
// The following state are used to test the delayed check when executor is busy.
EasyMock.expect(mockKafkaCruiseControl.state())
.andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
EasyMock.replay(mockAnomalyNotifier);
EasyMock.replay(mockBrokerFailureDetector);
EasyMock.replay(mockGoalViolationDetector);
EasyMock.replay(mockDetectorScheduler);
EasyMock.replay(mockKafkaCruiseControl);
AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
mockGoalViolationDetector, mockBrokerFailureDetector,
mockDetectorScheduler);
try {
anomalyDetector.startDetection();
anomalies.add(new BrokerFailures(Collections.singletonMap(0, 100L)));
while (!anomalies.isEmpty()) {
// just wait for the anomalies to be drained.
}
anomalyDetector.shutdown();
assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
} finally {
executorService.shutdown();
}
}
示例8: testFix
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testFix() throws InterruptedException, KafkaCruiseControlException {
LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
EasyMock.expect(mockAnomalyNotifier.onGoalViolation(EasyMock.isA(GoalViolations.class)))
.andReturn(AnomalyNotificationResult.fix());
// Starting periodic goal violation detection.
EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
EasyMock.anyLong(),
EasyMock.eq(3000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
// Starting anomaly handler
EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
.andDelegateTo(executorService);
mockDetectorScheduler.shutdown();
EasyMock.expectLastCall().andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);
// The following state are used to test the delayed check when executor is busy.
EasyMock.expect(mockKafkaCruiseControl.state())
.andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
EasyMock.expect(mockKafkaCruiseControl.rebalance(Collections.emptyList(), false, null))
.andReturn(null);
EasyMock.replay(mockAnomalyNotifier);
EasyMock.replay(mockBrokerFailureDetector);
EasyMock.replay(mockGoalViolationDetector);
EasyMock.replay(mockDetectorScheduler);
EasyMock.replay(mockKafkaCruiseControl);
AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
mockGoalViolationDetector, mockBrokerFailureDetector,
mockDetectorScheduler);
try {
anomalyDetector.startDetection();
anomalies.add(new GoalViolations());
while (!anomalies.isEmpty()) {
// Just wait for the anomalies to be drained.
}
anomalyDetector.shutdown();
assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
} finally {
executorService.shutdown();
}
}
示例9: testExecutionInProgress
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testExecutionInProgress() throws InterruptedException, KafkaCruiseControlException {
LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
// Starting periodic goal violation detection.
EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
EasyMock.anyLong(),
EasyMock.eq(3000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
// Starting anomaly handler
EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
.andDelegateTo(executorService);
// For detector shutdown.
mockDetectorScheduler.shutdown();
EasyMock.expectLastCall().andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);
// The following state are used to test the delayed check when executor is busy.
EasyMock.expect(mockKafkaCruiseControl.state())
.andReturn(new KafkaCruiseControlState(
ExecutorState.replicaMovementInProgress(1, Collections.emptySet(), Collections.emptySet(),
1, 1),
null, null));
EasyMock.replay(mockAnomalyNotifier);
EasyMock.replay(mockBrokerFailureDetector);
EasyMock.replay(mockGoalViolationDetector);
EasyMock.replay(mockDetectorScheduler);
EasyMock.replay(mockKafkaCruiseControl);
AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
mockGoalViolationDetector, mockBrokerFailureDetector,
mockDetectorScheduler);
try {
anomalyDetector.startDetection();
anomalies.add(new GoalViolations());
while (!anomalies.isEmpty()) {
// Just wait for the anomalies to be drained.
}
anomalyDetector.shutdown();
assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
} finally {
executorService.shutdown();
}
}
示例10: prepareContext
import org.easymock.EasyMock; //導入方法依賴的package包/類
private TestContext prepareContext() {
// Create mock metadata client.
Metadata metadata = getMetadata(Arrays.asList(T0P0, T0P1, T1P0, T1P1));
MetadataClient mockMetadataClient = EasyMock.mock(MetadataClient.class);
EasyMock.expect(mockMetadataClient.cluster())
.andReturn(metadata.fetch())
.anyTimes();
EasyMock.expect(mockMetadataClient.clusterAndGeneration())
.andReturn(new MetadataClient.ClusterAndGeneration(metadata.fetch(), 0))
.anyTimes();
EasyMock.expect(mockMetadataClient.metadata()).andReturn(metadata).anyTimes();
EasyMock.expect(mockMetadataClient.refreshMetadata())
.andReturn(new MetadataClient.ClusterAndGeneration(metadata.fetch(), 0))
.anyTimes();
EasyMock.expect(mockMetadataClient.refreshMetadata(anyLong()))
.andReturn(new MetadataClient.ClusterAndGeneration(metadata.fetch(), 0))
.anyTimes();
EasyMock.replay(mockMetadataClient);
// create load monitor.
Properties props = CruiseControlUnitTestUtils.getCruiseControlProperties();
props.put(KafkaCruiseControlConfig.NUM_LOAD_SNAPSHOTS_CONFIG, Integer.toString(NUM_SNAPSHOT_WINDOWS));
props.put(KafkaCruiseControlConfig.MIN_SAMPLES_PER_LOAD_SNAPSHOT_CONFIG,
Integer.toString(MIN_SAMPLES_PER_SNAPSHOT_WINDOW));
props.put(KafkaCruiseControlConfig.LOAD_SNAPSHOT_WINDOW_MS_CONFIG, Long.toString(SNAPSHOT_WINDOW_MS));
props.put("cleanup.policy", DEFAULT_CLEANUP_POLICY);
props.put(KafkaCruiseControlConfig.SAMPLE_STORE_CLASS_CONFIG, NoopSampleStore.class.getName());
KafkaCruiseControlConfig config = new KafkaCruiseControlConfig(props);
LoadMonitor loadMonitor = new LoadMonitor(config, mockMetadataClient, _time, new MetricRegistry());
MetricSampleAggregator aggregator = loadMonitor.aggregator();
MetricCompletenessChecker checker = loadMonitor.completenessChecker();
if (!Load.initialized()) {
Load.init(config);
}
ModelParameters.init(config);
loadMonitor.startUp();
while (loadMonitor.state().state() != LoadMonitorTaskRunner.LoadMonitorTaskRunnerState.RUNNING) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// let it go.
}
}
return new TestContext(loadMonitor, aggregator, checker, config, metadata);
}