Search in sources :

Example 21 with CacheEvent

use of org.apache.ignite.events.CacheEvent 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)

Example 22 with CacheEvent

use of org.apache.ignite.events.CacheEvent in project ignite by apache.

the class RocketMQStreamerTest method testStreamer.

/**
     * Tests data is properly injected into the grid.
     *
     * @throws Exception If fails.
     */
public void testStreamer() throws Exception {
    RocketMQStreamer<String, byte[]> streamer = null;
    Ignite ignite = grid();
    try (IgniteDataStreamer<String, byte[]> dataStreamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
        dataStreamer.allowOverwrite(true);
        dataStreamer.autoFlushFrequency(10);
        streamer = new RocketMQStreamer<>();
        //configure.
        streamer.setIgnite(ignite);
        streamer.setStreamer(dataStreamer);
        streamer.setNameSrvAddr(TEST_IP + ":" + NAME_SERVER_PORT);
        streamer.setConsumerGrp(CONSUMER_GRP);
        streamer.setTopic(TOPIC_NAME);
        streamer.setMultipleTupleExtractor(new TestTupleExtractor());
        streamer.start();
        IgniteCache<String, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
        assertEquals(0, cache.size(CachePeekMode.PRIMARY));
        final CountDownLatch latch = new CountDownLatch(EVT_NUM);
        IgniteBiPredicate<UUID, CacheEvent> putLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {

            @Override
            public boolean apply(UUID uuid, CacheEvent evt) {
                assert evt != null;
                latch.countDown();
                return true;
            }
        };
        ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).remoteListen(putLsnr, null, EVT_CACHE_OBJECT_PUT);
        produceData();
        assertTrue(latch.await(30, TimeUnit.SECONDS));
        assertEquals(EVT_NUM, cache.size(CachePeekMode.PRIMARY));
    } finally {
        if (streamer != null)
            streamer.stop();
    }
}
Also used : IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) CacheEvent(org.apache.ignite.events.CacheEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID)

Aggregations

CacheEvent (org.apache.ignite.events.CacheEvent)22 CountDownLatch (java.util.concurrent.CountDownLatch)11 UUID (java.util.UUID)10 Ignite (org.apache.ignite.Ignite)8 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)8 Event (org.apache.ignite.events.Event)5 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)5 HashMap (java.util.HashMap)3 IgniteException (org.apache.ignite.IgniteException)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)2 CacheRebalancingEvent (org.apache.ignite.events.CacheRebalancingEvent)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1 TimeoutException (java.util.concurrent.TimeoutException)1