Search in sources :

Example 1 with IComponent

use of org.apache.storm.topology.IComponent in project flink by apache.

the class WrapperSetupHelperTest method testRawType.

@Test(expected = IllegalArgumentException.class)
public void testRawType() throws Exception {
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    declarer.declare(new Fields("dummy1", "dummy2"));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)));
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) Fields(org.apache.storm.tuple.Fields) IComponent(org.apache.storm.topology.IComponent) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with IComponent

use of org.apache.storm.topology.IComponent in project flink by apache.

the class WrapperSetupHelperTest method testEmptyDeclarerBolt.

@Test
public void testEmptyDeclarerBolt() {
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    Assert.assertEquals(new HashMap<String, Integer>(), WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, null));
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) IComponent(org.apache.storm.topology.IComponent) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with IComponent

use of org.apache.storm.topology.IComponent in project storm by apache.

the class StreamBuilder method addSink.

private void addSink(TopologyBuilder topologyBuilder, SinkNode sinkNode) {
    IComponent bolt = sinkNode.getBolt();
    BoltDeclarer boltDeclarer;
    if (bolt instanceof IRichBolt) {
        boltDeclarer = topologyBuilder.setBolt(sinkNode.getComponentId(), (IRichBolt) bolt, sinkNode.getParallelism());
    } else if (bolt instanceof IBasicBolt) {
        boltDeclarer = topologyBuilder.setBolt(sinkNode.getComponentId(), (IBasicBolt) bolt, sinkNode.getParallelism());
    } else {
        throw new IllegalArgumentException("Expect IRichBolt or IBasicBolt in addBolt");
    }
    for (Node parent : parentNodes(sinkNode)) {
        for (String stream : sinkNode.getParentStreams(parent)) {
            declareGrouping(boltDeclarer, parent, stream, nodeGroupingInfo.get(parent, stream));
        }
    }
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IComponent(org.apache.storm.topology.IComponent) IBasicBolt(org.apache.storm.topology.IBasicBolt)

Example 4 with IComponent

use of org.apache.storm.topology.IComponent in project flink by apache.

the class WrapperSetupHelperTest method testTupleTypes.

private void testTupleTypes(final int numberOfAttributes) throws Exception {
    String[] schema;
    if (numberOfAttributes == -1) {
        schema = new String[1];
    } else {
        schema = new String[numberOfAttributes];
    }
    for (int i = 0; i < schema.length; ++i) {
        schema[i] = "a" + i;
    }
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    declarer.declare(new Fields(schema));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    HashMap<String, Integer> attributes = new HashMap<String, Integer>();
    attributes.put(Utils.DEFAULT_STREAM_ID, numberOfAttributes);
    Assert.assertEquals(attributes, WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, numberOfAttributes == -1 ? new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)) : null));
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) Fields(org.apache.storm.tuple.Fields) HashMap(java.util.HashMap) IComponent(org.apache.storm.topology.IComponent)

Example 5 with IComponent

use of org.apache.storm.topology.IComponent in project flink by apache.

the class WrapperSetupHelperTest method testToManyAttributes.

@Test(expected = IllegalArgumentException.class)
public void testToManyAttributes() throws Exception {
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    final String[] schema = new String[26];
    for (int i = 0; i < schema.length; ++i) {
        schema[i] = "a" + i;
    }
    declarer.declare(new Fields(schema));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, null);
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) Fields(org.apache.storm.tuple.Fields) IComponent(org.apache.storm.topology.IComponent) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

IComponent (org.apache.storm.topology.IComponent)6 IRichBolt (org.apache.storm.topology.IRichBolt)6 AbstractTest (org.apache.flink.storm.util.AbstractTest)4 IRichSpout (org.apache.storm.topology.IRichSpout)4 Test (org.junit.Test)4 Fields (org.apache.storm.tuple.Fields)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 HashMap (java.util.HashMap)1 FlinkTopology (org.apache.flink.storm.api.FlinkTopology)1 TestDummyBolt (org.apache.flink.storm.util.TestDummyBolt)1 TestDummySpout (org.apache.flink.storm.util.TestDummySpout)1 TestSink (org.apache.flink.storm.util.TestSink)1 StreamingRuntimeContext (org.apache.flink.streaming.api.operators.StreamingRuntimeContext)1 Config (org.apache.storm.Config)1 LocalCluster (org.apache.storm.LocalCluster)1 ComponentCommon (org.apache.storm.generated.ComponentCommon)1 StormTopology (org.apache.storm.generated.StormTopology)1 TopologyContext (org.apache.storm.task.TopologyContext)1 BoltDeclarer (org.apache.storm.topology.BoltDeclarer)1 IBasicBolt (org.apache.storm.topology.IBasicBolt)1