Search in sources :

Example 46 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheContinuousQueryFailoverAbstractSelfTest method waitRebalanceFinished.

/**
 * @param ignite Ignite.
 * @param topVer Major topology version.
 * @param minorVer Minor topology version.
 * @throws Exception If failed.
 */
private void waitRebalanceFinished(Ignite ignite, long topVer, int minorVer) throws Exception {
    final AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(topVer, minorVer);
    final GridDhtPartitionTopology top = ((IgniteKernal) ignite).context().cache().context().cacheContext(CU.cacheId(DEFAULT_CACHE_NAME)).topology();
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return top.rebalanceFinished(topVer0);
        }
    }, 5000);
    assertTrue(top.rebalanceFinished(topVer0));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 47 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheContinuousQueryFailoverAbstractSelfTest method testBackupQueueCleanupServerQuery.

/**
 * @throws Exception If failed.
 */
public void testBackupQueueCleanupServerQuery() throws Exception {
    Ignite qryClient = startGridsMultiThreaded(2);
    CacheEventListener1 lsnr = new CacheEventListener1(false);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(lsnr);
    IgniteCache<Object, Object> cache = qryClient.cache(DEFAULT_CACHE_NAME);
    QueryCursor<?> cur = cache.query(qry);
    assertEquals(0, backupQueue(ignite(1)).size());
    List<Integer> keys = primaryKeys(cache, BACKUP_ACK_THRESHOLD);
    CountDownLatch latch = new CountDownLatch(keys.size());
    lsnr.latch = latch;
    for (Integer key : keys) {
        log.info("Put: " + key);
        cache.put(key, key);
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return backupQueue(ignite(1)).isEmpty();
        }
    }, 5000);
    assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)), backupQueue(ignite(1)).size() < BACKUP_ACK_THRESHOLD);
    if (!latch.await(5, SECONDS))
        fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
    cur.close();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 48 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheContinuousQueryFailoverAbstractSelfTest method testBackupQueueCleanupClientQuery.

/**
 * @throws Exception If failed.
 */
public void testBackupQueueCleanupClientQuery() throws Exception {
    startGridsMultiThreaded(2);
    client = true;
    Ignite qryClient = startGrid(2);
    CacheEventListener1 lsnr = new CacheEventListener1(false);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(lsnr);
    QueryCursor<?> cur = qryClient.cache(DEFAULT_CACHE_NAME).query(qry);
    assertEquals(0, backupQueue(ignite(1)).size());
    IgniteCache<Object, Object> cache0 = ignite(0).cache(DEFAULT_CACHE_NAME);
    List<Integer> keys = primaryKeys(cache0, BACKUP_ACK_THRESHOLD);
    CountDownLatch latch = new CountDownLatch(keys.size());
    lsnr.latch = latch;
    for (Integer key : keys) {
        log.info("Put: " + key);
        cache0.put(key, key);
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return backupQueue(ignite(1)).isEmpty();
        }
    }, 2000);
    assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)), backupQueue(ignite(1)).size() < BACKUP_ACK_THRESHOLD);
    if (!latch.await(5, SECONDS))
        fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
    keys = primaryKeys(cache0, BACKUP_ACK_THRESHOLD / 2);
    latch = new CountDownLatch(keys.size());
    lsnr.latch = latch;
    for (Integer key : keys) cache0.put(key, key);
    final long ACK_FREQ = 5000;
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return backupQueue(ignite(1)).isEmpty();
        }
    }, ACK_FREQ + 2000);
    assertTrue("Backup queue is not cleared: " + backupQueue(ignite(1)), backupQueue(ignite(1)).isEmpty());
    if (!latch.await(5, SECONDS))
        fail("Failed to wait for notifications [exp=" + keys.size() + ", left=" + lsnr.latch.getCount() + ']');
    cur.close();
    assertFalse("Unexpected error during test, see log for details.", err);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite)

