use of com.twitter.heron.api.tuple.Values in project heron by twitter.
the class TestBolt method execute.
@Override
public void execute(Tuple tuple) {
AtomicInteger ackCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.ACK_COUNT);
AtomicInteger failCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton(Constants.FAIL_COUNT);
AtomicInteger tupleExecutedCount = (AtomicInteger) SingletonRegistry.INSTANCE.getSingleton("execute-count");
StringBuilder receivedStrings = (StringBuilder) SingletonRegistry.INSTANCE.getSingleton("received-string-list");
if (receivedStrings != null) {
receivedStrings.append(tuple.getString(0));
}
if (tupleExecutedCount != null) {
tupleExecutedCount.getAndIncrement();
}
if ((tupleExecuted & 1) == 0) {
outputCollector.ack(tuple);
if (ackCount != null) {
ackCount.getAndIncrement();
}
} else {
outputCollector.fail(tuple);
if (failCount != null) {
failCount.getAndIncrement();
}
}
tupleExecuted++;
outputCollector.emit(new Values(tuple.getString(0)));
}
use of com.twitter.heron.api.tuple.Values in project heron by twitter.
the class TestSpout method nextTuple.
@Override
public void nextTuple() {
// It will emit A, B, A, B, A, B, A, B, A, B
if (emitted < EMIT_COUNT) {
String word = toSend[emitted % toSend.length];
outputCollector.emit(new Values(word), MESSAGE_ID);
emitted++;
}
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class WindowedBoltExecutorTest method testExecuteWithLateTupleStream.
@Test
public void testExecuteWithLateTupleStream() throws Exception {
testWindowedBolt = new TestWindowedBolt();
testWindowedBolt.withTimestampField("ts");
executor = new WindowedBoltExecutor(testWindowedBolt);
TopologyContext context = getTopologyContext();
Mockito.when(context.getThisStreams()).thenReturn(new HashSet<>(Arrays.asList("default", "$late")));
OutputCollector outputCollector = Mockito.mock(OutputCollector.class);
Map<String, Object> conf = new HashMap<>();
conf.put(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 100000);
conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WINDOW_LENGTH_DURATION_MS, 20L);
conf.put(WindowingConfigs.TOPOLOGY_BOLTS_SLIDING_INTERVAL_DURATION_MS, 10L);
conf.put(WindowingConfigs.TOPOLOGY_BOLTS_LATE_TUPLE_STREAM, "$late");
conf.put(WindowingConfigs.TOPOLOGY_BOLTS_TUPLE_TIMESTAMP_MAX_LAG_MS, 5L);
// Trigger manually to avoid timing issues
conf.put(WindowingConfigs.TOPOLOGY_BOLTS_WATERMARK_EVENT_INTERVAL_MS, 1_000_000L);
executor.prepare(conf, context, outputCollector);
long[] timestamps = { 603, 605, 607, 618, 626, 636, 600 };
List<Tuple> tuples = new ArrayList<>(timestamps.length);
for (long ts : timestamps) {
Tuple tuple = getTuple("s1", new Fields("ts"), new Values(ts));
tuples.add(tuple);
executor.execute(tuple);
// Update the watermark to this timestamp
executor.waterMarkEventGenerator.run();
}
System.out.println(testWindowedBolt.tupleWindows);
Tuple tuple = tuples.get(tuples.size() - 1);
Mockito.verify(outputCollector).emit("$late", Arrays.asList(tuple), new Values(tuple));
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class WindowedBoltExecutorTest method testExecuteWithTs.
@Test
public void testExecuteWithTs() throws Exception {
long[] timestamps = { 603, 605, 607, 618, 626, 636 };
for (long ts : timestamps) {
executor.execute(getTuple("s1", new Fields("ts"), new Values(ts)));
}
// Thread.sleep(120);
executor.waterMarkEventGenerator.run();
// System.out.println(testWindowedBolt.tupleWindows);
assertEquals(3, testWindowedBolt.tupleWindows.size());
TupleWindow first = testWindowedBolt.tupleWindows.get(0);
assertArrayEquals(new long[] { 603, 605, 607 }, new long[] { (long) first.get().get(0).getValue(0), (long) first.get().get(1).getValue(0), (long) first.get().get(2).getValue(0) });
TupleWindow second = testWindowedBolt.tupleWindows.get(1);
assertArrayEquals(new long[] { 603, 605, 607, 618 }, new long[] { (long) second.get().get(0).getValue(0), (long) second.get().get(1).getValue(0), (long) second.get().get(2).getValue(0), (long) second.get().get(3).getValue(0) });
TupleWindow third = testWindowedBolt.tupleWindows.get(2);
assertArrayEquals(new long[] { 618, 626 }, new long[] { (long) third.get().get(0).getValue(0), (long) third.get().get(1).getValue(0) });
}
use of com.twitter.heron.api.tuple.Values in project incubator-heron by apache.
the class GeneralReduceByKeyAndWindowOperatorTest method getTupleWindow.
private TupleWindow getTupleWindow(int nkeys, int count) {
TopologyAPI.StreamId componentStreamId = TopologyAPI.StreamId.newBuilder().setComponentName("sourceComponent").setId("default").build();
List<Tuple> tuples = new LinkedList<>();
for (int i = 0; i < nkeys; i++) {
for (int j = 0; j < count; ++j) {
Tuple tuple = getTuple(componentStreamId, new Fields("a"), new Values(new KeyValue<>(String.valueOf(i), j)));
tuples.add(tuple);
}
}
TupleWindow tupleWindow = new TupleWindowImpl(tuples, new LinkedList<>(), new LinkedList<>(), startTime, endTime);
return tupleWindow;
}
Aggregations