use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method checkTtl.
/**
* @param inTx In tx flag.
* @param oldEntry {@code True} to check TTL on old entry, {@code false} on new.
* @throws Exception If failed.
*/
private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
// TODO GG-11133.
if (true)
return;
int ttl = 1000;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
final IgniteCache<String, Integer> c = jcache();
final String key = primaryKeysForCache(jcache(), 1).get(0);
IgnitePair<Long> entryTtl;
if (oldEntry) {
c.put(key, 1);
entryTtl = entryTtl(fullCache(), key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals((Long) 0L, entryTtl.get1());
assertEquals((Long) 0L, entryTtl.get2());
}
long startTime = System.currentTimeMillis();
if (inTx) {
// Rollback transaction for the first time.
Transaction tx = transactions().txStart();
try {
jcache().withExpiryPolicy(expiry).put(key, 1);
} finally {
tx.rollback();
}
if (oldEntry) {
entryTtl = entryTtl(fullCache(), key);
assertEquals((Long) 0L, entryTtl.get1());
assertEquals((Long) 0L, entryTtl.get2());
}
}
// Now commit transaction and check that ttl and expire time have been saved.
Transaction tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 1);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
long[] expireTimes = new long[gridCount()];
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// One more update from the same cache entry to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 2);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// And one more direct update to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 3);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// And one more update to ensure that ttl is not changed and expire time is not shifted forward.
U.sleep(100);
log.info("Put 4");
tx = inTx ? transactions().txStart() : null;
try {
jcache().put(key, 4);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
log.info("Put 4 done");
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertEquals(expireTimes[i], (long) curEntryTtl.get2());
}
}
// Avoid reloading from store.
storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@Override
public boolean applyx() {
try {
Integer val = c.get(key);
if (val != null) {
info("Value is in cache [key=" + key + ", val=" + val + ']');
return false;
}
// Get "cache" field from GridCacheProxyImpl.
GridCacheAdapter c0 = cacheFromCtx(c);
if (!c0.context().deferredDelete()) {
GridCacheEntryEx e0 = c0.peekEx(key);
return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null);
} else
return true;
} catch (GridCacheEntryRemovedException e) {
throw new RuntimeException(e);
}
}
}, Math.min(ttl * 10, getTestTimeout())));
IgniteCache fullCache = fullCache();
if (!isMultiJvmObject(fullCache)) {
GridCacheAdapter internalCache = internalCache(fullCache);
if (internalCache.isLocal())
return;
}
assert c.get(key) == null;
// Ensure that old TTL and expire time are not longer "visible".
entryTtl = entryTtl(fullCache(), key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
// Ensure that next update will not pick old expire time.
tx = inTx ? transactions().txStart() : null;
try {
jcache().put(key, 10);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
U.sleep(2000);
entryTtl = entryTtl(fullCache(), key);
assertEquals((Integer) 10, c.get(key));
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class IgniteCacheConfigVariationsFullApiTest method checkTtl.
/**
* @param inTx In tx flag.
* @param oldEntry {@code True} to check TTL on old entry, {@code false} on new.
* @throws Exception If failed.
*/
private void checkTtl(boolean inTx, boolean oldEntry) throws Exception {
// TODO GG-11133.
if (true)
return;
int ttl = 1000;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
final IgniteCache<String, Integer> c = jcache();
final String key = primaryKeysForCache(1).get(0);
IgnitePair<Long> entryTtl;
if (oldEntry) {
c.put(key, 1);
entryTtl = entryTtl(serverNodeCache(), key);
assertEquals((Long) 0L, entryTtl.get1());
assertEquals((Long) 0L, entryTtl.get2());
}
long startTime = System.currentTimeMillis();
if (inTx) {
// Rollback transaction for the first time.
Transaction tx = transactions().txStart();
try {
jcache().withExpiryPolicy(expiry).put(key, 1);
} finally {
tx.rollback();
}
if (oldEntry) {
entryTtl = entryTtl(serverNodeCache(), key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals((Long) 0L, entryTtl.get1());
assertEquals((Long) 0L, entryTtl.get2());
}
}
// Now commit transaction and check that ttl and expire time have been saved.
Transaction tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 1);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
long[] expireTimes = new long[gridCount()];
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(cacheName()).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// One more update from the same cache entry to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 2);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(cacheName()).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// And one more direct update to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? transactions().txStart() : null;
try {
jcache().withExpiryPolicy(expiry).put(key, 3);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(cacheName()).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertTrue(curEntryTtl.get2() > startTime);
expireTimes[i] = curEntryTtl.get2();
}
}
// And one more update to ensure that ttl is not changed and expire time is not shifted forward.
U.sleep(100);
log.info("Put 4");
tx = inTx ? transactions().txStart() : null;
try {
jcache().put(key, 4);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
log.info("Put 4 done");
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(cacheName()).isPrimaryOrBackup(grid(i).localNode(), key)) {
IgnitePair<Long> curEntryTtl = entryTtl(jcache(i), key);
assertNotNull(curEntryTtl.get1());
assertNotNull(curEntryTtl.get2());
assertEquals(ttl, (long) curEntryTtl.get1());
assertEquals(expireTimes[i], (long) curEntryTtl.get2());
}
}
// Avoid reloading from store.
storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@Override
public boolean applyx() {
try {
Integer val = c.get(key);
if (val != null) {
info("Value is in cache [key=" + key + ", val=" + val + ']');
return false;
}
// Get "cache" field from GridCacheProxyImpl.
GridCacheAdapter c0 = cacheFromCtx(c);
if (!c0.context().deferredDelete()) {
GridCacheEntryEx e0 = c0.peekEx(key);
return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null);
} else
return true;
} catch (GridCacheEntryRemovedException e) {
throw new RuntimeException(e);
}
}
}, Math.min(ttl * 10, getTestTimeout())));
IgniteCache srvNodeCache = serverNodeCache();
if (!isMultiJvmObject(srvNodeCache)) {
GridCacheAdapter internalCache = internalCache(srvNodeCache);
if (internalCache.isLocal())
return;
}
assert c.get(key) == null;
// Ensure that old TTL and expire time are not longer "visible".
entryTtl = entryTtl(srvNodeCache, key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
// Ensure that next update will not pick old expire time.
tx = inTx ? transactions().txStart() : null;
try {
jcache().put(key, 10);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
U.sleep(2000);
entryTtl = entryTtl(srvNodeCache, key);
assertEquals((Integer) 10, c.get(key));
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method checkTtl.
/**
* @param inTx {@code true} for tx.
* @throws Exception If failed.
*/
private void checkTtl(boolean inTx) throws Exception {
int ttl = 1000;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(MILLISECONDS, ttl));
final IgniteCache<Integer, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME);
final Integer key = primaryKeys(jcache(0), 1, 0).get(0);
c.put(key, 1);
GridCacheAdapter<Object, Object> c0 = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
GridCacheEntryEx entry = c0.entryEx(key);
assert entry != null;
assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
long startTime = U.currentTimeMillis();
if (inTx) {
// Rollback transaction for the first time.
Transaction tx = grid(0).transactions().txStart();
try {
grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry).put(key, 1);
} finally {
tx.rollback();
}
entry = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME).entryEx(key);
assertEquals(0, entry.ttl());
assertEquals(0, entry.expireTime());
}
// Now commit transaction and check that ttl and expire time have been saved.
Transaction tx = inTx ? grid(0).transactions().txStart() : null;
try {
grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry).put(key, 1);
} finally {
if (tx != null)
tx.commit();
}
long[] expireTimes = new long[gridCount()];
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
c0 = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
GridCacheEntryEx curEntry = c0.entryEx(key);
curEntry.unswap();
assertTrue(curEntry.expireTime() >= startTime);
expireTimes[i] = curEntry.expireTime();
}
}
// One more update from the same cache entry to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? grid(0).transactions().txStart() : null;
try {
grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry).put(key, 2);
} finally {
if (tx != null)
tx.commit();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
c0 = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
GridCacheEntryEx curEntry = c0.entryEx(key);
curEntry.unswap();
assertTrue(curEntry.expireTime() >= startTime);
expireTimes[i] = curEntry.expireTime();
}
}
// And one more direct update to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? grid(0).transactions().txStart() : null;
try {
grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(expiry).put(key, 3);
} finally {
if (tx != null)
tx.commit();
}
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
c0 = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
GridCacheEntryEx curEntry = c0.entryEx(key);
curEntry.unswap();
assertTrue(curEntry.expireTime() >= startTime);
expireTimes[i] = curEntry.expireTime();
}
}
// And one more update to ensure that ttl is not changed and expire time is not shifted forward.
U.sleep(100);
log.info("Put 4");
tx = inTx ? grid(0).transactions().txStart() : null;
try {
c.put(key, 4);
} finally {
if (tx != null)
tx.commit();
}
log.info("Put 4 done");
for (int i = 0; i < gridCount(); i++) {
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key)) {
c0 = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
GridCacheEntryEx curEntry = c0.entryEx(key);
curEntry.unswap();
assertEquals(expireTimes[i], curEntry.expireTime());
}
}
// Avoid reloading from store.
storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@Override
public boolean applyx() {
try {
if (c.get(key) != null)
return false;
// Get "cache" field from GridCacheProxyImpl.
GridCacheAdapter c0 = cacheFromCtx(c);
if (!c0.context().deferredDelete()) {
GridCacheEntryEx e0 = c0.entryEx(key);
return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null);
} else
return true;
} catch (GridCacheEntryRemovedException e) {
throw new RuntimeException(e);
}
}
}, Math.min(ttl * 10, getTestTimeout())));
c0 = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
if (c0.isNear())
c0 = c0.context().near().dht();
// Ensure that old TTL and expire time are not longer "visible".
entry = c0.entryEx(key);
assertEquals(0, entry.expireTime());
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class GridCacheNearOnlyMultiNodeFullApiSelfTest method checkReaderTtl.
/**
* @param inTx If {@code true} starts explicit transaction.
* @throws Exception If failed.
*/
private void checkReaderTtl(boolean inTx) throws Exception {
int ttl = 1000;
final ExpiryPolicy expiry = new TouchedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, ttl));
final IgniteCache<String, Integer> c = jcache();
final String key = primaryKeysForCache(fullCache(), 1).get(0);
c.put(key, 1);
info("Finished first put.");
{
IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
assertEquals((Integer) 1, c.get(key));
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
}
long startTime = System.currentTimeMillis();
int fullIdx = nearIdx == 0 ? 1 : 0;
// Now commit transaction and check that ttl and expire time have been saved.
Transaction tx = inTx ? grid(fullIdx).transactions().txStart() : null;
try {
jcache(fullIdx).withExpiryPolicy(expiry).put(key, 1);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
long[] expireTimes = new long[gridCount()];
for (int i = 0; i < gridCount(); i++) {
info("Checking grid: " + grid(i).localNode().id());
IgnitePair<Long> entryTtl = null;
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key))
entryTtl = entryTtl(jcache(i), key);
else if (i == nearIdx)
entryTtl = nearEntryTtl(jcache(i), key);
if (entryTtl != null) {
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(ttl, (long) entryTtl.get1());
assertTrue(entryTtl.get2() > startTime);
expireTimes[i] = entryTtl.get2();
}
}
// One more update from the same cache entry to ensure that expire time is shifted forward.
U.sleep(100);
tx = inTx ? grid(fullIdx).transactions().txStart() : null;
try {
jcache(fullIdx).withExpiryPolicy(expiry).put(key, 2);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
for (int i = 0; i < gridCount(); i++) {
IgnitePair<Long> entryTtl = null;
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key))
entryTtl = entryTtl(jcache(i), key);
else if (i == nearIdx)
entryTtl = nearEntryTtl(jcache(i), key);
if (entryTtl != null) {
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(ttl, (long) entryTtl.get1());
assertTrue(entryTtl.get2() > startTime);
expireTimes[i] = entryTtl.get2();
}
}
// And one more update to ensure that ttl is not changed and expire time is not shifted forward.
U.sleep(100);
tx = inTx ? grid(fullIdx).transactions().txStart() : null;
try {
jcache(fullIdx).put(key, 4);
} finally {
if (tx != null)
tx.commit();
}
for (int i = 0; i < gridCount(); i++) {
IgnitePair<Long> entryTtl = null;
if (grid(i).affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid(i).localNode(), key))
entryTtl = entryTtl(jcache(i), key);
else if (i == nearIdx)
entryTtl = nearEntryTtl(jcache(i), key);
if (entryTtl != null) {
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(ttl, (long) entryTtl.get1());
assertEquals(expireTimes[i], (long) entryTtl.get2());
}
}
// Avoid reloading from store.
storeStgy.removeFromStore(key);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@SuppressWarnings("unchecked")
@Override
public boolean applyx() throws IgniteCheckedException {
try {
Integer val = c.get(key);
if (val != null) {
info("Value is in cache [key=" + key + ", val=" + val + ']');
return false;
}
if (!internalCache(c).context().deferredDelete()) {
GridCacheEntryEx e0 = internalCache(c).peekEx(key);
return e0 == null || (e0.rawGet() == null && e0.valueBytes() == null);
} else
return true;
} catch (GridCacheEntryRemovedException ignored) {
// If e0.valueBytes() thrown this exception then entry has been removed.
return true;
}
}
}, Math.min(ttl * 10, getTestTimeout())));
// Ensure that old TTL and expire time are not longer "visible".
{
IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
}
// Ensure that next update will not pick old expire time.
tx = inTx ? transactions().txStart() : null;
try {
c.put(key, 10);
if (tx != null)
tx.commit();
} finally {
if (tx != null)
tx.close();
}
U.sleep(2000);
{
IgnitePair<Long> entryTtl = entryTtl(fullCache(), key);
assertNotNull(entryTtl.get1());
assertNotNull(entryTtl.get2());
assertEquals(0, (long) entryTtl.get1());
assertEquals(0, (long) entryTtl.get2());
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicateX in project ignite by apache.
the class IgniteSemaphoreAbstractSelfTest method removeSemaphore.
/**
* @param semaphoreName Semaphore name.
* @throws Exception If failed.
*/
private void removeSemaphore(final String semaphoreName) throws Exception {
IgniteSemaphore semaphore = grid(RND.nextInt(NODES_CNT)).semaphore(semaphoreName, 10, false, true);
assert semaphore != null;
if (semaphore.availablePermits() < 0)
semaphore.release(-semaphore.availablePermits());
// Remove semaphore on random node.
IgniteSemaphore semaphore0 = grid(RND.nextInt(NODES_CNT)).semaphore(semaphoreName, 0, false, true);
assertNotNull(semaphore0);
semaphore0.close();
// Ensure semaphore is removed on all nodes.
assert GridTestUtils.waitForCondition(new GridAbsPredicateX() {
@Override
public boolean applyx() throws IgniteCheckedException {
for (Ignite g : G.allGrids()) {
if (((IgniteKernal) g).context().dataStructures().semaphore(semaphoreName, null, 10, true, false) != null)
return false;
}
return true;
}
}, 5_000);
checkRemovedSemaphore(semaphore);
}
Aggregations