use of org.apache.ignite.IgniteSemaphore 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);
}
use of org.apache.ignite.IgniteSemaphore in project ignite by apache.
the class IgniteSemaphoreAbstractSelfTest method testIsolation.
/**
* Implementation of ignite data structures internally uses special system caches, need make sure
* that transaction on these system caches do not intersect with transactions started by user.
*
* @throws Exception If failed.
*/
public void testIsolation() throws Exception {
Ignite ignite = grid(0);
CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
cfg.setName("myCache");
cfg.setAtomicityMode(TRANSACTIONAL);
cfg.setWriteSynchronizationMode(FULL_SYNC);
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(cfg);
try {
IgniteSemaphore semaphore = ignite.semaphore("testIsolation", 1, true, true);
assertNotNull(semaphore);
try (Transaction tx = ignite.transactions().txStart()) {
cache.put(1, 1);
assertEquals(1, semaphore.availablePermits());
semaphore.acquire();
tx.rollback();
}
assertEquals(0, cache.size());
assertEquals(0, semaphore.availablePermits());
semaphore.close();
assertTrue(semaphore.removed());
} finally {
ignite.destroyCache(cfg.getName());
}
}
Aggregations