use of org.apache.storm.tuple.Tuple in project storm by apache.
the class KafkaBoltTest method executeWithByteArrayKeyAndMessageFire.
/* test with fireAndForget option enabled */
@Test
public void executeWithByteArrayKeyAndMessageFire() {
boolean async = true;
boolean fireAndForget = true;
bolt = generateDefaultSerializerBolt(async, fireAndForget, null);
String keyString = "test-key";
String messageString = "test-message";
byte[] key = keyString.getBytes();
byte[] message = messageString.getBytes();
Tuple tuple = generateTestTuple(key, message);
final ByteBufferMessageSet mockMsg = mockSingleMessage(key, message);
simpleConsumer.close();
simpleConsumer = mockSimpleConsumer(mockMsg);
KafkaProducer<?, ?> producer = mock(KafkaProducer.class);
// do not invoke the callback of send() in order to test whether the bolt handle the fireAndForget option
// properly.
doReturn(mock(Future.class)).when(producer).send(any(ProducerRecord.class), any(Callback.class));
bolt.execute(tuple);
verify(collector).ack(tuple);
verifyMessage(keyString, messageString);
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class KafkaBoltTest method executeWithoutKey.
@Test
public void executeWithoutKey() throws Exception {
String message = "value-234";
Tuple tuple = generateTestTuple(message);
bolt.execute(tuple);
verify(collector).ack(tuple);
verifyMessage(null, message);
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class KafkaBoltTest method executeWithBoltSpecifiedProperties.
/* test bolt specified properties */
@Test
public void executeWithBoltSpecifiedProperties() {
boolean async = false;
boolean fireAndForget = false;
bolt = defaultSerializerBoltWithSpecifiedProperties(async, fireAndForget);
String keyString = "test-key";
String messageString = "test-message";
byte[] key = keyString.getBytes();
byte[] message = messageString.getBytes();
Tuple tuple = generateTestTuple(key, message);
bolt.execute(tuple);
verify(collector).ack(tuple);
verifyMessage(keyString, messageString);
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class JoinBolt method doLeftJoin.
// left join - core implementation
protected JoinAccumulator doLeftJoin(JoinAccumulator probe, Map<Object, ArrayList<Tuple>> buildInput, JoinInfo joinInfo, boolean finalJoin) {
String[] probeKeyName = joinInfo.getOtherField();
JoinAccumulator result = new JoinAccumulator();
FieldSelector fieldSelector = new FieldSelector(joinInfo.other.getStreamName(), probeKeyName);
for (ResultRecord rec : probe.getRecords()) {
Object probeKey = rec.getField(fieldSelector);
if (probeKey != null) {
// ok if its return null
ArrayList<Tuple> matchingBuildRecs = buildInput.get(probeKey);
if (matchingBuildRecs != null && !matchingBuildRecs.isEmpty()) {
for (Tuple matchingRec : matchingBuildRecs) {
ResultRecord mergedRecord = new ResultRecord(rec, matchingRec, finalJoin);
result.insert(mergedRecord);
}
} else {
ResultRecord mergedRecord = new ResultRecord(rec, null, finalJoin);
result.insert(mergedRecord);
}
}
}
return result;
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class StatefulBoltExecutor method fail.
private void fail(List<Tuple> tuples) {
if (!tuples.isEmpty()) {
LOG.debug("Failing {} tuples", tuples.size());
for (Tuple tuple : tuples) {
collector.fail(tuple);
}
tuples.clear();
}
}
Aggregations