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;
}
};
}
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));
}
};
}
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;
}
};
}
}
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;
}
};
}
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());
}
};
}
Aggregations