Search in sources :

Example 1 with ILocalCluster

use of org.apache.storm.ILocalCluster in project storm by apache.

the class LocalNimbusTest method testSubmitTopologyToLocalNimbus.

@Test
public void testSubmitTopologyToLocalNimbus() throws Exception {
    HashMap<String, Object> localClusterConf = new HashMap<>();
    localClusterConf.put("nimbus-daemon", true);
    ILocalCluster localCluster = Testing.getLocalCluster(localClusterConf);
    Config stormConf = new Config();
    stormConf.putAll(Utils.readDefaultConfig());
    stormConf.setDebug(true);
    // default is aways "distributed" but here local cluster is being used.
    stormConf.put("storm.cluster.mode", "local");
    stormConf.put(Config.STORM_TOPOLOGY_SUBMISSION_NOTIFIER_PLUGIN, InmemoryTopologySubmitterHook.class.getName());
    List<TopologyDetails> topologyNames = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        final String topologyName = "word-count-" + UUID.randomUUID().toString();
        final StormTopology stormTopology = createTestTopology();
        topologyNames.add(new TopologyDetails(topologyName, stormTopology));
        localCluster.submitTopology(topologyName, stormConf, stormTopology);
    }
    Assert.assertEquals(InmemoryTopologySubmitterHook.submittedTopologies, topologyNames);
    localCluster.shutdown();
}
Also used : ILocalCluster(org.apache.storm.ILocalCluster) HashMap(java.util.HashMap) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ILocalCluster

use of org.apache.storm.ILocalCluster in project ignite by apache.

the class StormIgniteStreamerSelfTest method testStormStreamerIgniteBolt.

/**
     * Tests for the streamer bolt. Ignite started in bolt based on what is specified in the configuration file.
     *
     * @throws TimeoutException
     * @throws InterruptedException
     */
public void testStormStreamerIgniteBolt() throws TimeoutException, InterruptedException {
    final StormStreamer<String, String> stormStreamer = new StormStreamer<>();
    stormStreamer.setAutoFlushFrequency(10L);
    stormStreamer.setAllowOverwrite(true);
    stormStreamer.setCacheName(TEST_CACHE);
    stormStreamer.setIgniteTupleField(TestStormSpout.IGNITE_TUPLE_FIELD);
    stormStreamer.setIgniteConfigFile(GRID_CONF_FILE);
    Config daemonConf = new Config();
    daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, false);
    MkClusterParam mkClusterParam = new MkClusterParam();
    mkClusterParam.setDaemonConf(daemonConf);
    mkClusterParam.setSupervisors(4);
    final CountDownLatch latch = new CountDownLatch(TestStormSpout.CNT);
    IgniteBiPredicate<UUID, CacheEvent> putLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {

        @Override
        public boolean apply(UUID uuid, CacheEvent evt) {
            assert evt != null;
            latch.countDown();
            return true;
        }
    };
    final UUID putLsnrId = ignite.events(ignite.cluster().forCacheNodes(TEST_CACHE)).remoteListen(putLsnr, null, EVT_CACHE_OBJECT_PUT);
    Testing.withSimulatedTimeLocalCluster(mkClusterParam, new TestJob() {

        @Override
        public void run(ILocalCluster cluster) throws IOException, InterruptedException {
            // Creates a test topology.
            TopologyBuilder builder = new TopologyBuilder();
            TestStormSpout testStormSpout = new TestStormSpout();
            builder.setSpout("test-spout", testStormSpout);
            builder.setBolt("ignite-bolt", stormStreamer, STORM_EXECUTORS).shuffleGrouping("test-spout");
            StormTopology topology = builder.createTopology();
            // Prepares a mock data for the spout.
            MockedSources mockedSources = new MockedSources();
            mockedSources.addMockData("test-spout", getMockData());
            // Prepares the config.
            Config conf = new Config();
            conf.setMessageTimeoutSecs(10);
            IgniteCache<Integer, String> cache = ignite.cache(TEST_CACHE);
            CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
            completeTopologyParam.setTimeoutMs(10000);
            completeTopologyParam.setMockedSources(mockedSources);
            completeTopologyParam.setStormConf(conf);
            // Checks the cache doesn't contain any entries yet.
            assertEquals(0, cache.size(CachePeekMode.PRIMARY));
            Testing.completeTopology(cluster, topology, completeTopologyParam);
            // Checks events successfully processed in 20 seconds.
            assertTrue(latch.await(10, TimeUnit.SECONDS));
            ignite.events(ignite.cluster().forCacheNodes(TEST_CACHE)).stopRemoteListen(putLsnrId);
            // Validates all entries are in the cache.
            assertEquals(TestStormSpout.CNT, cache.size(CachePeekMode.PRIMARY));
            for (Map.Entry<Integer, String> entry : TestStormSpout.getKeyValMap().entrySet()) assertEquals(entry.getValue(), cache.get(entry.getKey()));
        }
    });
}
Also used : TestJob(org.apache.storm.testing.TestJob) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) IgniteCache(org.apache.ignite.IgniteCache) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) MkClusterParam(org.apache.storm.testing.MkClusterParam) ILocalCluster(org.apache.storm.ILocalCluster) MockedSources(org.apache.storm.testing.MockedSources) CompleteTopologyParam(org.apache.storm.testing.CompleteTopologyParam) CacheEvent(org.apache.ignite.events.CacheEvent) UUID(java.util.UUID)

Aggregations

Config (org.apache.storm.Config)2 ILocalCluster (org.apache.storm.ILocalCluster)2 StormTopology (org.apache.storm.generated.StormTopology)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 IgniteCache (org.apache.ignite.IgniteCache)1 CacheEvent (org.apache.ignite.events.CacheEvent)1 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)1 CompleteTopologyParam (org.apache.storm.testing.CompleteTopologyParam)1 MkClusterParam (org.apache.storm.testing.MkClusterParam)1 MockedSources (org.apache.storm.testing.MockedSources)1 TestJob (org.apache.storm.testing.TestJob)1 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)1 Test (org.junit.Test)1