Search in sources :

Example 1 with FeederSpout

use of backtype.storm.testing.FeederSpout in project storm-lib by xumingming.

the class TestingApiDemo method ackTrackingFeeder.

public static FeederSpout ackTrackingFeeder(AckTracker tracker, String... fields) {
    FeederSpout feeder = createFeederSpout(fields);
    feeder.setAckFailDelegate(tracker);
    return feeder;
}
Also used : FeederSpout(backtype.storm.testing.FeederSpout)

Example 2 with FeederSpout

use of backtype.storm.testing.FeederSpout in project jstorm by alibaba.

the class SingleJoinTest method test_single_join.

@Test
public void test_single_join() {
    receiveCounter.set(0);
    try {
        FeederSpout genderSpout = new FeederSpout(new Fields("id", "gender"));
        FeederSpout ageSpout = new FeederSpout(new Fields("id", "age"));
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout("gender", genderSpout);
        builder.setSpout("age", ageSpout);
        builder.setBolt("join", new SingleJoinBolt(new Fields("gender", "age"))).fieldsGrouping("gender", new Fields("id")).fieldsGrouping("age", new Fields("id"));
        Config conf = new Config();
        conf.setDebug(true);
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("join-example", conf, builder.createTopology());
        for (int i = 0; i < 10; i++) {
            String gender;
            if (i % 2 == 0) {
                gender = "male";
            } else {
                gender = "female";
            }
            genderSpout.feed(new Values(i, gender));
        }
        for (int i = 9; i >= 0; i--) {
            ageSpout.feed(new Values(i, i + 20));
        }
        JStormUtils.sleepMs(60 * 1000);
        assertNotSame(0, receiveCounter.get());
        cluster.shutdown();
    } catch (Exception e) {
        Assert.fail("Failed to run SingleJoinExample");
    }
}
Also used : LocalCluster(backtype.storm.LocalCluster) Fields(backtype.storm.tuple.Fields) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) Values(backtype.storm.tuple.Values) FeederSpout(backtype.storm.testing.FeederSpout) Test(org.junit.Test)

Example 3 with FeederSpout

use of backtype.storm.testing.FeederSpout in project storm-lib by xumingming.

the class TestingApiDemo method testTimeout.

public void testTimeout() {
    Config daemonConfig = new Config();
    daemonConfig.put(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true);
    MkClusterParam mkClusterParam = new MkClusterParam();
    mkClusterParam.setDaemonConf(daemonConfig);
    Testing.withSimulatedTimeLocalCluster(mkClusterParam, new TestJob() {

        @Override
        public void run(ILocalCluster cluster) {
            AckFailMapTracker tracker = new AckFailMapTracker();
            FeederSpout feeder = createFeederSpout("field1");
            feeder.setAckFailDelegate(tracker);
            TopologyBuilder builder = new TopologyBuilder();
            builder.setSpout("1", feeder);
            builder.setBolt("2", new AckEveryOtherBolt()).globalGrouping("1");
            StormTopology topology = builder.createTopology();
            Config topologyConfig = new Config();
            topologyConfig.setMessageTimeoutSecs(10);
            /**
				 * TODO
				 */
            try {
                cluster.submitTopology("timeout-tester", topologyConfig, topology);
            } catch (AlreadyAliveException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidTopologyException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            feeder.feed(new Values("a"), 1);
            feeder.feed(new Values("b"), 2);
            feeder.feed(new Values("c"), 3);
            /**
				 * TODO
				 */
            Testing.advanceClusterTime(cluster, 9);
            assertAcked(tracker, 1, 3);
            assertFalse(tracker.isFailed(2));
            Testing.advanceClusterTime(cluster, 12);
            assertFailed(tracker, 2);
        }
    });
}
Also used : TestJob(backtype.storm.testing.TestJob) TopologyBuilder(backtype.storm.topology.TopologyBuilder) Config(backtype.storm.Config) AckFailMapTracker(backtype.storm.testing.AckFailMapTracker) StormTopology(backtype.storm.generated.StormTopology) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) Values(backtype.storm.tuple.Values) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) MkClusterParam(backtype.storm.testing.MkClusterParam) ILocalCluster(backtype.storm.ILocalCluster) FeederSpout(backtype.storm.testing.FeederSpout)

Aggregations

FeederSpout (backtype.storm.testing.FeederSpout)3 Config (backtype.storm.Config)2 TopologyBuilder (backtype.storm.topology.TopologyBuilder)2 Values (backtype.storm.tuple.Values)2 ILocalCluster (backtype.storm.ILocalCluster)1 LocalCluster (backtype.storm.LocalCluster)1 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)1 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)1 StormTopology (backtype.storm.generated.StormTopology)1 AckFailMapTracker (backtype.storm.testing.AckFailMapTracker)1 MkClusterParam (backtype.storm.testing.MkClusterParam)1 TestJob (backtype.storm.testing.TestJob)1 Fields (backtype.storm.tuple.Fields)1 Test (org.junit.Test)1