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));
}
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();
}
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);
}
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);
}
}
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();
}
Aggregations