use of backtype.storm.testing.MkClusterParam in project storm-lib by xumingming.
the class TestingApiDemo method testBasicTopology.
public void testBasicTopology() {
MkClusterParam mkClusterParam = new MkClusterParam();
mkClusterParam.setSupervisors(4);
Config daemonConf = new Config();
daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, false);
mkClusterParam.setDaemonConf(daemonConf);
/**
* This is a combination of <code>Testing.withLocalCluster</code> and <code>Testing.withSimulatedTime</code>.
*/
Testing.withSimulatedTimeLocalCluster(mkClusterParam, new TestJob() {
@Override
public void run(ILocalCluster cluster) {
// build the test topology
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("1", new TestWordSpout(true), 3);
builder.setBolt("2", new TestWordCounter(), 4).fieldsGrouping("1", new Fields("word"));
builder.setBolt("3", new TestGlobalCount()).globalGrouping("1");
builder.setBolt("4", new TestAggregatesCounter()).globalGrouping("2");
StormTopology topology = builder.createTopology();
// complete the topology
// prepare the mock data
MockedSources mockedSources = new MockedSources();
mockedSources.addMockData("1", new Values("nathan"), new Values("bob"), new Values("joey"), new Values("nathan"));
// prepare the config
Config conf = new Config();
conf.setNumWorkers(2);
CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
completeTopologyParam.setMockedSources(mockedSources);
completeTopologyParam.setStormConf(conf);
/**
* TODO
*/
Map result = Testing.completeTopology(cluster, topology, completeTopologyParam);
// check whether the result is right
assertTrue(Testing.multiseteq(new Values(new Values("nathan"), new Values("bob"), new Values("joey"), new Values("nathan")), Testing.readTuples(result, "1")));
assertTrue(Testing.multiseteq(new Values(new Values("nathan", 1), new Values("nathan", 2), new Values("bob", 1), new Values("joey", 1)), Testing.readTuples(result, "2")));
assertTrue(Testing.multiseteq(new Values(new Values(1), new Values(2), new Values(3), new Values(4)), Testing.readTuples(result, "3")));
assertTrue(Testing.multiseteq(new Values(new Values(1), new Values(2), new Values(3), new Values(4)), Testing.readTuples(result, "4")));
}
});
}
use of backtype.storm.testing.MkClusterParam in project storm-lib by xumingming.
the class TestingApiDemo method testWithLocalCluster.
public void testWithLocalCluster() {
MkClusterParam mkClusterParam = new MkClusterParam();
mkClusterParam.setSupervisors(2);
mkClusterParam.setPortsPerSupervisor(5);
Config daemonConf = new Config();
daemonConf.put(Config.SUPERVISOR_ENABLE, false);
daemonConf.put(Config.TOPOLOGY_ACKER_EXECUTORS, 0);
/**
* when testing your topology, you need a <code>LocalCluster</code> to run your topologies, you need
* to create it, after using it, you need to stop it. Using <code>Testing.withLocalCluster</code> you
* don't need to do any of this, just use the <code>cluster</code> provided through the param of
* <code>TestJob.run</code>.
*/
Testing.withLocalCluster(mkClusterParam, new TestJob() {
@Override
public void run(ILocalCluster cluster) {
assertNotNull(cluster.getState());
}
});
}
use of backtype.storm.testing.MkClusterParam 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);
}
});
}
Aggregations