@Test public void shouldExitAndDrainIfQueryStopsRunning() throws Exception { // Given: expect(queryMetadata.isRunning()).andReturn(true).andReturn(false); expect(rowQueue.drainTo(capture(drainCapture))).andAnswer(rows("Row1", "Row2", "Row3")); createWriter(); // When: writer.write(out); // Then: final List<String> lines = getOutput(out); assertThat(lines, hasItems( containsString("Row1"), containsString("Row2"), containsString("Row3"))); }
@Test public void testInvoke() throws Throwable { MethodInvocation allianceInvocation = createMock(MethodInvocation.class); MethodInterceptor mockShiroInterceptor = createMock(MethodInterceptor.class); expect(mockShiroInterceptor.invoke(anyObject(AopAllianceMethodInvocationAdapter.class))).andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { return getCurrentArguments()[0]; } }); final Object expectedValue = new Object(); expect(allianceInvocation.proceed()).andReturn(expectedValue); replay(mockShiroInterceptor, allianceInvocation); AopAllianceMethodInterceptorAdapter underTest = new AopAllianceMethodInterceptorAdapter(mockShiroInterceptor); Object invocation = underTest.invoke(allianceInvocation); Object value = ((AopAllianceMethodInvocationAdapter) invocation).proceed(); assertSame("Adapter invocation returned a different value.", expectedValue, value); verify(mockShiroInterceptor, allianceInvocation); } }
@Test public void shouldExitAndDrainIfLimitReached() throws Exception { // Given: expect(queryMetadata.isRunning()).andReturn(true).anyTimes(); expect(rowQueue.drainTo(capture(drainCapture))).andAnswer(rows("Row1", "Row2", "Row3")); createWriter(); limitHandler.limitReached(); // When: writer.write(out); // Then: final List<String> lines = getOutput(out); assertThat(lines, hasItems( containsString("Row1"), containsString("Row2"), containsString("Row3"))); }
private void primePool() { EasyMock.expect(resourceFactory.generate("billy")).andAnswer(new StringIncrementingAnswer("billy")).times(2); EasyMock.expect(resourceFactory.generate("sally")).andAnswer(new StringIncrementingAnswer("sally")).times(2); EasyMock.expect(resourceFactory.isGood("billy0")).andReturn(true).times(1); EasyMock.expect(resourceFactory.isGood("sally0")).andReturn(true).times(1); EasyMock.replay(resourceFactory); ResourceContainer<String> billyString = pool.take("billy"); ResourceContainer<String> sallyString = pool.take("sally"); Assert.assertEquals("billy0", billyString.get()); Assert.assertEquals("sally0", sallyString.get()); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); billyString.returnResource(); sallyString.returnResource(); }
@Test public void shouldWriteAnyPendingRowsBeforeReportingException() throws Exception { // Given: expect(queryMetadata.isRunning()).andReturn(true).anyTimes(); expect(rowQueue.drainTo(capture(drainCapture))).andAnswer(rows("Row1", "Row2", "Row3")); createWriter(); givenUncaughtException(new KsqlException("Server went Boom")); // When: writer.write(out); // Then: final List<String> lines = getOutput(out); assertThat(lines, hasItems( containsString("Row1"), containsString("Row2"), containsString("Row3"))); }
.andAnswer(new IAnswer<Sequence>()
private BrokerFailureDetector createBrokerFailureDetector(Queue<Anomaly> anomalies, Time time) { LoadMonitor mockLoadMonitor = EasyMock.mock(LoadMonitor.class); KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class); EasyMock.expect(mockLoadMonitor.brokersWithPartitions(anyLong())).andAnswer(() -> new HashSet<>(Arrays.asList(0, 1))).anyTimes(); EasyMock.replay(mockLoadMonitor); Properties props = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties(); props.setProperty(KafkaCruiseControlConfig.ZOOKEEPER_CONNECT_CONFIG, zookeeper().getConnectionString()); KafkaCruiseControlConfig kafkaCruiseControlConfig = new KafkaCruiseControlConfig(props); return new BrokerFailureDetector(kafkaCruiseControlConfig, mockLoadMonitor, anomalies, time, mockKafkaCruiseControl); }
@Test public void testTimedOutResource() throws Exception { resourceFactory = (ResourceFactory<String, String>) EasyMock.createMock(ResourceFactory.class); pool = new ResourcePool<String, String>( resourceFactory, new ResourcePoolConfig(2, TimeUnit.MILLISECONDS.toMillis(10)) ); EasyMock.expect(resourceFactory.generate("billy")).andAnswer(new StringIncrementingAnswer("billy")).times(2); EasyMock.expect(resourceFactory.isGood("billy0")).andReturn(true).times(1); EasyMock.replay(resourceFactory); ResourceContainer<String> billyString = pool.take("billy"); Assert.assertEquals("billy0", billyString.get()); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); billyString.returnResource(); //make sure resources have been timed out. Thread.sleep(100); EasyMock.expect(resourceFactory.generate("billy")).andReturn("billy1").times(1); resourceFactory.close("billy1"); EasyMock.expect(resourceFactory.isGood("billy1")).andReturn(true).times(1); EasyMock.replay(resourceFactory); ResourceContainer<String> billy = pool.take("billy"); Assert.assertEquals("billy1", billy.get()); billy.returnResource(); EasyMock.verify(resourceFactory); EasyMock.reset(resourceFactory); }
.andAnswer( new IAnswer<Integer>() { @Override
public void replay() throws Exception { EasyMock.expect(orderItemDaoMock.createOrderItemPriceDetail()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAnswer()).anyTimes(); EasyMock.expect(orderItemDaoMock.createOrderItemQualifier()).andAnswer(OfferDataItemProvider.getCreateOrderItemQualifierAnswer()).anyTimes(); EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).anyTimes(); EasyMock.expect(fgServiceMock.addItemToFulfillmentGroup(EasyMock.isA(FulfillmentGroupItemRequest.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getAddItemToFulfillmentGroupAnswer()).anyTimes(); EasyMock.expect(orderServiceMock.removeItem(EasyMock.isA(Long.class), EasyMock.isA(Long.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getRemoveItemFromOrderAnswer()).anyTimes(); EasyMock.expect(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes(); EasyMock.expect(orderItemServiceMock.saveOrderItem(EasyMock.isA(OrderItem.class))).andAnswer(OfferDataItemProvider.getSaveOrderItemAnswer()).anyTimes(); EasyMock.expect(fgItemDaoMock.save(EasyMock.isA(FulfillmentGroupItem.class))).andAnswer(OfferDataItemProvider.getSaveFulfillmentGroupItemAnswer()).anyTimes(); EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() { EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getSameOrderAnswer()).anyTimes(); EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes(); fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class)); EasyMock.expectLastCall().anyTimes();
l.accept((CatalogVisitor) anyObject()); expectLastCall() .andAnswer( new VisitAnswer() { @Override
); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>()
); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>()
.andAnswer( new IAnswer<ServerView.CallbackAction>()
base.evaluate(); expectLastCall() .andAnswer( new IAnswer<Void>() {
base.evaluate(); expectLastCall() .andAnswer( new IAnswer<Void>() {
base.evaluate(); expectLastCall() .andAnswer( new IAnswer<Void>() {
.andAnswer( new IAnswer<ResourcePool>() { @Override