Search in sources :

Example 16 with IgnitePredicate

use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.

the class IgniteTopologyPrintFormatSelfTest method doServerAndClientTest.

/**
     * @param log Log.
     * @throws Exception If failed.
     */
private void doServerAndClientTest(MockLogger log) throws Exception {
    try {
        Ignite server = startGrid("server");
        setLogger(log, server);
        Ignite server1 = startGrid("server1");
        Ignite client1 = startGrid("first client");
        Ignite client2 = startGrid("second client");
        waitForDiscovery(server, server1, client1, client2);
    } finally {
        stopAllGrids();
    }
    assertTrue(F.forAny(log.logs(), new IgnitePredicate<String>() {

        @Override
        public boolean apply(String s) {
            return s.contains("Topology snapshot [ver=4, servers=2, clients=2,") || (s.contains(">>> Number of server nodes: 2") && s.contains(">>> Number of client nodes: 2"));
        }
    }));
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Ignite(org.apache.ignite.Ignite)

Example 17 with IgnitePredicate

use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.

the class IgniteTopologyPrintFormatSelfTest method doForceServerAndClientTest.

/**
     * @param log Log.
     * @throws Exception If failed.
     */
private void doForceServerAndClientTest(MockLogger log) throws Exception {
    try {
        Ignite server = startGrid("server");
        setLogger(log, server);
        Ignite server1 = startGrid("server1");
        Ignite client1 = startGrid("first client");
        Ignite client2 = startGrid("second client");
        Ignite forceServClnt3 = startGrid("third client_force_server");
        waitForDiscovery(server, server1, client1, client2, forceServClnt3);
    } finally {
        stopAllGrids();
    }
    assertTrue(F.forAny(log.logs(), new IgnitePredicate<String>() {

        @Override
        public boolean apply(String s) {
            return s.contains("Topology snapshot [ver=5, servers=2, clients=3,") || (s.contains(">>> Number of server nodes: 2") && s.contains(">>> Number of client nodes: 3"));
        }
    }));
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Ignite(org.apache.ignite.Ignite)

Example 18 with IgnitePredicate

use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.

the class GridCacheOrderedPreloadingSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setCacheConfiguration(cacheConfig(firstCacheMode, 1, FIRST_CACHE_NAME), cacheConfig(secondCacheMode, 2, SECOND_CACHE_NAME));
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    discoSpi.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(discoSpi);
    Map<IgnitePredicate<? extends Event>, int[]> listeners = new HashMap<>();
    listeners.put(new IgnitePredicate<CacheRebalancingEvent>() {

        @Override
        public boolean apply(CacheRebalancingEvent event) {
            times.get(gridIdx(event)).putIfAbsent(event.cacheName(), event.timestamp());
            return true;
        }
    }, new int[] { EventType.EVT_CACHE_REBALANCE_STOPPED });
    cfg.setLocalEventListeners(listeners);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) CacheRebalancingEvent(org.apache.ignite.events.CacheRebalancingEvent) CacheRebalancingEvent(org.apache.ignite.events.CacheRebalancingEvent) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 19 with IgnitePredicate

use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.

the class OffheapCacheMetricsForClusterGroupSelfTest method awaitMetricsUpdate.

/**
     * Wait for {@link EventType#EVT_NODE_METRICS_UPDATED} event will be receieved.
     */
private void awaitMetricsUpdate() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch((GRID_CNT + 1) * 2);
    IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event ignore) {
            latch.countDown();
            return true;
        }
    };
    for (int i = 0; i < GRID_CNT; i++) grid("server-" + i).events().localListen(lsnr, EVT_NODE_METRICS_UPDATED);
    latch.await();
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 20 with IgnitePredicate

use of org.apache.ignite.lang.IgnitePredicate in project ignite by apache.

the class PartitionsExchangeOnDiscoveryHistoryOverflowTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);
    Map<IgnitePredicate<? extends Event>, int[]> map = new HashMap<>();
    // To make partitions exchanges longer.
    map.put(new P1<Event>() {

        @Override
        public boolean apply(Event evt) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
            // No op.
            }
            return false;
        }
    }, new int[] { EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_DISCOVERY_CUSTOM_EVT });
    cfg.setLocalEventListeners(map);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HashMap(java.util.HashMap) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) Event(org.apache.ignite.events.Event)

Aggregations

IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)75 Event (org.apache.ignite.events.Event)43 CountDownLatch (java.util.concurrent.CountDownLatch)33 Ignite (org.apache.ignite.Ignite)27 ArrayList (java.util.ArrayList)15 UUID (java.util.UUID)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 IgfsEvent (org.apache.ignite.events.IgfsEvent)9 HashMap (java.util.HashMap)8 CacheEvent (org.apache.ignite.events.CacheEvent)7 CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)7 IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)7 Map (java.util.Map)6 IgniteException (org.apache.ignite.IgniteException)6 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 CacheQueryReadEvent (org.apache.ignite.events.CacheQueryReadEvent)6 IgniteBiPredicate (org.apache.ignite.lang.IgniteBiPredicate)6 Ignition (org.apache.ignite.Ignition)5