@Test public void shouldFlushWriterWhenOutputtingLongMessage() { // Given: mockPrintWriter.flush(); EasyMock.expectLastCall(); EasyMock.replay(mockPrintWriter); // When: WelcomeMsgUtils.displayWelcomeMessage(80, mockPrintWriter); // Then: EasyMock.verify(mockPrintWriter); }
private void expectAuthorizationTokenCheck() { AuthenticationResult authenticationResult = new AuthenticationResult("druid", "druid", null, null); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).atLeastOnce(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(authenticationResult) .atLeastOnce(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, false); EasyMock.expectLastCall().anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); }
/** * Prepares an executor service mock to expect the start of the timer. * * @param service the mock * @param future the future */ private void prepareStartTimer(final ScheduledExecutorService service, final ScheduledFuture<?> future) { service.scheduleAtFixedRate((Runnable) EasyMock.anyObject(), EasyMock .eq(PERIOD), EasyMock.eq(PERIOD), EasyMock.eq(UNIT)); EasyMock.expectLastCall().andReturn(future); }
@Test(expected = KsqlRestClientException.class) public void shouldThrowIfRestClientThrowsOnSet() { restClient.setServerAddress("localhost:8088"); expectLastCall().andThrow(new KsqlRestClientException("Boom")); replay(restClient); command.execute(ImmutableList.of("localhost:8088"), terminal); }
private void replayOnSubscribe() { subscription.request(1); EasyMock.expectLastCall().once(); EasyMock.replay(subscription); subscriber.onSubscribe(subscription); EasyMock.verify(subscription); EasyMock.reset(subscription); }
private void mockCoordinator(DruidCoordinator coordinator) { coordinator.moveSegment( EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject() ); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(coordinator); }
@Test public void shouldFlushWriterWhenOutputtingShortMessage() { // Given: mockPrintWriter.flush(); EasyMock.expectLastCall(); EasyMock.replay(mockPrintWriter); // When: WelcomeMsgUtils.displayWelcomeMessage(10, mockPrintWriter); // Then: EasyMock.verify(mockPrintWriter); } }
@Test public void shouldReturnServiceUnavailableIfTimeoutWaitingForCommandSequenceNumber() throws Exception { // Given: commandQueue.ensureConsumedPast(anyLong(), anyObject()); expectLastCall().andThrow(new TimeoutException("whoops")); replay(commandQueue); // Expect expectedException.expect(KsqlRestException.class); expectedException.expect(exceptionStatusCode(is(Code.SERVICE_UNAVAILABLE))); expectedException.expect(exceptionKsqlErrorMessage(errorMessage(is("whoops")))); expectedException.expect( exceptionKsqlErrorMessage(errorCode(is(Errors.ERROR_CODE_COMMAND_QUEUE_CATCHUP_TIMEOUT)))); // When: testResource.streamQuery(new KsqlRequest(queryString, Collections.emptyMap(), 3L)); }
private void setUpRequestExpectations(String producerId, String producerSequenceValue) { EasyMock.reset(req); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT) .anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.expect(req.getContentType()).andReturn("application/json"); EasyMock.expect(req.getHeader("X-Firehose-Producer-Id")).andReturn(producerId); if (producerId != null) { EasyMock.expect(req.getHeader("X-Firehose-Producer-Seq")).andReturn(producerSequenceValue); } EasyMock.replay(req); } }
@Test public void shouldStopAppOnJoin() throws Exception { // Given: executable.stop(); expectLastCall(); replay(executable); // When: main.tryStartApp(); // Then: verify(executable); }
@Test public void testGoodQuery() throws IOException { EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(testServletRequest.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(authenticationResult) .anyTimes(); testServletRequest.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(testServletRequest); Response response = queryResource.doPost( new ByteArrayInputStream(simpleTimeSeriesQuery.getBytes("UTF-8")), null /*pretty*/, testServletRequest ); Assert.assertNotNull(response); }
@Test public void shouldRestClientServerAddressWhenNonEmptyStringArg() { expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO)); restClient.setServerAddress(VALID_SERVER_ADDRESS); expectLastCall(); replay(restClient); command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal); verify(restClient); }
@Test public void shouldCreateCommandTopicIfItDoesNotExist() { topicClient.createTopic(COMMAND_TOPIC, 1, (short) 1, commandTopicConfig); EasyMock.expectLastCall(); EasyMock.replay(topicClient); KsqlRestApplication.ensureCommandTopic(restConfig, topicClient, COMMAND_TOPIC); EasyMock.verify(topicClient); }
@Test(timeout = 60_000L) public void testShutdownWithPrevTime() throws Exception { EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT) .anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(req); firehose.shutdown(DateTimes.nowUtc().minusMinutes(2).toString(), req); while (!firehose.isClosed()) { Thread.sleep(50); } }
@Test(timeout = 60_000L) public void testShutdown() throws Exception { EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT) .anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(req); firehose.shutdown(DateTimes.nowUtc().plusMillis(100).toString(), req); while (!firehose.isClosed()) { Thread.sleep(50); } }
@Test public void testTerminateAll() { EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)); supervisorManager.stopAndRemoveAllSupervisors(); EasyMock.expectLastCall(); replayAll(); Response response = supervisorResource.terminateAll(); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity()); verifyAll(); }
@Test public void cleanup() { PooledTopNAlgorithm pooledTopNAlgorithm = new PooledTopNAlgorithm(EasyMock.mock(StorageAdapter.class), null, null); PooledTopNAlgorithm.PooledTopNParams params = EasyMock.createMock(PooledTopNAlgorithm.PooledTopNParams.class); ResourceHolder<ByteBuffer> resourceHolder = EasyMock.createMock(ResourceHolder.class); EasyMock.expect(params.getResultsBufHolder()).andReturn(resourceHolder).times(1); EasyMock.expect(resourceHolder.get()).andReturn(ByteBuffer.allocate(1)).times(1); resourceHolder.close(); EasyMock.expectLastCall().once(); EasyMock.replay(params); EasyMock.replay(resourceHolder); pooledTopNAlgorithm.cleanup(params); EasyMock.verify(params); EasyMock.verify(resourceHolder); } }
@Test public void shouldPrintServerAddressWhenEmptyStringArg() throws Exception { expect(restClient.makeRootRequest()).andReturn(RestResponse.successful(SERVER_INFO)); expect(restClient.getServerAddress()).andReturn(new URI(INITIAL_SERVER_ADDRESS)); restClient.setServerAddress(anyString()); expectLastCall().andThrow(new AssertionError("should not set address")); replay(restClient); command.execute(ImmutableList.of(), terminal); assertThat(out.toString(), equalTo(INITIAL_SERVER_ADDRESS + "\n")); }
@Test public void testSuspendAll() { EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)); supervisorManager.suspendOrResumeAllSupervisors(true); EasyMock.expectLastCall(); replayAll(); Response response = supervisorResource.suspendAll(); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity()); verifyAll(); }
@Test public void testResumeAll() { EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)); supervisorManager.suspendOrResumeAllSupervisors(false); EasyMock.expectLastCall(); replayAll(); Response response = supervisorResource.resumeAll(); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(ImmutableMap.of("status", "success"), response.getEntity()); verifyAll(); }