@Test public void testChunking() { Query query = queryBuilder.intervals("2015-01-01T00:00:00.000/2015-01-11T00:00:00.000").context(ImmutableMap.of("chunkPeriod", "P1D")).build(); executors.execute(EasyMock.anyObject(Runnable.class)); EasyMock.expectLastCall().times(10); EasyMock.replay(executors); EasyMock.replay(toolChest); QueryRunner runner = decorator.decorate(baseRunner, toolChest); runner.run(QueryPlus.wrap(query), Collections.EMPTY_MAP); EasyMock.verify(executors); }
@Before public void setUp() { resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class); EasyMock.replay(resourceFactory); pool = new ResourcePool<String, String>( resourceFactory, new ResourcePoolConfig(2, TimeUnit.MINUTES.toMillis(4)) ); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); }
@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); }
/** * If "full" is specified, then dimensions/metrics that exist in an incompelte segment should be ingored */ @Test public void testGetDatasourceFullWithIncompleteSegment() { Map<String, Object> actual = resource.getDatasource(dataSource, "2015-04-03/2015-04-05", "true"); Map<String, Object> expected = ImmutableMap.of(); EasyMock.verify(serverInventoryView, timelineServerView); Assert.assertEquals(expected, actual); }
@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); }
@Test public void testMissingProducerSequence() throws IOException { setUpRequestExpectations("producer", null); final InputStream inputStream = IOUtils.toInputStream(inputRow, StandardCharsets.UTF_8); final Response response = firehose.addAll(inputStream, req); Assert.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); inputStream.close(); EasyMock.verify(req); firehose.close(); }
/** * Tests a successful initializeUnchecked() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitializeUnchecked() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initializeUnchecked(init)); EasyMock.verify(init); }
/** * Tests a successful initialize() operation. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testInitialize() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Object> init = EasyMock .createMock(ConcurrentInitializer.class); final Object result = new Object(); EasyMock.expect(init.get()).andReturn(result); EasyMock.replay(init); assertSame("Wrong result object", result, ConcurrentUtils .initialize(init)); EasyMock.verify(init); }
@Test public void testFalseBranchNext() { boolean expected = true; EasyMock.expect(peekIterator.hasNext()).andReturn(expected); expected = false; EasyMock.expect(peekIterator.hasNext()).andReturn(expected); EasyMock.replay(peekIterator); Object res = testingIterator.next(); EasyMock.verify(peekIterator); Assert.assertNull("Should be null", res); }
@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); } }
/** * Tests whether the thread name is not modified if no naming pattern is * set. */ @Test public void testNewThreadNoNamingPattern() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final String name = "unchangedThreadName"; final Thread t = new Thread(name); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Name was changed", name, t.getName()); EasyMock.verify(wrapped, r); }
/** * Tests whether the original priority is not changed if no priority is * specified. */ @Test public void testNewThreadNoPriority() { final ThreadFactory wrapped = EasyMock.createMock(ThreadFactory.class); final Runnable r = EasyMock.createMock(Runnable.class); final int orgPriority = Thread.NORM_PRIORITY + 1; final Thread t = new Thread(); t.setPriority(orgPriority); EasyMock.expect(wrapped.newThread(r)).andReturn(t); EasyMock.replay(wrapped, r); final BasicThreadFactory factory = builder.wrappedFactory(wrapped).build(); assertSame("Wrong thread", t, factory.newThread(r)); assertEquals("Wrong priority", orgPriority, t.getPriority()); EasyMock.verify(wrapped, r); }
/** * Tests createIfAbsent() if a null map is passed in. * * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it */ @Test public void testCreateIfAbsentNullMap() throws ConcurrentException { @SuppressWarnings("unchecked") final ConcurrentInitializer<Integer> init = EasyMock .createMock(ConcurrentInitializer.class); EasyMock.replay(init); assertNull("Wrong result", ConcurrentUtils.createIfAbsent(null, "test", init)); EasyMock.verify(init); }
@Test public void testGetMethod() throws Exception { MethodInvocation mock = createMock(MethodInvocation.class); Method method = AopAllianceMethodInvocationAdapterTest.class.getMethod("testGetMethod"); expect(mock.getMethod()).andReturn(method); AopAllianceMethodInvocationAdapter underTest = new AopAllianceMethodInvocationAdapter(mock); replay(mock); assertSame(method, underTest.getMethod()); verify(mock); }