private void mockFetchManagerRestartAnyTimes() throws InterruptedException { this.fetchManager.stopFetchRunner(); EasyMock.expectLastCall().anyTimes(); this.fetchManager.resetFetchState(); EasyMock.expectLastCall().anyTimes(); this.fetchManager.startFetchRunner(); EasyMock.expectLastCall().anyTimes(); }
@SuppressWarnings({"ThrowableInstanceNeverThrown"}) private void expectEvaluateCalled( final I_EncodeBusinessProcess mockBusinessProcess, final CleanableProcessExtByRef mockCleanableProcess, final CleanableProcessExtByRefBuilder mockCleanableProcessBuilder) throws Exception { File mockDirectoryFile = mockControl.createMock(File.class); I_GetConceptData mockRefset = mockControl.createMock(I_GetConceptData.class); EasyMock.expect(mockTerminologyWrapper.get()).andReturn(mockTermFactory); EasyMock.expect(mockBusinessProcess.getProperty(DIRECTORY_KEY)).andReturn(mockDirectoryFile); EasyMock.expect(mockBusinessProcess.getProperty(WORKING_REFSET_KEY)).andReturn(mockRefset); mockPropertyValidator.validate(mockDirectoryFile, "output directory"); mockPropertyValidator.validate(mockRefset, "selected refset"); EasyMock.expect(mockCleanableProcessBuilder.withTermFactory(mockTermFactory)) .andReturn(mockCleanableProcessBuilder); EasyMock.expect(mockCleanableProcessBuilder.withSelectedDir(mockDirectoryFile)) .andReturn(mockCleanableProcessBuilder); EasyMock.expect(mockCleanableProcessBuilder.withLogger(EasyMock.isA(Logger.class))) .andReturn(mockCleanableProcessBuilder); EasyMock.expect(mockCleanableProcessBuilder.build()).andReturn(mockCleanableProcess); I_ExtendByRef mockExt1 = mockControl.createMock(I_ExtendByRef.class); I_ExtendByRef mockExt2 = mockControl.createMock(I_ExtendByRef.class); EasyMock.expect(mockRefset.getConceptId()).andReturn(REFSET_CONCEPT_ID); // TODO fix this one // EasyMock.expect(mockTermFactory.getRefsetExtensionMembers(REFSET_CONCEPT_ID)).andReturn(Arrays.asList(mockExt1, mockExt2)); mockCleanableProcess.processExtensionByReference(mockExt1); mockCleanableProcess.processExtensionByReference(mockExt2); EasyMock.expectLastCall().andThrow(new IllegalStateException()); mockCleanableProcess.clean(); }
@Test public void testHandleRequestPartitionClosedSlave() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = 10; this.metaConfig.setTopics(Arrays.asList(this.topic)); this.metaConfig.closePartitions(this.topic, partition, partition); final MessageStore store = this.mocksControl.createMock(MessageStore.class); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store); final MessageSet set = this.mocksControl.createMock(MessageSet.class); EasyMock.expect(store.slice(offset, maxSize)).andReturn(set); final GetCommand request = new GetCommand( this.topic, this.metaConfig.getSlaveGroup(), partition, offset, maxSize, opaque); // this.conn.response(new BooleanCommand(request.getOpaque(), // HttpStatus.Forbidden, "partition[" // + this.metaConfig.getBrokerId() + "-" + request.getPartition() + // "] have been closed")); set.write(request, this.sessionContext); EasyMock.expectLastCall(); this.mocksControl.replay(); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(0, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(0, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestPartitionClosed() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = 10; this.metaConfig.setTopics(Arrays.asList(this.topic)); this.metaConfig.closePartitions(this.topic, partition, partition); final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque); this.conn.response( new BooleanCommand( request.getOpaque(), HttpStatus.Forbidden, "Partition[" + this.metaConfig.getBrokerId() + "-" + request.getPartition() + "] has been closed")); EasyMock.expectLastCall(); this.mocksControl.replay(); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); }
public SmsBuilder aboutPurchase(String amount) { EasyMock.expect(anySmsMessage.getDisplayMessageBody()) .andReturn( String.format( "You have done a debit purchase of INR %s at ARJAY RETAIL SONY BANGALORE.Available balance as on Jan 6 2010 8:45 PM IST is INR 10,000.00", amount)); EasyMock.expectLastCall().anyTimes(); return this; }
private void mockLoadNullInitOffset( final String topic, final String group, final Partition partition) { EasyMock.expect( this.offsetStorage.load( EasyMock.eq(topic), EasyMock.contains(group), EasyMock.eq(partition))) .andReturn(null); this.offsetStorage.initOffset( EasyMock.eq(topic), EasyMock.contains(group), EasyMock.eq(partition), EasyMock.eq(0L)); EasyMock.expectLastCall(); }
@Test public void testPerformReturnsUnstableAndDoesNotInvokeOtherPublishers() throws Exception { final BapPublisher mockPub1 = createAndAddMockPublisher(hostConfiguration.getName()); mockPub1.perform(hostConfiguration, buildInfo); EasyMock.expectLastCall().andThrow(new RuntimeException("Bad stuff here!")); createAndAddMockPublisher(null); final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, false, false, false); instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess); assertResult(Result.UNSTABLE, instanceConfig); }
@Test public void testPerformReturnsFailureIfFailOnError() throws Exception { final BapPublisher mockPub1 = createAndAddMockPublisher(hostConfiguration.getName()); mockPub1.perform(hostConfiguration, buildInfo); EasyMock.expectLastCall().andThrow(new RuntimeException("Bad stuff here!")); createAndAddMockPublisher(null); final BPInstanceConfig instanceConfig = createInstanceConfig(publishers, false, true, false); instanceConfig.setHostConfigurationAccess(mockHostConfigurationAccess); assertResult(Result.FAILURE, instanceConfig); }
@Test public void testHandleBeginTransaction() throws Exception { final String sessionId = "test"; final LocalTransactionId transactionId = new LocalTransactionId(sessionId, 1); final TransactionInfo info = new TransactionInfo(transactionId, sessionId, TransactionType.BEGIN); final TransactionCommand tc = new TransactionCommand(info, 1); this.commandProcessor.beginTransaction( new SessionContextImpl(sessionId, this.conn), transactionId, 0); EasyMock.expectLastCall(); this.mockSessionContext(sessionId, sessionId); this.mockResponseOK(); this.replay(); this.transactionProcessor.handleRequest(tc, this.conn); }
@Test public void testCommitOnePhase() throws Exception { final String sessionId = "test"; final LocalTransactionId transactionId = new LocalTransactionId(sessionId, 1); final TransactionInfo info = new TransactionInfo(transactionId, sessionId, TransactionType.COMMIT_ONE_PHASE); final TransactionCommand tc = new TransactionCommand(info, 1); this.commandProcessor.commitTransaction( new SessionContextImpl(sessionId, this.conn), transactionId, true); EasyMock.expectLastCall(); this.mockResponseOK(); this.mockSessionContext(sessionId, sessionId); this.replay(); this.transactionProcessor.handleRequest(tc, this.conn); }
@Test public void testHandleException() throws Exception { final String sessionId = "test"; final TransactionInfo info = new TransactionInfo(null, sessionId, TransactionType.RECOVER); final TransactionCommand tc = new TransactionCommand(info, 1); this.mockSessionContext(SessionContextHolder.GLOBAL_SESSION_KEY, sessionId); EasyMock.expect( this.commandProcessor.getPreparedTransactions( new SessionContextImpl("test", this.conn))) .andThrow(new RuntimeException("just for test")); this.conn.response(new BooleanCommand(1, HttpStatus.InternalServerError, "just for test")); EasyMock.expectLastCall(); this.replay(); this.transactionProcessor.handleRequest(tc, this.conn); }
@Test public void testRecoverTransaction() throws Exception { final String sessionId = "test"; final TransactionInfo info = new TransactionInfo(null, sessionId, TransactionType.RECOVER); final TransactionCommand tc = new TransactionCommand(info, 1); final TransactionId[] ids = this.generateIds(); final String resultString = this.generateIdsString(ids); this.mockSessionContext(SessionContextHolder.GLOBAL_SESSION_KEY, sessionId); EasyMock.expect( this.commandProcessor.getPreparedTransactions( new SessionContextImpl("test", this.conn))) .andReturn(ids); this.conn.response(new BooleanCommand(1, HttpStatus.Success, resultString)); EasyMock.expectLastCall(); this.replay(); this.transactionProcessor.handleRequest(tc, this.conn); }
@Test public void testHandleRequestNoStore() throws Exception { final int partition = 1; final int opaque = 0; EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(null); this.conn.response( new BooleanCommand( opaque, HttpStatus.NotFound, "The topic `" + this.topic + "` in partition `" + partition + "` is not exists")); EasyMock.expectLastCall(); this.mocksControl.replay(); final GetCommand request = new GetCommand(this.topic, this.group, partition, opaque, 1024 * 1024, opaque); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(1, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(0, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestNormal() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = 10; final MessageStore store = this.mocksControl.createMock(MessageStore.class); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store); final MessageSet set = this.mocksControl.createMock(MessageSet.class); EasyMock.expect(store.slice(offset, maxSize)).andReturn(set); final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque); set.write(request, this.sessionContext); EasyMock.expectLastCall(); this.mocksControl.replay(); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(0, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(0, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestInvalidMaxSize() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = -1; this.metaConfig.setMaxTransferSize(1024); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)) .andReturn(new MessageStore(this.topic, partition, this.metaConfig, null)); this.conn.response( new BooleanCommand( opaque, HttpStatus.BadRequest, "Bad request,invalid max size:" + maxSize)); EasyMock.expectLastCall(); this.mocksControl.replay(); final GetCommand request = new GetCommand(this.topic, this.group, partition, opaque, maxSize, opaque); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(0, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(0, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestArrayIndexOutOfBounds() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = 10; final long newOffset = 512; final MessageStore store = this.mocksControl.createMock(MessageStore.class); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store); EasyMock.expect(store.slice(offset, maxSize)).andThrow(new ArrayIndexOutOfBoundsException()); EasyMock.expect(store.getNearestOffset(offset)).andReturn(newOffset); this.conn.response(new BooleanCommand(opaque, HttpStatus.Moved, String.valueOf(newOffset))); EasyMock.expectLastCall(); this.mocksControl.replay(); final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(1, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(1, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestGreatThanMaxOffsetSliceNull() throws Exception { final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = 10; final MessageStore store = this.mocksControl.createMock(MessageStore.class); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store); EasyMock.expect(store.slice(offset, maxSize)).andReturn(null); this.conn.response( new BooleanCommand( opaque, HttpStatus.NotFound, "Could not find message at position " + offset)); EasyMock.expect(store.getMaxOffset()).andReturn(offset - 1); EasyMock.expectLastCall(); this.mocksControl.replay(); final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(1, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(0, this.statsManager.getCmdOffsets()); }
@Test public void testHandleRequestMaxOffset() throws Exception { // 从实际最大的offset开始订阅 final int partition = 1; final int opaque = 0; final int maxSize = 1024; final long offset = Long.MAX_VALUE; final long realMaxOffset = 100; final MessageStore store = this.mocksControl.createMock(MessageStore.class); EasyMock.expect(this.storeManager.getMessageStore(this.topic, partition)).andReturn(store); EasyMock.expect(store.slice(offset, maxSize)).andReturn(null); this.conn.response(new BooleanCommand(opaque, HttpStatus.Moved, String.valueOf(realMaxOffset))); EasyMock.expect(store.getMaxOffset()).andReturn(realMaxOffset); EasyMock.expectLastCall(); this.mocksControl.replay(); final GetCommand request = new GetCommand(this.topic, this.group, partition, offset, maxSize, opaque); this.getProcessor.handleRequest(request, this.conn); this.mocksControl.verify(); assertEquals(1, this.statsManager.getCmdGetMiss()); assertEquals(1, this.statsManager.getCmdGets()); assertEquals(1, this.statsManager.getCmdOffsets()); }
@Test public void testFailureJob2() throws Exception { final AtomicLong numJobsComplete = new AtomicLong(0); /** ** Setup mockFlow1 *** */ final Capture<FlowCallback> flow1Callback = new Capture<FlowCallback>(); mockFlow1.execute(EasyMock.eq(props), EasyMock.capture(flow1Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(1, numJobsComplete.incrementAndGet()); flow1Callback.getValue().completed(Status.SUCCEEDED); return null; } }) .once(); EasyMock.expect(mockFlow1.getStatus()).andReturn(Status.SUCCEEDED).times(2); EasyMock.expect(mockFlow1.getExceptions()).andReturn(emptyExceptions).times(1); /** ** Setup mockFlow2 *** */ final Capture<FlowCallback> flow2Callback = new Capture<FlowCallback>(); mockFlow2.execute(EasyMock.eq(props), EasyMock.capture(flow2Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(2, numJobsComplete.incrementAndGet()); flow2Callback.getValue().completed(Status.FAILED); return null; } }) .once(); EasyMock.expect(mockFlow2.getStatus()) .andAnswer( new IAnswer<Status>() { private volatile AtomicInteger count = new AtomicInteger(0); @Override public Status answer() throws Throwable { switch (count.getAndIncrement()) { case 0: return Status.READY; case 1: return Status.FAILED; default: Assert.fail("mockFlow2.getStatus() should only be called 2 times."); } return null; } }) .times(2); final RuntimeException e1 = new RuntimeException(); final RuntimeException e2 = new RuntimeException(); final Map<String, Throwable> e1s = new HashMap<String, Throwable>(); e1s.put("e1", e1); e1s.put("e2", e2); EasyMock.expect(mockFlow2.getExceptions()).andReturn(e1s).times(1); EasyMock.expect(props.equalsProps(props)).andReturn(true).once(); EasyMock.replay(mockFlow1, mockFlow2, props); /** ** Start the test *** */ AtomicBoolean callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override public void theCallback(Status status) { Assert.assertEquals(Status.FAILED, status); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertEquals(e1s, flow.getExceptions()); callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override protected void theCallback(Status status) { Assert.assertEquals(Status.FAILED, status); Assert.assertEquals(2, numJobsComplete.get()); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertEquals(e1s, flow.getExceptions()); Assert.assertTrue("Expected to be able to reset the flow", flow.reset()); Assert.assertEquals(Status.READY, flow.getStatus()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); }
private void mockCommitOffsets( final String group, final Collection<TopicPartitionRegInfo> arrayList) { this.offsetStorage.commitOffset(group, arrayList); EasyMock.expectLastCall(); }
public SmsBuilder fromStandardChartered() { EasyMock.expect(anySmsMessage.getDisplayOriginatingAddress()).andReturn("DM-StanChrt"); EasyMock.expectLastCall().anyTimes(); return this; }
private void mockConnect(final String url) throws NotifyRemotingException, InterruptedException { this.remotingClient.connect(url); EasyMock.expectLastCall(); this.remotingClient.awaitReadyInterrupt(url); EasyMock.expectLastCall(); }
public SmsBuilder fromSourceOtherThanTheBank() { EasyMock.expect(anySmsMessage.getDisplayOriginatingAddress()).andReturn("TA-Adiclub"); EasyMock.expectLastCall().anyTimes(); return this; }
@Test public void testFailureJob1() throws Exception { final AtomicLong numJobsComplete = new AtomicLong(0); /** ** Setup mockFlow1 *** */ final Capture<FlowCallback> flow1Callback = new Capture<FlowCallback>(); mockFlow1.execute(EasyMock.eq(props), EasyMock.capture(flow1Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(1, numJobsComplete.incrementAndGet()); flow1Callback.getValue().completed(Status.FAILED); return null; } }) .once(); EasyMock.expect(mockFlow1.getStatus()).andReturn(Status.FAILED).times(1); EasyMock.expect(mockFlow1.getExceptions()).andReturn(theExceptions).times(1); EasyMock.expect(props.equalsProps(props)).andReturn(true).once(); /** ** Setup mockFlow2 *** */ EasyMock.expect(mockFlow2.getExceptions()).andReturn(emptyExceptions).times(1); EasyMock.replay(mockFlow1, mockFlow2, props); /** ** Start the test *** */ AtomicBoolean callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override public void theCallback(Status status) { Assert.assertEquals(Status.FAILED, status); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertEquals(theExceptions, flow.getExceptions()); callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override protected void theCallback(Status status) { Assert.assertEquals(Status.FAILED, status); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.FAILED, flow.getStatus()); Assert.assertEquals(theExceptions, flow.getExceptions()); Assert.assertTrue("Expected to be able to reset the flow", flow.reset()); Assert.assertEquals(Status.READY, flow.getStatus()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); }
private void mockAddFetchRequest(final FetchRequest fetchRequest) { this.fetchManager.addFetchRequest(fetchRequest); EasyMock.expectLastCall(); }
@Test public void testSanity() throws Exception { final AtomicLong numJobsComplete = new AtomicLong(0); /** ** Setup mockFlow1 *** */ final Capture<FlowCallback> flow1Callback = new Capture<FlowCallback>(); mockFlow1.execute(EasyMock.eq(props), EasyMock.capture(flow1Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(1, numJobsComplete.incrementAndGet()); flow1Callback.getValue().completed(Status.SUCCEEDED); Assert.assertEquals(Status.RUNNING, flow.getStatus()); return null; } }) .once(); Props mockFlow1Props = new Props(); mockFlow1Props.put("1", "1"); mockFlow1Props.put("2", "1"); EasyMock.expect(mockFlow1.getStatus()).andReturn(Status.SUCCEEDED).times(2); EasyMock.expect(mockFlow1.getReturnProps()).andReturn(mockFlow1Props).once(); /** ** Setup mockFlow2 *** */ final Capture<FlowCallback> flow2Callback = new Capture<FlowCallback>(); mockFlow2.execute(EasyMock.eq(props), EasyMock.capture(flow2Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(2, numJobsComplete.incrementAndGet()); flow2Callback.getValue().completed(Status.SUCCEEDED); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); return null; } }) .once(); EasyMock.expect(mockFlow2.getStatus()) .andAnswer( new IAnswer<Status>() { private volatile AtomicInteger count = new AtomicInteger(0); @Override public Status answer() throws Throwable { switch (count.getAndIncrement()) { case 0: return Status.READY; case 1: return Status.SUCCEEDED; default: Assert.fail("mockFlow2.getStatus() should only be called 2 times."); } return null; } }) .times(2); Props mockFlow2Props = new Props(); mockFlow2Props.put("2", "2"); mockFlow2Props.put("3", "2"); EasyMock.expect(mockFlow2.getReturnProps()).andReturn(mockFlow2Props).once(); EasyMock.expect(props.equalsProps(props)).andReturn(true).once(); EasyMock.replay(mockFlow1, mockFlow2, props); /** ** Start the test *** */ AtomicBoolean callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override public void theCallback(Status status) { Assert.assertEquals(Status.SUCCEEDED, status); Assert.assertEquals(2, numJobsComplete.get()); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); Assert.assertEquals(props, flow.getParentProps()); callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override protected void theCallback(Status status) { Assert.assertEquals(Status.SUCCEEDED, status); Assert.assertEquals(2, numJobsComplete.get()); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); Props retProps = flow.getReturnProps(); Assert.assertEquals(3, retProps.size()); Assert.assertEquals("1", retProps.get("1")); Assert.assertEquals("2", retProps.get("2")); Assert.assertEquals("2", retProps.get("3")); EasyMock.verify(props); EasyMock.reset(props); EasyMock.expect(props.equalsProps(props)).andReturn(false).once(); EasyMock.replay(props); boolean exceptionThrown = false; try { flow.execute( props, new FlowCallback() { @Override public void progressMade() {} @Override public void completed(Status status) {} }); } catch (IllegalArgumentException e) { exceptionThrown = true; } Assert.assertTrue( "Expected an IllegalArgumentException to be thrown because props weren't the same.", exceptionThrown); }
private void mockConnectCloseAnyTimes(final String url) throws NotifyRemotingException, InterruptedException { this.remotingClient.close(url, false); EasyMock.expectLastCall().anyTimes(); }
@Test public void testAllCallbacksCalled() throws Exception { final AtomicLong numJobsComplete = new AtomicLong(0); final AtomicBoolean executeCallWhileStateWasRunningHadItsCallbackCalled = new AtomicBoolean(false); /** ** Setup mockFlow1 *** */ final Capture<FlowCallback> flow1Callback = new Capture<FlowCallback>(); mockFlow1.execute(EasyMock.eq(props), EasyMock.capture(flow1Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(1, numJobsComplete.incrementAndGet()); flow.execute( props, new OneCallFlowCallback(executeCallWhileStateWasRunningHadItsCallbackCalled) { @Override protected void theCallback(Status status) {} }); flow1Callback.getValue().completed(Status.SUCCEEDED); return null; } }) .once(); EasyMock.expect(mockFlow1.getStatus()).andReturn(Status.SUCCEEDED).times(2); /** ** Setup mockFlow2 *** */ final Capture<FlowCallback> flow2Callback = new Capture<FlowCallback>(); mockFlow2.execute(EasyMock.eq(props), EasyMock.capture(flow2Callback)); EasyMock.expectLastCall() .andAnswer( new IAnswer<Void>() { @Override public Void answer() throws Throwable { Assert.assertEquals(Status.RUNNING, flow.getStatus()); Assert.assertEquals(2, numJobsComplete.incrementAndGet()); flow2Callback.getValue().completed(Status.SUCCEEDED); return null; } }) .once(); EasyMock.expect(mockFlow2.getStatus()) .andAnswer( new IAnswer<Status>() { private volatile AtomicInteger count = new AtomicInteger(0); @Override public Status answer() throws Throwable { switch (count.getAndIncrement()) { case 0: return Status.READY; case 1: return Status.SUCCEEDED; default: Assert.fail("mockFlow2.getStatus() should only be called 2 times."); } return null; } }) .times(2); EasyMock.expect(mockFlow1.getReturnProps()).andReturn(new Props()).once(); EasyMock.expect(mockFlow2.getReturnProps()).andReturn(new Props()).once(); EasyMock.expect(props.equalsProps(props)).andReturn(true).times(2); EasyMock.replay(mockFlow1, mockFlow2, props); /** ** Start the test *** */ AtomicBoolean callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override public void theCallback(Status status) { Assert.assertEquals(Status.SUCCEEDED, status); Assert.assertEquals(2, numJobsComplete.get()); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); Assert.assertTrue( "mockFlow1, upon completion, sends another execute() call to the flow. " + "The callback from that execute call was apparently not called.", executeCallWhileStateWasRunningHadItsCallbackCalled.get()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); callbackRan = new AtomicBoolean(false); flow.execute( props, new OneCallFlowCallback(callbackRan) { @Override protected void theCallback(Status status) { Assert.assertEquals(Status.SUCCEEDED, status); Assert.assertEquals(2, numJobsComplete.get()); } }); Assert.assertTrue("Callback wasn't run.", callbackRan.get()); Assert.assertEquals(Status.SUCCEEDED, flow.getStatus()); Assert.assertEquals(emptyExceptions, flow.getExceptions()); }