use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteServiceDynamicCachesSelfTest method testDeployCalledBeforeCacheStart.
/**
* @throws Exception If failed.
*/
public void testDeployCalledBeforeCacheStart() throws Exception {
String cacheName = "cache";
CacheConfiguration ccfg = new CacheConfiguration(cacheName);
ccfg.setBackups(1);
Ignite ig = ignite(0);
final IgniteServices svcs = ig.services();
final String svcName = "myService";
ig.createCache(ccfg);
Object key = primaryKey(ig.cache(cacheName));
ig.destroyCache(cacheName);
awaitPartitionMapExchange();
svcs.deployKeyAffinitySingleton(svcName, new TestService(), cacheName, key);
assert svcs.service(svcName) == null;
ig.createCache(ccfg);
try {
boolean res = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return svcs.service(svcName) != null;
}
}, 10 * 1000);
assertTrue("Service was not deployed", res);
info("stopping cache: " + cacheName);
ig.destroyCache(cacheName);
res = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return svcs.service(svcName) == null;
}
}, 10 * 1000);
assertTrue("Service was not undeployed", res);
} finally {
ig.services().cancelAll();
ig.destroyCache(cacheName);
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class GridCacheAbstractFullApiSelfTest method checkGetOutTx.
/**
* @throws Exception If failed.
*/
private void checkGetOutTx(boolean async) throws Exception {
final AtomicInteger lockEvtCnt = new AtomicInteger();
IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
lockEvtCnt.incrementAndGet();
return true;
}
};
try {
IgniteCache<String, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
List<String> keys = primaryKeysForCache(cache, 2);
assertEquals(2, keys.size());
cache.put(keys.get(0), 0);
cache.put(keys.get(1), 1);
grid(0).events().localListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
try (Transaction tx = transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
Integer val0;
if (async)
val0 = cache.getAsync(keys.get(0)).get();
else
val0 = cache.get(keys.get(0));
assertEquals(0, val0.intValue());
Map<String, Integer> allOutTx;
if (async)
allOutTx = cache.getAllOutTxAsync(F.asSet(keys.get(1))).get();
else
allOutTx = cache.getAllOutTx(F.asSet(keys.get(1)));
assertEquals(1, allOutTx.size());
assertTrue(allOutTx.containsKey(keys.get(1)));
assertEquals(1, allOutTx.get(keys.get(1)).intValue());
}
assertTrue(GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
info("Lock event count: " + lockEvtCnt.get());
if (atomicityMode() == ATOMIC)
return lockEvtCnt.get() == 0;
if (cacheMode() == PARTITIONED && nearEnabled()) {
if (!grid(0).configuration().isClientMode())
return lockEvtCnt.get() == 4;
}
return lockEvtCnt.get() == 2;
}
}, 15000));
} finally {
grid(0).events().stopLocalListen(lsnr, EVT_CACHE_OBJECT_LOCKED, EVT_CACHE_OBJECT_UNLOCKED);
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method checkData.
/**
* @param map Expected data.
* @param keys Expected keys (if expected data is not specified).
* @param clientCache Client cache.
* @param expNodes Expected nodes number.
* @throws Exception If failed.
*/
private void checkData(final Map<Integer, Integer> map, final Set<Integer> keys, IgniteCache<?, ?> clientCache, final int expNodes) throws Exception {
final List<Ignite> nodes = G.allGrids();
final Affinity<Integer> aff = nodes.get(0).affinity(DEFAULT_CACHE_NAME);
assertEquals(expNodes, nodes.size());
boolean hasNearCache = clientCache.getConfiguration(CacheConfiguration.class).getNearConfiguration() != null;
final Ignite nearCacheNode = hasNearCache ? clientCache.unwrap(Ignite.class) : null;
boolean wait = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
try {
Set<Integer> keys0 = map != null ? map.keySet() : keys;
assertNotNull(keys0);
for (Integer key : keys0) {
GridCacheVersion ver = null;
Object val = null;
for (Ignite node : nodes) {
IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
boolean affNode = aff.isPrimaryOrBackup(node.cluster().localNode(), key);
Object val0 = cache.localPeek(key);
if (affNode || node == nearCacheNode) {
if (map != null)
assertEquals("Unexpected value for " + node.name(), map.get(key), val0);
else
assertNotNull("Unexpected value for " + node.name(), val0);
GridCacheAdapter cache0 = ((IgniteKernal) node).internalCache(DEFAULT_CACHE_NAME);
if (affNode && cache0.isNear())
cache0 = ((GridNearCacheAdapter) cache0).dht();
GridCacheEntryEx entry = cache0.entryEx(key);
try {
entry.unswap(true);
assertNotNull("No entry [node=" + node.name() + ", key=" + key + ']', entry);
GridCacheVersion ver0 = entry instanceof GridNearCacheEntry ? ((GridNearCacheEntry) entry).dhtVersion() : entry.version();
assertNotNull("Null version [node=" + node.name() + ", key=" + key + ']', ver0);
if (ver == null) {
ver = ver0;
val = val0;
} else {
assertEquals("Version check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', ver0, ver);
assertEquals("Value check failed [node=" + node.name() + ", key=" + key + ", affNode=" + affNode + ", primary=" + aff.isPrimary(node.cluster().localNode(), key) + ']', val0, val);
}
} finally {
cache0.context().evicts().touch(entry, cache0.context().affinity().affinityTopologyVersion());
}
} else
assertNull("Unexpected non-null value for " + node.name(), val0);
}
}
} catch (AssertionError e) {
log.info("Check failed, will retry: " + e);
return false;
} catch (Exception e) {
fail("Unexpected exception: " + e);
}
return true;
}
}, 10_000);
assertTrue("Data check failed.", wait);
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheLateAffinityAssignmentTest method checkServicesDeploy.
/**
* @param ignite Node.
* @param affinity Affinity.
* @throws Exception If failed.
*/
private void checkServicesDeploy(Ignite ignite, final List<List<ClusterNode>> affinity) throws Exception {
Affinity<Object> aff = ignite.affinity(CACHE_NAME1);
for (int i = 0; i < 10; i++) {
final int part = aff.partition(i);
final String srvcName = "service-" + i;
final ClusterNode srvcNode = affinity.get(part).get(0);
boolean wait = GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
TestService srvc = grid(srvcNode).services().service(srvcName);
if (srvc == null)
return false;
assertEquals(srvcNode, srvc.serviceNode());
return true;
}
}, 5000);
assertTrue(wait);
}
}
use of org.apache.ignite.internal.util.typedef.PA in project ignite by apache.
the class CacheContinuousBatchAckTest method checkBackupAcknowledgeMessage.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkBackupAcknowledgeMessage(CacheConfiguration<Object, Object> ccfg) throws Exception {
QueryCursor qry = null;
IgniteCache<Object, Object> cache = null;
try {
ContinuousQuery q = new ContinuousQuery();
q.setLocalListener(new CacheEntryUpdatedListener() {
@Override
public void onUpdated(Iterable iterable) throws CacheEntryListenerException {
// No-op.
}
});
cache = grid(SERVER).getOrCreateCache(ccfg);
qry = cache.query(q);
for (int i = 0; i < 10000; i++) cache.put(i, i);
assert !GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
return fail.get();
}
}, 1300L);
} finally {
if (qry != null)
qry.close();
if (cache != null)
grid(SERVER).destroyCache(cache.getName());
}
}
Aggregations