use of mockit.Verifications in project streamline by hortonworks.
the class NotificationBoltTest method testFail.
@Test
public void testFail() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("foobar", "100");
final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
final Notification notification = new StreamlineEventAdapter(event);
new MockUp<NotificationQueueHandler>() {
@Mock
public void enqueue(Notifier notifier, Notification notification1) {
notifier.notify(notification);
}
@Mock
public void resubmit(String notificationId) {
notifier.notify(notification);
}
};
new Expectations() {
{
mockProxyUtil.loadClassFromJar(anyString, "TestClass");
result = notifier;
tuple.getValueByField(anyString);
result = event;
}
};
Map<String, String> stormConf = new HashMap<>();
stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
stormConf.put("local.notifier.jar.path", "/tmp");
bolt.prepare(stormConf, null, collector);
bolt.execute(tuple);
new Verifications() {
{
hBaseNotificationStore.store(notification);
times = 1;
hBaseNotificationStore.updateNotificationStatus(notification.getId(), Notification.Status.FAILED);
times = 1;
collector.ack(tuple);
times = 0;
collector.fail(tuple);
times = 1;
}
};
}
use of mockit.Verifications in project streamline by hortonworks.
the class FunctionsTest method testStringFunctions1.
@Test
public void testStringFunctions1() throws Exception {
doTest(readFile("/streamline-udf.json"), getTuple());
new Verifications() {
{
String streamId;
Tuple anchor;
List<List<Object>> tuples = new ArrayList<>();
mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
Assert.assertEquals(1, tuples.size());
Assert.assertEquals("CONCAT helloworld IDENTITY hello UPPER HELLO LOWER hello INITCAP Hello CHAR_LENGTH 5", ((StreamlineEvent) (tuples.get(0).get(0))).get("body"));
}
};
}
use of mockit.Verifications in project streamline by hortonworks.
the class FunctionsTest method testStringFunctions3.
@Test
public void testStringFunctions3() throws Exception {
doTest(readFile("/streamline-udf3.json"), getTuple());
new Verifications() {
{
String streamId;
Tuple anchor;
List<List<Object>> tuples = new ArrayList<>();
mockCollector.emit(streamId = withCapture(), anchor = withCapture(), withCapture(tuples));
Assert.assertEquals(1, tuples.size());
Assert.assertEquals("TRIM2 space LTRIM2 space RTRIM2 space", ((StreamlineEvent) (tuples.get(0).get(0))).get("body"));
}
};
}
use of mockit.Verifications in project streamline by hortonworks.
the class EventCorrelatingOutputCollectorTest method testAck.
@Test
public void testAck() throws Exception {
setupExpectationsForTuple();
setupExpectationsForTopologyContextNoEmit();
EventCorrelatingOutputCollector sut = getSystemUnderTest();
Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(PARENT_STREAMLINE_EVENT), TASK_0, Utils.DEFAULT_STREAM_ID);
sut.ack(anchor);
new Verifications() {
{
mockedOutputCollector.ack(anchor);
times = 1;
}
};
}
use of mockit.Verifications in project streamline by hortonworks.
the class EventCorrelatingOutputCollectorTest method emitWithoutAnchor.
@Test
public void emitWithoutAnchor() throws Exception {
setupExpectationsForTopologyContextEmit();
setupExpectationsForEventCorrelationInjector();
EventCorrelatingOutputCollector sut = getSystemUnderTest();
String testStreamId = "testStreamId";
List<Integer> expectedTasks = Lists.newArrayList(TASK_1, TASK_2);
final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
// String streamId, List<Object> tuple
new Expectations() {
{
mockedOutputCollector.emit(testStreamId, withAny(tuple));
result = expectedTasks;
}
};
List<Integer> tasks = sut.emit(testStreamId, tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(testStreamId, capturedValues = withCapture());
StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
List<Tuple> capturedParents;
mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
assertEquals(0, capturedParents.size());
}
};
// List<Object> tuple
new Expectations() {
{
mockedOutputCollector.emit(withAny(tuple));
result = expectedTasks;
}
};
tasks = sut.emit(tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(capturedValues = withCapture());
StreamlineEventTestUtil.assertEventIsProperlyCopied((StreamlineEvent) capturedValues.get(0), INPUT_STREAMLINE_EVENT);
List<Tuple> capturedParents;
mockStormEventCorrelationInjector.injectCorrelationInformation(tuple, capturedParents = withCapture(), TEST_COMPONENT_NAME_FOR_STORM);
assertEquals(0, capturedParents.size());
}
};
}
Aggregations