Example 49 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheContinuousQueryFailoverAbstractSelfTest method testFirstFilteredEvent.

/**
 * @throws Exception If failed.
 */
public void testFirstFilteredEvent() throws Exception {
    this.backups = 2;
    final int SRV_NODES = 4;
    startGridsMultiThreaded(SRV_NODES);
    client = true;
    Ignite qryClient = startGrid(SRV_NODES);
    client = false;
    IgniteCache<Object, Object> qryClnCache = qryClient.cache(DEFAULT_CACHE_NAME);
    final CacheEventListener3 lsnr = new CacheEventListener3();
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(lsnr);
    qry.setRemoteFilter(new CacheEventFilter());
    try (QueryCursor<?> cur = qryClnCache.query(qry)) {
        List<Integer> keys = testKeys(grid(0).cache(DEFAULT_CACHE_NAME), 1);
        for (Integer key : keys) qryClnCache.put(key, -1);
        qryClnCache.put(keys.get(0), 100);
        GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                return lsnr.evts.size() == 1;
            }
        }, 5000);
        assertEquals(lsnr.evts.size(), 1);
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite)

Example 50 with GridAbsPredicate

use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.

the class CacheContinuousQueryFailoverAbstractSelfTest method testBackupQueueEvict.

/**
 * @throws Exception If failed.
 */
public void testBackupQueueEvict() throws Exception {
    startGridsMultiThreaded(2);
    client = true;
    Ignite qryClient = startGrid(2);
    CacheEventListener1 lsnr = new CacheEventListener1(false);
    ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
    qry.setLocalListener(lsnr);
    QueryCursor<?> cur = qryClient.cache(DEFAULT_CACHE_NAME).query(qry);
    assertEquals(0, backupQueue(ignite(0)).size());
    long ttl = 100;
    final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
    final IgniteCache<Object, Object> cache0 = ignite(2).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry);
    final List<Integer> keys = primaryKeys(ignite(1).cache(DEFAULT_CACHE_NAME), BACKUP_ACK_THRESHOLD);
    lsnr.latch = new CountDownLatch(keys.size());
    for (Integer key : keys) {
        log.info("Put: " + key);
        cache0.put(key, key);
    }
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return backupQueue(ignite(0)).isEmpty();
        }
    }, 5000);
    assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)), backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
    boolean wait = waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return cache0.localPeek(keys.get(0)) == null;
        }
    }, ttl + 1000);
    assertTrue("Entry evicted.", wait);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return backupQueue(ignite(0)).isEmpty();
        }
    }, 2000);
    assertTrue("Backup queue is not cleared: " + backupQueue(ignite(0)), backupQueue(ignite(0)).size() < BACKUP_ACK_THRESHOLD);
    if (backupQueue(ignite(0)).size() != 0) {
        for (Object o : backupQueue(ignite(0))) {
            CacheContinuousQueryEntry e = (CacheContinuousQueryEntry) o;
            assertNotSame("Evicted entry added to backup queue.", -1L, e.updateCounter());
        }
    }
    cur.close();
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Duration(javax.cache.expiry.Duration) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Ignite(org.apache.ignite.Ignite) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy)

Aggregations

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)175 Ignite (org.apache.ignite.Ignite)81 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ClusterNode (org.apache.ignite.cluster.ClusterNode)32 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 IgniteException (org.apache.ignite.IgniteException)22 CountDownLatch (java.util.concurrent.CountDownLatch)20 IgniteKernal (org.apache.ignite.internal.IgniteKernal)19 ArrayList (java.util.ArrayList)18 IgniteCache (org.apache.ignite.IgniteCache)16 Map (java.util.Map)15 Transaction (org.apache.ignite.transactions.Transaction)15 IgniteEx (org.apache.ignite.internal.IgniteEx)14 Duration (javax.cache.expiry.Duration)13 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)13 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)11 Event (org.apache.ignite.events.Event)11