use of org.apache.storm.tuple.Values in project storm by apache.
the class JdbcLookupBolt method process.
@Override
protected void process(Tuple tuple) {
try {
List<Column> columns = jdbcLookupMapper.getColumns(tuple);
List<List<Column>> result = jdbcClient.select(this.selectQuery, columns);
if (result != null && result.size() != 0) {
for (List<Column> row : result) {
List<Values> values = jdbcLookupMapper.toTuple(tuple, row);
for (Values value : values) {
collector.emit(tuple, value);
}
}
}
this.collector.ack(tuple);
} catch (Exception e) {
this.collector.reportError(e);
this.collector.fail(tuple);
}
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class SimpleJdbcLookupMapper method toTuple.
@Override
public List<Values> toTuple(ITuple input, List<Column> columns) {
Values values = new Values();
for (String field : outputFields) {
if (input.contains(field)) {
values.add(input.getValueByField(field));
} else {
for (Column column : columns) {
if (column.getColumnName().equalsIgnoreCase(field)) {
values.add(column.getVal());
}
}
}
}
List<Values> result = new ArrayList<Values>();
result.add(values);
return result;
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class ByTopicRecordTranslatorTest method testTopicCollision.
@Test(expected = IllegalStateException.class)
public void testTopicCollision() {
ByTopicRecordTranslator<String, String> trans = new ByTopicRecordTranslator<>((r) -> new Values(r.key()), new Fields("key"));
trans.forTopic("foo", (r) -> new Values(r.value()), new Fields("value"), "foo1");
trans.forTopic("foo", (r) -> new Values(r.key(), r.value()), new Fields("key", "value"), "foo2");
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class ByTopicRecordTranslatorTest method testFieldCollision.
@Test(expected = IllegalArgumentException.class)
public void testFieldCollision() {
ByTopicRecordTranslator<String, String> trans = new ByTopicRecordTranslator<>((r) -> new Values(r.key()), new Fields("key"));
trans.forTopic("foo", (r) -> new Values(r.value()), new Fields("value"));
}
use of org.apache.storm.tuple.Values in project storm by apache.
the class SingleTopicKafkaSpoutTest method shouldEmitAllMessages.
@Test
public void shouldEmitAllMessages() throws Exception {
try (SimulatedTime simulatedTime = new SimulatedTime()) {
int messageCount = 10;
initializeSpout(messageCount);
//Emit all messages and check that they are emitted. Ack the messages too
IntStream.range(0, messageCount).forEach(value -> {
spout.nextTuple();
ArgumentCaptor<Object> messageId = ArgumentCaptor.forClass(Object.class);
verify(collector).emit(eq(SingleTopicKafkaSpoutConfiguration.STREAM), eq(new Values(SingleTopicKafkaSpoutConfiguration.TOPIC, Integer.toString(value), Integer.toString(value))), messageId.capture());
spout.ack(messageId.getValue());
reset(collector);
});
Time.advanceTime(commitOffsetPeriodMs + KafkaSpout.TIMER_DELAY_MS);
//Commit offsets
spout.nextTuple();
verifyAllMessagesCommitted(messageCount);
}
}
Aggregations