use of org.apache.storm.tuple.Values in project flink by apache.
the class TestDummySpout method nextTuple.
@Override
public void nextTuple() {
if (this.emit) {
this.collector.emit(new Values(this.context));
this.emit = false;
}
}
use of org.apache.storm.tuple.Values in project flink by apache.
the class BoltCollectorTest method testBoltStormCollector.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBoltStormCollector() throws InstantiationException, IllegalAccessException {
for (int numberOfAttributes = -1; numberOfAttributes < 26; ++numberOfAttributes) {
final Output flinkCollector = mock(Output.class);
Tuple flinkTuple = null;
final Values tuple = new Values();
BoltCollector<?> collector;
final String streamId = "streamId";
HashMap<String, Integer> attributes = new HashMap<String, Integer>();
attributes.put(streamId, numberOfAttributes);
if (numberOfAttributes == -1) {
collector = new BoltCollector(attributes, -1, flinkCollector);
tuple.add(new Integer(this.r.nextInt()));
} else {
collector = new BoltCollector(attributes, -1, flinkCollector);
flinkTuple = Tuple.getTupleClass(numberOfAttributes).newInstance();
for (int i = 0; i < numberOfAttributes; ++i) {
tuple.add(new Integer(this.r.nextInt()));
flinkTuple.setField(tuple.get(i), i);
}
}
final Collection anchors = mock(Collection.class);
final List<Integer> taskIds;
taskIds = collector.emit(streamId, anchors, tuple);
Assert.assertNull(taskIds);
if (numberOfAttributes == -1) {
verify(flinkCollector).collect(tuple.get(0));
} else {
verify(flinkCollector).collect(flinkTuple);
}
}
}
use of org.apache.storm.tuple.Values in project flink by apache.
the class SpoutCollectorTest method testSpoutStormCollector.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSpoutStormCollector() throws InstantiationException, IllegalAccessException {
for (int numberOfAttributes = -1; numberOfAttributes < 26; ++numberOfAttributes) {
final SourceContext flinkCollector = mock(SourceContext.class);
Tuple flinkTuple = null;
final Values tuple = new Values();
SpoutCollector<?> collector;
final String streamId = "streamId";
HashMap<String, Integer> attributes = new HashMap<String, Integer>();
attributes.put(streamId, numberOfAttributes);
if (numberOfAttributes == -1) {
collector = new SpoutCollector(attributes, -1, flinkCollector);
tuple.add(new Integer(this.r.nextInt()));
} else {
collector = new SpoutCollector(attributes, -1, flinkCollector);
flinkTuple = Tuple.getTupleClass(numberOfAttributes).newInstance();
for (int i = 0; i < numberOfAttributes; ++i) {
tuple.add(new Integer(this.r.nextInt()));
flinkTuple.setField(tuple.get(i), i);
}
}
final List<Integer> taskIds;
final Object messageId = new Integer(this.r.nextInt());
taskIds = collector.emit(streamId, tuple, messageId);
Assert.assertNull(taskIds);
if (numberOfAttributes == -1) {
verify(flinkCollector).collect(tuple.get(0));
} else {
verify(flinkCollector).collect(flinkTuple);
}
}
}
use of org.apache.storm.tuple.Values in project flink by apache.
the class SpoutCollectorTest method testSpoutStormCollectorWithTaskId.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSpoutStormCollectorWithTaskId() throws InstantiationException, IllegalAccessException {
for (int numberOfAttributes = 0; numberOfAttributes < 25; ++numberOfAttributes) {
final SourceContext flinkCollector = mock(SourceContext.class);
final int taskId = 42;
final String streamId = "streamId";
HashMap<String, Integer> attributes = new HashMap<String, Integer>();
attributes.put(streamId, numberOfAttributes);
SpoutCollector<?> collector = new SpoutCollector(attributes, taskId, flinkCollector);
final Values tuple = new Values();
final Tuple flinkTuple = Tuple.getTupleClass(numberOfAttributes + 1).newInstance();
for (int i = 0; i < numberOfAttributes; ++i) {
tuple.add(new Integer(this.r.nextInt()));
flinkTuple.setField(tuple.get(i), i);
}
flinkTuple.setField(taskId, numberOfAttributes);
final List<Integer> taskIds;
final Object messageId = new Integer(this.r.nextInt());
taskIds = collector.emit(streamId, tuple, messageId);
Assert.assertNull(taskIds);
verify(flinkCollector).collect(flinkTuple);
}
}
use of org.apache.storm.tuple.Values in project flink by apache.
the class StormTupleTest method testSelect.
@Test
public void testSelect() throws Exception {
Tuple tuple = Tuple.getTupleClass(arity).newInstance();
Values values = new Values();
ArrayList<String> attributeNames = new ArrayList<String>(arity);
ArrayList<String> filterNames = new ArrayList<String>(arity);
for (int i = 0; i < arity; ++i) {
tuple.setField(i, i);
attributeNames.add("a" + i);
if (r.nextBoolean()) {
filterNames.add("a" + i);
values.add(i);
}
}
Fields schema = new Fields(attributeNames);
Fields selector = new Fields(filterNames);
Assert.assertEquals(values, new StormTuple<>(tuple, schema, -1, null, null, null).select(selector));
}
Aggregations