use of org.apache.storm.tuple.Tuple in project storm by apache.
the class StatefulBoltExecutor method handleCheckpoint.
@Override
protected void handleCheckpoint(Tuple checkpointTuple, Action action, long txid) {
LOG.debug("handleCheckPoint with tuple {}, action {}, txid {}", checkpointTuple, action, txid);
if (action == PREPARE) {
if (boltInitialized) {
bolt.prePrepare(txid);
state.prepareCommit(txid);
preparedTuples.addAll(collector.ackedTuples());
} else {
/*
* May be the task restarted in the middle and the state needs be initialized.
* Fail fast and trigger recovery.
*/
LOG.debug("Failing checkpointTuple, PREPARE received when bolt state is not initialized.");
collector.fail(checkpointTuple);
return;
}
} else if (action == COMMIT) {
bolt.preCommit(txid);
state.commit(txid);
ack(preparedTuples);
} else if (action == ROLLBACK) {
bolt.preRollback();
state.rollback();
fail(preparedTuples);
fail(collector.ackedTuples());
} else if (action == INITSTATE) {
if (!boltInitialized) {
bolt.initState((T) state);
boltInitialized = true;
LOG.debug("{} pending tuples to process", pendingTuples.size());
for (Tuple tuple : pendingTuples) {
doExecute(tuple);
}
pendingTuples.clear();
} else {
LOG.debug("Bolt state is already initialized, ignoring tuple {}, action {}, txid {}", checkpointTuple, action, txid);
}
}
collector.emit(CheckpointSpout.CHECKPOINT_STREAM_ID, checkpointTuple, new Values(txid, action));
collector.delegate.ack(checkpointTuple);
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class TestJoinBolt method testLeftJoin.
@Test
public void testLeftJoin() throws Exception {
ArrayList<Tuple> userStream = makeStream("users", userFields, users);
ArrayList<Tuple> orderStream = makeStream("orders", orderFields, orders);
TupleWindow window = makeTupleWindow(orderStream, userStream);
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "users", userFields[0]).leftJoin("orders", "userId", "users").select("userId,name,price");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(12, collector.actualResults.size());
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class TestJoinBolt method testTrivial.
@Test
public void testTrivial() throws Exception {
ArrayList<Tuple> orderStream = makeStream("orders", orderFields, orders);
TupleWindow window = makeTupleWindow(orderStream);
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "orders", orderFields[0]).select("orderId,userId,itemId,price");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(orderStream.size(), collector.actualResults.size());
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class TestJoinBolt method testInnerJoin.
@Test
public void testInnerJoin() throws Exception {
ArrayList<Tuple> userStream = makeStream("users", userFields, users);
ArrayList<Tuple> orderStream = makeStream("orders", orderFields, orders);
TupleWindow window = makeTupleWindow(orderStream, userStream);
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "users", userFields[0]).join("orders", "userId", "users").select("userId,name,price");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(orders.length, collector.actualResults.size());
}
use of org.apache.storm.tuple.Tuple in project storm by apache.
the class TestJoinBolt method testThreeStreamLeftJoin_1.
@Test
public void testThreeStreamLeftJoin_1() throws Exception {
ArrayList<Tuple> userStream = makeStream("users", userFields, users);
ArrayList<Tuple> storesStream = makeStream("stores", storeFields, stores);
ArrayList<Tuple> cityStream = makeStream("cities", cityFields, cities);
TupleWindow window = makeTupleWindow(userStream, cityStream, storesStream);
JoinBolt bolt = new JoinBolt(JoinBolt.Selector.STREAM, "users", userFields[2]).leftJoin("stores", "city", "users").leftJoin("cities", "cityName", "users").select("name,storeName,city,country");
MockCollector collector = new MockCollector();
bolt.prepare(null, null, collector);
bolt.execute(window);
printResults(collector);
Assert.assertEquals(users.length, collector.actualResults.size());
}
Aggregations