Search in sources :

Example 21 with Values

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)));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Values(com.twitter.heron.api.tuple.Values)

Example 22 with Values

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++;
    }
}
Also used : Values(com.twitter.heron.api.tuple.Values)

Example 23 with Values

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Values(com.twitter.heron.api.tuple.Values) Fields(com.twitter.heron.api.tuple.Fields) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Tuple(com.twitter.heron.api.tuple.Tuple) Test(org.junit.Test)

Example 24 with Values

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) });
}
Also used : Fields(com.twitter.heron.api.tuple.Fields) Values(com.twitter.heron.api.tuple.Values) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) Test(org.junit.Test)

Example 25 with Values

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;
}
Also used : Fields(com.twitter.heron.api.tuple.Fields) KeyValue(com.twitter.heron.streamlet.KeyValue) TupleWindowImpl(com.twitter.heron.api.windowing.TupleWindowImpl) Values(com.twitter.heron.api.tuple.Values) TupleWindow(com.twitter.heron.api.windowing.TupleWindow) Tuple(com.twitter.heron.api.tuple.Tuple) LinkedList(java.util.LinkedList) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI)

Aggregations

Values (com.twitter.heron.api.tuple.Values)34 Tuple (com.twitter.heron.api.tuple.Tuple)7 TupleWindow (com.twitter.heron.api.windowing.TupleWindow)6 IOException (java.io.IOException)6 Fields (com.twitter.heron.api.tuple.Fields)5 KeyValue (com.twitter.heron.streamlet.KeyValue)4 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)3 TupleWindowImpl (com.twitter.heron.api.windowing.TupleWindowImpl)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 KeyedWindow (com.twitter.heron.streamlet.KeyedWindow)2 Window (com.twitter.heron.streamlet.Window)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2 TweetsGenerator (com.github.ashvina.common.TweetsGenerator)1 TopologyContext (com.twitter.heron.api.topology.TopologyContext)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RankableObjectWithFields (org.apache.storm.starter.tools.RankableObjectWithFields)1