Search in sources :

Example 1 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class FileWatcherTest method test.

@Test
public void test() throws IOException {
    boolean hasMoreEvents;
    File f = testFilePath.toFile();
    f.createNewFile();
    hasMoreEvents = fileWatcher.processEvents();
    Assert.assertEquals(true, hasMoreEvents);
    new VerificationsInOrder() {

        {
            fileEventHandler.created(withEqual(testFilePath));
            times = 1;
        }
    };
    f.setLastModified(System.currentTimeMillis());
    hasMoreEvents = fileWatcher.processEvents();
    Assert.assertEquals(true, hasMoreEvents);
    new VerificationsInOrder() {

        {
            fileEventHandler.modified(withEqual(testFilePath));
            times = 1;
        }
    };
    f.delete();
    hasMoreEvents = fileWatcher.processEvents();
    Assert.assertEquals(true, hasMoreEvents);
    new VerificationsInOrder() {

        {
            fileEventHandler.deleted(withEqual(testFilePath));
            times = 1;
        }
    };
}
Also used : File(java.io.File) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 2 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class CustomProcessorUploadHandlerTest method testSuccessfulUpload.

@Test
public void testSuccessfulUpload() throws IOException, ComponentConfigException, NoSuchAlgorithmException {
    String fileName = "consolecustomprocessor.tar";
    URL url = classLoader.getResource(resourceDirectoryPrefix + fileName);
    String consoleCustomProcessorTarString = url.getFile();
    File consoleCustomProcessorTar = new File(consoleCustomProcessorTarString);
    FileUtils.copyFileToDirectory(consoleCustomProcessorTar, new File(uploadWatchDirectory), false);
    this.customProcessorUploadHandler.created(Paths.get(uploadWatchDirectory).resolve(fileName));
    new VerificationsInOrder() {

        {
            InputStream jarFileActual;
            CustomProcessorInfo actual;
            catalogService.addCustomProcessorInfoAsBundle(actual = withCapture(), jarFileActual = withCapture());
            times = 1;
            Assert.assertTrue(actual.getName().equals(customProcessorInfo.getName()));
            Assert.assertTrue(IOUtils.contentEquals(jarFileActual, jarFile));
        }
    };
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) URL(java.net.URL) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 3 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class CustomProcessorBoltTest method testExecute.

private void testExecute(boolean isSuccess) throws ProcessingException, ClassNotFoundException, MalformedURLException, InstantiationException, IllegalAccessException {
    customProcessorBolt.customProcessorImpl(ConsoleCustomProcessor.class.getCanonicalName());
    customProcessorBolt.outputSchema(outputStreamToSchema);
    Map<String, Object> data = new HashMap<>();
    data.put("key", "value");
    final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(data).dataSourceId("dsrcid").build();
    final List<StreamlineEvent> result = Arrays.asList(event);
    final ProcessingException pe = new ProcessingException("Test");
    new Expectations() {

        {
            tuple.getSourceComponent();
            returns("datasource");
            tuple.getSourceStreamId();
            returns(stream);
            tuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
            returns(event);
        }
    };
    if (!isSuccess) {
        new Expectations() {

            {
                customProcessorRuntime.process(event);
                result = pe;
            }
        };
    } else {
        new Expectations() {

            {
                customProcessorRuntime.process(event);
                returns(result);
            }
        };
    }
    Map<Object, Object> conf = new HashMap<>();
    customProcessorBolt.prepare(conf, null, mockOutputCollector);
    customProcessorBolt.execute(tuple);
    if (!isSuccess) {
        new VerificationsInOrder() {

            {
                RuntimeException e;
                customProcessorRuntime.process(event);
                times = 1;
                mockOutputCollector.fail(tuple);
                times = 1;
                mockOutputCollector.reportError(e = withCapture());
                assertTrue(e.getCause() == pe);
            }
        };
    } else {
        new VerificationsInOrder() {

            {
                tuple.getSourceComponent();
                times = 1;
                tuple.getSourceStreamId();
                times = 1;
                StreamlineEvent actual;
                customProcessorRuntime.process(actual = withCapture());
                times = 1;
                Assert.assertEquals(actual.getSourceStream(), stream);
                Assert.assertEquals(actual, event);
                Values actualValues;
                mockOutputCollector.emit(outputStream, tuple, actualValues = withCapture());
                times = 1;
                mockOutputCollector.ack(tuple);
                times = 1;
            }
        };
    }
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) ConsoleCustomProcessor(com.hortonworks.streamline.examples.processors.ConsoleCustomProcessor) Values(org.apache.storm.tuple.Values) VerificationsInOrder(mockit.VerificationsInOrder) ProcessingException(com.hortonworks.streamline.streams.exception.ProcessingException)

Example 4 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class RulesBoltSqlTest method test_ProjectedValues.

@Test
public void test_ProjectedValues() throws Exception {
    new Expectations() {

        {
            mockTuple.getValueByField(StreamlineEvent.STREAMLINE_EVENT);
            result = STREAMLINE_EVENT;
            mockTuple.getSourceStreamId();
            result = "default";
            mockContext.getThisComponentId();
            result = "1-componentid";
            minTimes = 0;
        }
    };
    rulesBolt.execute(mockTuple);
    new VerificationsInOrder() {

        {
            mockOutputCollector.emit(rulesProcessor.getRules().get(0).getOutputStreamNameForAction(rulesProcessor.getRules().get(0).getActions().iterator().next()), mockTuple, STREAMLINE_EVENT_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
            times = 1;
            StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) actualValues.get(0), PROJECTED_STREAMLINE_EVENT);
            mockOutputCollector.ack(withAny(mockTuple));
            times = 1;
        }
    };
}
Also used : Expectations(mockit.Expectations) Values(org.apache.storm.tuple.Values) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 5 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_withMismatchedExpectedOutputRecords.

@Test
public void runTest_withMismatchedExpectedOutputRecords() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    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);
    setTopologyTestRunCaseSinkMismatchedRecordsExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setSucceedTopologyActionsExpectations();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    assertNotNull(resultHistory);
    waitForTopologyTestRunToFinish(resultHistory);
    new VerificationsInOrder() {

        {
            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());
            assertTrue(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isNotEmptyJson(runHistory.getExpectedOutputRecords()));
            assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : 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)

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