Search in sources :

Example 11 with VerificationsInOrder

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;
        }
    };
}
Also used : Values(org.apache.storm.tuple.Values) VerificationsInOrder(mockit.VerificationsInOrder)

Example 12 with VerificationsInOrder

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());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) BeforeClass(org.junit.BeforeClass) Expectations(mockit.Expectations) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) VerificationsInOrder(mockit.VerificationsInOrder) Collectors.toMap(java.util.stream.Collectors.toMap) Files(com.google.common.io.Files) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) JMockit(mockit.integration.junit4.JMockit) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Before(org.junit.Before) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Delegate(mockit.Delegate) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) Injectable(mockit.Injectable) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 13 with VerificationsInOrder

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;
            }
        };
    }
}
Also used : Expectations(mockit.Expectations) IgnoreTransactionRollbackException(com.hortonworks.registries.storage.exception.IgnoreTransactionRollbackException) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 14 with VerificationsInOrder

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;
            }
        };
    }
}
Also used : Expectations(mockit.Expectations) IgnoreTransactionRollbackException(com.hortonworks.registries.storage.exception.IgnoreTransactionRollbackException) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Aggregations

VerificationsInOrder (mockit.VerificationsInOrder)14 Test (org.junit.Test)12 Expectations (mockit.Expectations)9 File (java.io.File)6 Topology (com.hortonworks.streamline.streams.catalog.Topology)4 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)4 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)4 IgnoreTransactionRollbackException (com.hortonworks.registries.storage.exception.IgnoreTransactionRollbackException)3 HashMap (java.util.HashMap)3 Values (org.apache.storm.tuple.Values)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Files (com.google.common.io.Files)2 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)2 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)2 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)2 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)2 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)2 Edge (com.hortonworks.streamline.streams.layout.component.Edge)2 Stream (com.hortonworks.streamline.streams.layout.component.Stream)2