Search in sources :

Example 96 with Values

use of org.apache.storm.tuple.Values in project flink by apache.

the class TestDummySpout method nextTuple.

@Override
public void nextTuple() {
    if (this.emit) {
        this.collector.emit(new Values(this.context));
        this.emit = false;
    }
}
Also used : Values(org.apache.storm.tuple.Values)

Example 97 with Values

use of org.apache.storm.tuple.Values in project flink by apache.

the class BoltCollectorTest method testBoltStormCollector.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBoltStormCollector() throws InstantiationException, IllegalAccessException {
    for (int numberOfAttributes = -1; numberOfAttributes < 26; ++numberOfAttributes) {
        final Output flinkCollector = mock(Output.class);
        Tuple flinkTuple = null;
        final Values tuple = new Values();
        BoltCollector<?> collector;
        final String streamId = "streamId";
        HashMap<String, Integer> attributes = new HashMap<String, Integer>();
        attributes.put(streamId, numberOfAttributes);
        if (numberOfAttributes == -1) {
            collector = new BoltCollector(attributes, -1, flinkCollector);
            tuple.add(new Integer(this.r.nextInt()));
        } else {
            collector = new BoltCollector(attributes, -1, flinkCollector);
            flinkTuple = Tuple.getTupleClass(numberOfAttributes).newInstance();
            for (int i = 0; i < numberOfAttributes; ++i) {
                tuple.add(new Integer(this.r.nextInt()));
                flinkTuple.setField(tuple.get(i), i);
            }
        }
        final Collection anchors = mock(Collection.class);
        final List<Integer> taskIds;
        taskIds = collector.emit(streamId, anchors, tuple);
        Assert.assertNull(taskIds);
        if (numberOfAttributes == -1) {
            verify(flinkCollector).collect(tuple.get(0));
        } else {
            verify(flinkCollector).collect(flinkTuple);
        }
    }
}
Also used : HashMap(java.util.HashMap) Output(org.apache.flink.streaming.api.operators.Output) Values(org.apache.storm.tuple.Values) Collection(java.util.Collection) Tuple(org.apache.flink.api.java.tuple.Tuple) AbstractTest(org.apache.flink.storm.util.AbstractTest) Test(org.junit.Test)

Example 98 with Values

use of org.apache.storm.tuple.Values in project flink by apache.

the class SpoutCollectorTest method testSpoutStormCollector.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSpoutStormCollector() throws InstantiationException, IllegalAccessException {
    for (int numberOfAttributes = -1; numberOfAttributes < 26; ++numberOfAttributes) {
        final SourceContext flinkCollector = mock(SourceContext.class);
        Tuple flinkTuple = null;
        final Values tuple = new Values();
        SpoutCollector<?> collector;
        final String streamId = "streamId";
        HashMap<String, Integer> attributes = new HashMap<String, Integer>();
        attributes.put(streamId, numberOfAttributes);
        if (numberOfAttributes == -1) {
            collector = new SpoutCollector(attributes, -1, flinkCollector);
            tuple.add(new Integer(this.r.nextInt()));
        } else {
            collector = new SpoutCollector(attributes, -1, flinkCollector);
            flinkTuple = Tuple.getTupleClass(numberOfAttributes).newInstance();
            for (int i = 0; i < numberOfAttributes; ++i) {
                tuple.add(new Integer(this.r.nextInt()));
                flinkTuple.setField(tuple.get(i), i);
            }
        }
        final List<Integer> taskIds;
        final Object messageId = new Integer(this.r.nextInt());
        taskIds = collector.emit(streamId, tuple, messageId);
        Assert.assertNull(taskIds);
        if (numberOfAttributes == -1) {
            verify(flinkCollector).collect(tuple.get(0));
        } else {
            verify(flinkCollector).collect(flinkTuple);
        }
    }
}
Also used : HashMap(java.util.HashMap) Values(org.apache.storm.tuple.Values) SourceContext(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext) Tuple(org.apache.flink.api.java.tuple.Tuple) AbstractTest(org.apache.flink.storm.util.AbstractTest) Test(org.junit.Test)

Example 99 with Values

use of org.apache.storm.tuple.Values in project flink by apache.

the class SpoutCollectorTest method testSpoutStormCollectorWithTaskId.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSpoutStormCollectorWithTaskId() throws InstantiationException, IllegalAccessException {
    for (int numberOfAttributes = 0; numberOfAttributes < 25; ++numberOfAttributes) {
        final SourceContext flinkCollector = mock(SourceContext.class);
        final int taskId = 42;
        final String streamId = "streamId";
        HashMap<String, Integer> attributes = new HashMap<String, Integer>();
        attributes.put(streamId, numberOfAttributes);
        SpoutCollector<?> collector = new SpoutCollector(attributes, taskId, flinkCollector);
        final Values tuple = new Values();
        final Tuple flinkTuple = Tuple.getTupleClass(numberOfAttributes + 1).newInstance();
        for (int i = 0; i < numberOfAttributes; ++i) {
            tuple.add(new Integer(this.r.nextInt()));
            flinkTuple.setField(tuple.get(i), i);
        }
        flinkTuple.setField(taskId, numberOfAttributes);
        final List<Integer> taskIds;
        final Object messageId = new Integer(this.r.nextInt());
        taskIds = collector.emit(streamId, tuple, messageId);
        Assert.assertNull(taskIds);
        verify(flinkCollector).collect(flinkTuple);
    }
}
Also used : HashMap(java.util.HashMap) Values(org.apache.storm.tuple.Values) SourceContext(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext) Tuple(org.apache.flink.api.java.tuple.Tuple) AbstractTest(org.apache.flink.storm.util.AbstractTest) Test(org.junit.Test)

Example 100 with Values

use of org.apache.storm.tuple.Values in project flink by apache.

the class StormTupleTest method testSelect.

@Test
public void testSelect() throws Exception {
    Tuple tuple = Tuple.getTupleClass(arity).newInstance();
    Values values = new Values();
    ArrayList<String> attributeNames = new ArrayList<String>(arity);
    ArrayList<String> filterNames = new ArrayList<String>(arity);
    for (int i = 0; i < arity; ++i) {
        tuple.setField(i, i);
        attributeNames.add("a" + i);
        if (r.nextBoolean()) {
            filterNames.add("a" + i);
            values.add(i);
        }
    }
    Fields schema = new Fields(attributeNames);
    Fields selector = new Fields(filterNames);
    Assert.assertEquals(values, new StormTuple<>(tuple, schema, -1, null, null, null).select(selector));
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) ArrayList(java.util.ArrayList) Tuple(org.apache.flink.api.java.tuple.Tuple) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest)

Aggregations

Values (org.apache.storm.tuple.Values)187 Test (org.junit.Test)80 ArrayList (java.util.ArrayList)42 Fields (org.apache.storm.tuple.Fields)40 HashMap (java.util.HashMap)36 ChannelHandler (org.apache.storm.sql.runtime.ChannelHandler)26 TridentTopology (org.apache.storm.trident.TridentTopology)21 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)14 Stream (org.apache.storm.trident.Stream)12 TupleImpl (org.apache.storm.tuple.TupleImpl)12 TestUtils (org.apache.storm.sql.TestUtils)11 TridentState (org.apache.storm.trident.TridentState)11 List (java.util.List)9 Config (org.apache.storm.Config)9 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)9 Tuple (org.apache.storm.tuple.Tuple)9 Map (java.util.Map)8 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)8 TridentTuple (org.apache.storm.trident.tuple.TridentTuple)8 StateFactory (org.apache.storm.trident.state.StateFactory)7