use of mockit.VerificationsInOrder in project streamline by hortonworks.
the class RulesBoltTest method executeAndVerifyCollectorCallsAcks.
private void executeAndVerifyCollectorCallsAcks(final int rule2NumTimes, final Values expectedValues) {
rulesBolt.execute(mockTuple);
new VerificationsInOrder() {
{
mockOutputCollector.emit(rulesProcessor.getRules().get(0).getOutputStreamNameForAction(rulesProcessor.getRules().get(0).getActions().iterator().next()), mockTuple, STREAMLINE_EVENT_MATCHES_TUPLE_VALUES);
// rule 1 does not trigger
times = 0;
Values actualValues;
mockOutputCollector.emit(rulesProcessor.getRules().get(1).getOutputStreamNameForAction(rulesProcessor.getRules().get(1).getActions().iterator().next()), mockTuple, actualValues = withCapture());
// rule 2 triggers rule2NumTimes
times = rule2NumTimes;
Assert.assertEquals(expectedValues, actualValues);
mockOutputCollector.ack(mockTuple);
times = 1;
}
};
}
use of mockit.VerificationsInOrder in project streamline by hortonworks.
the class TopologyTestRunnerTest method runTest_topologyActionsTestRunFails.
@Test
public void runTest_topologyActionsTestRunFails() throws Exception {
Topology topology = createSimpleDAGInjectedTestTopology();
Long topologyId = topology.getId();
Long testCaseId = 1L;
TopologyTestRunCase testCase = new TopologyTestRunCase();
testCase.setId(testCaseId);
testCase.setTopologyId(topology.getId());
testCase.setName("testcase1");
testCase.setTimestamp(System.currentTimeMillis());
setTopologyCurrentVersionExpectation(topology);
setTopologyTestRunCaseExpectations(topology, testCase);
setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
setTopologyTestRunHistoryExpectations();
setTopologyActionsThrowingExceptionExpectations();
long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
assertNotNull(resultHistory);
waitForTopologyTestRunToFinish(resultHistory);
new VerificationsInOrder() {
{
catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
times = (int) sourceCount;
catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
times = (int) sinkCount;
TopologyTestRunHistory runHistory;
// some fields are already modified after calling the method, so don't need to capture it
catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
times = 1;
catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
times = 1;
assertEquals(topology.getId(), runHistory.getTopologyId());
assertEquals(topology.getVersionId(), runHistory.getVersionId());
assertTrue(runHistory.getFinished());
assertFalse(runHistory.getSuccess());
assertNotNull(runHistory.getStartTime());
assertNotNull(runHistory.getFinishTime());
assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
assertTrue(isEmptyJson(runHistory.getExpectedOutputRecords()));
assertNull(runHistory.getActualOutputRecords());
assertFalse(runHistory.getMatched());
}
};
}
use of mockit.VerificationsInOrder in project registry by hortonworks.
the class ManagedTransactionTest method testCaseRollbackTransactionThrowsException.
@Test
public void testCaseRollbackTransactionThrowsException() {
final Exception rollbackException = new Exception("Rollback exception");
new Expectations() {
{
mockedTransactionManager.rollbackTransaction();
result = rollbackException;
}
};
try {
managedTransaction.executeConsumer(this::callHelperWithThrowException);
Assert.fail("It should propagate Exception");
} catch (Exception e) {
Assert.assertEquals(rollbackException, e);
Assert.assertTrue(testHelper.isCalled());
new VerificationsInOrder() {
{
mockedTransactionManager.beginTransaction(transactionIsolation);
times = 1;
mockedTransactionManager.commitTransaction();
times = 0;
mockedTransactionManager.rollbackTransaction();
times = 1;
}
};
}
}
use of mockit.VerificationsInOrder in project registry by hortonworks.
the class ManagedTransactionTest method testCaseCommitTransactionThrowsExceptionAfterCaseIgnoreRollbackException.
@Test
public void testCaseCommitTransactionThrowsExceptionAfterCaseIgnoreRollbackException() {
final Exception commitException = new Exception("Commit exception");
new Expectations() {
{
mockedTransactionManager.commitTransaction();
result = commitException;
}
};
try {
managedTransaction.executeConsumer(this::callHelperWithThrowIgnoreRollbackException);
Assert.fail("It should propagate Exception");
} catch (Exception e) {
Assert.assertEquals(commitException, e);
Assert.assertTrue(testHelper.isCalled());
new VerificationsInOrder() {
{
mockedTransactionManager.beginTransaction(transactionIsolation);
times = 1;
mockedTransactionManager.commitTransaction();
times = 1;
mockedTransactionManager.rollbackTransaction();
times = 1;
}
};
}
}
Aggregations