Search in sources :

Example 41 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheContinuousQueryLostPartitionTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    super.beforeTest();
    startGridsMultiThreaded(2);
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return grid(0).cluster().nodes().size() == 2;
        }
    }, 10000L);
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA)

Example 42 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class CacheContinuousQueryLostPartitionTest method testEvent.

/**
 * @param cacheName Cache name.
 * @throws Exception If failed.
 */
public void testEvent(String cacheName, boolean client) throws Exception {
    IgniteCache<Integer, String> cache1 = grid(0).getOrCreateCache(cacheName);
    final AllEventListener<Integer, String> lsnr1 = registerCacheListener(cache1);
    IgniteCache<Integer, String> cache2 = grid(1).getOrCreateCache(cacheName);
    Integer key = primaryKey(cache1);
    cache1.put(key, "1");
    // Note the issue is only reproducible if the second registration is done right
    // here, after the first put() above.
    AllEventListener<Integer, String> lsnr20;
    if (client) {
        IgniteCache<Integer, String> clnCache = startGrid(3).getOrCreateCache(cacheName);
        lsnr20 = registerCacheListener(clnCache);
    } else
        lsnr20 = registerCacheListener(cache2);
    final AllEventListener<Integer, String> lsnr2 = lsnr20;
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return lsnr1.createdCnt.get() == 1;
        }
    }, 2000L) : "Unexpected number of events: " + lsnr1.createdCnt.get();
    // Sanity check.
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return lsnr2.createdCnt.get() == 0;
        }
    }, 2000L) : "Expected no create events, but got: " + lsnr2.createdCnt.get();
    // node2 now becomes the primary for the key.
    stopGrid(0);
    final int prevSize = grid(1).cluster().nodes().size();
    GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return prevSize - 1 == grid(1).cluster().nodes().size();
        }
    }, 5000L);
    cache2.put(key, "2");
    // Sanity check.
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return lsnr1.createdCnt.get() == 1;
        }
    }, 2000L) : "Expected no change here, but got: " + lsnr1.createdCnt.get();
    // Sanity check.
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return lsnr2.updatedCnt.get() == 0;
        }
    }, 2000L) : "Expected no update events, but got: " + lsnr2.updatedCnt.get();
    System.out.println(">>>>> " + lsnr2.createdCnt.get());
    // This assertion fails: 0 events get delivered.
    assert GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return lsnr2.createdCnt.get() == 1;
        }
    }, 2000L) : "Expected a single event due to '2', but got: " + lsnr2.createdCnt.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PA(org.apache.ignite.internal.util.typedef.PA)

Example 43 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridMessageListenSelfTest method testNullTopicWithDeployment.

/**
 * @throws Exception If failed.
 */
public void testNullTopicWithDeployment() throws Exception {
    Class<?> cls = getExternalClassLoader().loadClass(LSNR_CLS_NAME);
    grid(0).message().remoteListen(null, (IgniteBiPredicate<UUID, Object>) cls.newInstance());
    send();
    boolean s = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return checkDeployedListeners(GRID_CNT);
        }
    }, 2000);
    assertTrue(s);
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) UUID(java.util.UUID)

Example 44 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridMessageListenSelfTest method testNonNullTopicWithDeployment.

/**
 * @throws Exception If failed.
 */
public void testNonNullTopicWithDeployment() throws Exception {
    ClassLoader ldr = getExternalClassLoader();
    Class<?> topicCls = ldr.loadClass(TOPIC_CLS_NAME);
    Class<?> lsnrCls = ldr.loadClass(LSNR_CLS_NAME);
    Object topic = topicCls.newInstance();
    grid(0).message().remoteListen(topic, (IgniteBiPredicate<UUID, Object>) lsnrCls.newInstance());
    send(topic);
    boolean s = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return checkDeployedListeners(GRID_CNT);
        }
    }, 2000);
    assertTrue(s);
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) UUID(java.util.UUID)

Example 45 with PA

use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.

the class GridCacheContinuousQueryAbstractSelfTest method testRestartQuery.

/**
 * @throws Exception If failed.
 */
public void testRestartQuery() throws Exception {
    if (cacheMode() == LOCAL)
        return;
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    final int parts = grid(0).affinity(DEFAULT_CACHE_NAME).partitions();
    final int keyCnt = parts * 2;
    for (int i = 0; i < parts / 2; i++) cache.put(i, i);
    for (int i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            final AtomicInteger cntr = new AtomicInteger(0);
            ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
            qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {

                @Override
                public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
                    for (CacheEntryEvent<? extends Integer, ? extends Integer> ignore : evts) cntr.incrementAndGet();
                }
            });
            QueryCursor<Cache.Entry<Integer, Integer>> qryCur = cache.query(qry);
            for (int key = 0; key < keyCnt; key++) cache.put(key, key);
            try {
                assert GridTestUtils.waitForCondition(new PA() {

                    @Override
                    public boolean apply() {
                        return cntr.get() == keyCnt;
                    }
                }, 2000L);
            } finally {
                qryCur.close();
            }
        } else {
            for (int key = 0; key < keyCnt; key++) cache.put(key, key);
        }
    }
}
Also used : CacheEntryEvent(javax.cache.event.CacheEntryEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PA(org.apache.ignite.internal.util.typedef.PA) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

PA (org.apache.ignite.internal.util.typedef.PA)55 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 Ignite (org.apache.ignite.Ignite)20 ArrayList (java.util.ArrayList)14 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)13 UUID (java.util.UUID)9 CacheEntryEvent (javax.cache.event.CacheEntryEvent)9 IgniteException (org.apache.ignite.IgniteException)7 QueryCursor (org.apache.ignite.cache.query.QueryCursor)7 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 IgniteCache (org.apache.ignite.IgniteCache)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 Transaction (org.apache.ignite.transactions.Transaction)5 Callable (java.util.concurrent.Callable)4