本文整理了Java中org.easymock.EasyMock.expect()
方法的一些代码示例,展示了EasyMock.expect()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.expect()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:expect
[英]Returns the expectation setter for the last expected invocation in the current thread.
[中]返回当前线程中最后一次预期调用的预期设置程序。
代码示例来源:origin: apache/incubator-druid
@Test
public void testHasNext()
{
boolean expected = true;
EasyMock.expect(peekIterator.hasNext()).andReturn(expected);
EasyMock.replay(peekIterator);
boolean actual = testingIterator.hasNext();
EasyMock.verify(peekIterator);
Assert.assertEquals("The hasNext function is broken", expected, actual);
}
代码示例来源:origin: apache/incubator-druid
private static LoadQueuePeon createLoadingPeon(List<DataSegment> segments)
{
final Set<DataSegment> segs = ImmutableSet.copyOf(segments);
final long loadingSize = segs.stream().mapToLong(DataSegment::getSize).sum();
final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(segs).anyTimes();
EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(loadingSize).anyTimes();
EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(segs.size()).anyTimes();
return mockPeon;
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test(expected = Error.class)
public void testWhenComputableThrowsError() throws Exception {
final Integer input = 1;
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
final Error error = new Error();
expect(computable.compute(input)).andThrow(error);
replay(computable);
memoizer.compute(input);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testStartAlreadyStarted()
{
EasyMock.expect(metadataSupervisorManager.getLatest()).andReturn(ImmutableMap.of());
replayAll();
exception.expect(IllegalStateException.class);
manager.start();
manager.start();
}
代码示例来源:origin: apache/incubator-druid
private void mockCoordinator()
{
EasyMock.expect(coordinator.getDynamicConfigs()).andReturn(createCoordinatorDynamicConfig()).anyTimes();
coordinator.removeSegment(EasyMock.anyObject());
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(coordinator);
}
代码示例来源:origin: apache/incubator-druid
@Before
public void setUp()
{
mapper.registerSubtypes(SomeBeanClass.class);
req = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(req.getContentType()).andReturn(MediaType.APPLICATION_JSON).anyTimes();
EasyMock.replay(req);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testRewriteURI()
{
DruidLeaderClient druidLeaderClient = EasyMock.createMock(DruidLeaderClient.class);
EasyMock.expect(druidLeaderClient.findCurrentLeader()).andReturn("https://overlord:port");
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
EasyMock.expect(request.getQueryString()).andReturn("param1=test¶m2=test2").anyTimes();
// %3A is a colon; test to make sure urlencoded paths work right.
EasyMock.expect(request.getRequestURI()).andReturn("/druid/over%3Alord/worker").anyTimes();
EasyMock.replay(druidLeaderClient, request);
URI uri = URI.create(new OverlordProxyServlet(druidLeaderClient, null, null).rewriteTarget(request));
Assert.assertEquals("https://overlord:port/druid/over%3Alord/worker?param1=test¶m2=test2", uri.toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test(expected = RuntimeException.class)
public void testWhenComputableThrowsRuntimeException() throws Exception {
final Integer input = 1;
final Memoizer<Integer, Integer> memoizer = new Memoizer<>(computable);
final RuntimeException runtimeException = new RuntimeException("Some runtime exception");
expect(computable.compute(input)).andThrow(runtimeException);
replay(computable);
memoizer.compute(input);
}
代码示例来源:origin: apache/incubator-druid
private static LoadQueuePeon createEmptyPeon()
{
final LoadQueuePeon mockPeon = EasyMock.createMock(LoadQueuePeon.class);
EasyMock.expect(mockPeon.getSegmentsToLoad()).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(mockPeon.getSegmentsMarkedToDrop()).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(mockPeon.getLoadQueueSize()).andReturn(0L).anyTimes();
EasyMock.expect(mockPeon.getNumberOfSegmentsInQueue()).andReturn(0).anyTimes();
return mockPeon;
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetEmitter()
{
ComposingEmitterConfig config = EasyMock.createMock(ComposingEmitterConfig.class);
EasyMock.expect(config.getEmitters()).andReturn(Collections.singletonList(testEmitterType)).anyTimes();
Injector injector = EasyMock.createMock(Injector.class);
EasyMock.expect(injector.getInstance(Key.get(Emitter.class, Names.named(testEmitterType)))).andReturn(emitter);
EasyMock.replay(config, injector);
Emitter composingEmitter = new ComposingEmitterModule().getEmitter(config, injector);
composingEmitter.start();
EasyMock.verify(config, emitter, injector);
}
代码示例来源:origin: apache/incubator-druid
private static ShardSpec shardSpec(String dimension, boolean contained)
{
ShardSpec shard = EasyMock.createMock(ShardSpec.class);
EasyMock.expect(shard.getDomainDimensions())
.andReturn(ImmutableList.of(dimension))
.anyTimes();
EasyMock.expect(shard.possibleInDomain(EasyMock.anyObject()))
.andReturn(contained)
.anyTimes();
return shard;
}
}
代码示例来源:origin: apache/incubator-druid
@Test(expected = NoSuchElementException.class)
public void testExceptionInNext()
{
boolean expected = false;
EasyMock.expect(peekIterator.hasNext()).andReturn(expected);
EasyMock.replay(peekIterator);
testingIterator.next();
EasyMock.verify(peekIterator);
}
代码示例来源:origin: apache/incubator-druid
@Before
public void setUp()
{
tierSelectorStrategy = EasyMock.createMock(TierSelectorStrategy.class);
expect(tierSelectorStrategy.getComparator()).andReturn(Integer::compare).anyTimes();
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testShutdownAllTasksForNonExistingDataSource()
{
final TaskQueue taskQueue = EasyMock.createMock(TaskQueue.class);
EasyMock.expect(taskMaster.isLeader()).andReturn(true).anyTimes();
EasyMock.expect(taskMaster.getTaskQueue()).andReturn(Optional.of(taskQueue)).anyTimes();
EasyMock.expect(taskStorageQueryAdapter.getActiveTaskInfo(EasyMock.anyString())).andReturn(Collections.emptyList());
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req);
final Response response = overlordResource.shutdownTasksForDataSource("notExisting");
Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetRedirectURL()
{
String query = "foo=bar&x=y";
String request = "/request";
EasyMock.expect(druidCoordinator.getCurrentLeader()).andReturn("http://localhost").anyTimes();
EasyMock.replay(druidCoordinator);
URL url = coordinatorRedirectInfo.getRedirectURL(query, request);
Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString());
EasyMock.verify(druidCoordinator);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testGetRedirectURL()
{
String host = "http://localhost";
String query = "foo=bar&x=y";
String request = "/request";
EasyMock.expect(taskMaster.getCurrentLeader()).andReturn(host).anyTimes();
EasyMock.replay(taskMaster);
URL url = redirectInfo.getRedirectURL(query, request);
Assert.assertEquals("http://localhost/request?foo=bar&x=y", url.toString());
EasyMock.verify(taskMaster);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testDatasourcesResourcesFilteringBadPath()
{
final String badRequestPath = WORD.matcher(requestPath).replaceAll("droid");
EasyMock.expect(request.getPath()).andReturn(badRequestPath).anyTimes();
EasyMock.replay(req, request, authorizerMapper);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNotImplementedIntrospectLookup()
{
EasyMock.expect(lookupExtractorFactory.getIntrospectHandler()).andReturn(null);
EasyMock.expect(lookupExtractorFactory.get()).andReturn(new MapLookupExtractor(ImmutableMap.of(), false)).anyTimes();
EasyMock.replay(lookupExtractorFactory);
Assert.assertEquals(Response.status(Response.Status.NOT_FOUND).build().getStatus(), ((Response) lookupIntrospectionResource.introspectLookup("lookupId")).getStatus());
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests createIfAbsent() if the map does not contain the key in question.
*
* @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
*/
@Test
public void testCreateIfAbsentKeyNotPresent() throws ConcurrentException {
@SuppressWarnings("unchecked")
final
ConcurrentInitializer<Integer> init = EasyMock
.createMock(ConcurrentInitializer.class);
final String key = "testKey";
final Integer value = 42;
EasyMock.expect(init.get()).andReturn(value);
EasyMock.replay(init);
final ConcurrentMap<String, Integer> map = new ConcurrentHashMap<>();
assertEquals("Wrong result", value,
ConcurrentUtils.createIfAbsent(map, key, init));
assertEquals("Wrong value in map", value, map.get(key));
EasyMock.verify(init);
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testLeader()
{
EasyMock.expect(taskMaster.getCurrentLeader()).andReturn("boz").once();
EasyMock.replay(taskRunner, taskMaster, taskStorageQueryAdapter, indexerMetadataStorageAdapter, req);
final Response response = overlordResource.getLeader();
Assert.assertEquals("boz", response.getEntity());
Assert.assertEquals(200, response.getStatus());
}
内容来源于网络,如有侵权,请联系作者删除!