Search in sources :

Example 91 with Event

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

the class TcpDiscoveryNodeAttributesUpdateOnReconnectTest method testReconnect.

/**
     * @throws Exception If failed.
     */
public void testReconnect() throws Exception {
    Ignite srv = startGrid("server");
    IgniteEvents evts = srv.events();
    evts.enableLocal(EventType.EVTS_DISCOVERY_ALL);
    evts.localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            ClusterNode node = ((DiscoveryEvent) evt).eventNode();
            rejoinAttr = node.attribute("test");
            return true;
        }
    }, EventType.EVT_NODE_JOINED);
    Ignite client = startGrid("client");
    reconnectClientNode(log, client, srv, null);
    assertEquals("2", rejoinAttr);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteEvents(org.apache.ignite.IgniteEvents) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 92 with Event

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

the class TcpDiscoverySelfTest method testCoordinatorNodeFailure.

/**
     * @throws Exception If any error occurs.
     */
public void testCoordinatorNodeFailure() throws Exception {
    try {
        Ignite g1 = startGrid(1);
        Ignite g2 = startGrid(2);
        final CountDownLatch cnt = new CountDownLatch(1);
        g2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                cnt.countDown();
                return true;
            }
        }, EventType.EVT_NODE_FAILED);
        info("Nodes were started");
        discoMap.get(g1.name()).simulateNodeFailure();
        assert cnt.await(20, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 93 with Event

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

the class TcpDiscoverySelfTest method testNodeAdded.

/**
     * @throws Exception If any error occurs.
     */
public void testNodeAdded() throws Exception {
    try {
        final Ignite g1 = startGrid(1);
        final CountDownLatch cnt = new CountDownLatch(2);
        g1.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info("Node joined: " + evt.message());
                DiscoveryEvent discoEvt = (DiscoveryEvent) evt;
                TcpDiscoveryNode node = ((TcpDiscoveryNode) discoMap.get(g1.name()).getNode(discoEvt.eventNode().id()));
                assert node != null && node.visible();
                cnt.countDown();
                return true;
            }
        }, EventType.EVT_NODE_JOINED);
        startGrid(2);
        startGrid(3);
        info("Nodes were started");
        assert cnt.await(1, SECONDS);
    } finally {
        stopAllGrids();
    }
}
Also used : Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Example 94 with Event

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

the class TcpDiscoveryRestartTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi spi = new TcpDiscoverySpi();
    spi.setIpFinder(ipFinder);
    cfg.setDiscoverySpi(spi);
    int[] evts = { EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT };
    cfg.setIncludeEventTypes(evts);
    Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();
    lsnrs.put(new TestEventListener(), evts);
    cfg.setLocalEventListeners(lsnrs);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event)

Example 95 with Event

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

the class IgniteSinkConnectorTest method testSinkPuts.

/**
     * Tests the whole data flow from injecting data to Kafka to transferring it to the grid. It reads from two
     * specified Kafka topics, because a sink task can read from multiple topics.
     *
     * @param sinkProps Sink properties.
     * @param keyless Tests on Kafka stream with null keys if true.
     * @throws Exception Thrown in case of the failure.
     */
private void testSinkPuts(Map<String, String> sinkProps, boolean keyless) throws Exception {
    FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>(new Callback<Herder.Created<ConnectorInfo>>() {

        @Override
        public void onCompletion(Throwable error, Herder.Created<ConnectorInfo> info) {
            if (error != null)
                throw new RuntimeException("Failed to create a job!");
        }
    });
    herder.putConnectorConfig(sinkProps.get(ConnectorConfig.NAME_CONFIG), sinkProps, false, cb);
    cb.get();
    final CountDownLatch latch = new CountDownLatch(EVENT_CNT * TOPICS.length);
    final IgnitePredicate<Event> putLsnr = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assert evt != null;
            latch.countDown();
            return true;
        }
    };
    grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).localListen(putLsnr, EVT_CACHE_OBJECT_PUT);
    IgniteCache<String, String> cache = grid.cache(CACHE_NAME);
    assertEquals(0, cache.size(CachePeekMode.PRIMARY));
    Map<String, String> keyValMap = new HashMap<>(EVENT_CNT * TOPICS.length);
    // Produces events for the specified number of topics
    for (String topic : TOPICS) keyValMap.putAll(produceStream(topic, keyless));
    // Checks all events successfully processed in 10 seconds.
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    grid.events(grid.cluster().forCacheNodes(CACHE_NAME)).stopLocalListen(putLsnr);
    // Checks that each event was processed properly.
    for (Map.Entry<String, String> entry : keyValMap.entrySet()) assertEquals(entry.getValue(), cache.get(entry.getKey()));
    assertEquals(EVENT_CNT * TOPICS.length, cache.size(CachePeekMode.PRIMARY));
}
Also used : ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CountDownLatch(java.util.concurrent.CountDownLatch) Event(org.apache.ignite.events.Event) Herder(org.apache.kafka.connect.runtime.Herder) StandaloneHerder(org.apache.kafka.connect.runtime.standalone.StandaloneHerder) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) FutureCallback(org.apache.kafka.connect.util.FutureCallback)

Aggregations

Event (org.apache.ignite.events.Event)210 CountDownLatch (java.util.concurrent.CountDownLatch)117 Ignite (org.apache.ignite.Ignite)104 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)88 UUID (java.util.UUID)66 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)43 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ClusterNode (org.apache.ignite.cluster.ClusterNode)35 JobEvent (org.apache.ignite.events.JobEvent)27 ArrayList (java.util.ArrayList)26 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)25 IgniteException (org.apache.ignite.IgniteException)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 HashSet (java.util.HashSet)15 TaskEvent (org.apache.ignite.events.TaskEvent)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 Collection (java.util.Collection)13 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)12 HashMap (java.util.HashMap)11 CacheException (javax.cache.CacheException)11