use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class SubstituteTransformRuntimeTest method testSubstituteSpecificVars.
@Test
public void testSubstituteSpecificVars() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("1", "one");
fieldsAndValues.put("2", "${1} plus ${1}");
fieldsAndValues.put("3", "${1} plus two");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("dsrcid").build();
TransformRuntime transformRuntime = new SubstituteTransformRuntime(new SubstituteTransform(Collections.singleton("3")));
List<StreamlineEvent> result = transformRuntime.execute(event);
assertEquals(1, result.size());
assertEquals(3, result.get(0).size());
assertEquals("one", result.get(0).get("1"));
assertEquals("${1} plus ${1}", result.get(0).get("2"));
assertEquals("one plus two", result.get(0).get("3"));
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class FunctionsTest method getTupleNestedAndArray.
private Tuple getTupleNestedAndArray() {
Map<String, Object> map = new HashMap<>();
List<Person> person = Arrays.asList(new Person("a", 1), new Person("b", 2));
Map<Integer, Integer> squares = new HashMap<>();
squares.put(1, 1);
squares.put(2, 4);
squares.put(3, 9);
map.put("person", person);
map.put("squares", squares);
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).dataSourceId("dsrcid").build();
return new TupleImpl(mockContext, new Values(event), 1, "inputstream");
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class FunctionsTest method getTuple.
private Tuple getTuple() {
Map<String, Object> map = new HashMap<>();
map.put("intfield", 2);
map.put("stringfield1", "hello");
map.put("stringfield2", "world");
map.put("stringfield3", " space ");
map.put("stringfield4", "aaaa");
map.put("negativefield", -1.0);
map.put("doublefield", 1.41);
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).dataSourceId("dsrcid").build();
return new TupleImpl(mockContext, new Values(event), 1, "inputstream");
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class EventCorrelatingOutputCollectorTest method emitWithAnchor.
@Test
public void emitWithAnchor() throws Exception {
setupExpectationsForTuple();
setupExpectationsForTopologyContextEmit();
setupExpectationsForEventCorrelationInjector();
EventCorrelatingOutputCollector sut = new EventCorrelatingOutputCollector(mockedTopologyContext, mockedOutputCollector);
Deencapsulation.setField(sut, "eventCorrelationInjector", mockStormEventCorrelationInjector);
StreamlineEvent parentEvent = eventCorrelationInjector.injectCorrelationInformation(PARENT_STREAMLINE_EVENT, Collections.emptyList(), TEST_COMPONENT_NAME_FOR_STORM);
Tuple anchor = new TupleImpl(mockedTopologyContext, new Values(parentEvent), TASK_0, Utils.DEFAULT_STREAM_ID);
String testStreamId = "testStreamId";
List<Integer> expectedTasks = Lists.newArrayList(TASK_1, TASK_2);
final List<Tuple> anchors = Collections.singletonList(anchor);
final Values tuple = new Values(INPUT_STREAMLINE_EVENT);
// String streamId, Tuple anchor, List<Object> anchor
new Expectations() {
{
mockedOutputCollector.emit(testStreamId, anchor, withAny(tuple));
result = expectedTasks;
}
};
List<Integer> tasks = sut.emit(testStreamId, anchor, tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(testStreamId, anchor, 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(1, capturedParents.size());
assertEquals(anchor, capturedParents.get(0));
}
};
// Collection<Tuple> anchors, List<Object> tuple
new Expectations() {
{
mockedOutputCollector.emit(anchors, withAny(tuple));
result = expectedTasks;
}
};
tasks = sut.emit(anchors, tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(anchors, 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(1, capturedParents.size());
assertEquals(anchor, capturedParents.get(0));
}
};
// Tuple anchor, List<Object> tuple
new Expectations() {
{
mockedOutputCollector.emit(anchor, withAny(tuple));
result = expectedTasks;
}
};
tasks = sut.emit(anchor, tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(anchor, 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(1, capturedParents.size());
assertEquals(anchor, capturedParents.get(0));
}
};
// String streamId, Collection<Tuple> anchors, List<Object> tuple
new Expectations() {
{
mockedOutputCollector.emit(testStreamId, anchors, withAny(tuple));
result = expectedTasks;
}
};
tasks = sut.emit(testStreamId, anchors, tuple);
assertEquals(expectedTasks, tasks);
new Verifications() {
{
List<Object> capturedValues;
mockedOutputCollector.emit(testStreamId, anchors, 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(1, capturedParents.size());
assertEquals(anchor, capturedParents.get(0));
}
};
}
use of com.hortonworks.streamline.streams.StreamlineEvent in project streamline by hortonworks.
the class StreamlineEventImplTest method testGetId.
@Test
public void testGetId() throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("a", "aval");
map.put("b", "bval");
StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(map).build();
assertNotNull(UUID.fromString(event.getId()));
}
Aggregations