use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheNestedTxAbstractTest method testTwoTx.
/**
* JUnit.
*
* @throws Exception If failed.
*/
public void testTwoTx() throws Exception {
final IgniteCache<String, Integer> c = grid(0).cache(DEFAULT_CACHE_NAME);
GridKernalContext ctx = ((IgniteKernal) grid(0)).context();
c.put(CNTR_KEY, 0);
for (int i = 0; i < 10; i++) {
try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
c.get(CNTR_KEY);
ctx.closure().callLocalSafe((new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertFalse(((GridCacheAdapter) c).context().tm().inUserTx());
assertNull(((GridCacheAdapter) c).context().tm().userTx());
return true;
}
}), true);
tx.commit();
}
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheOrderedPreloadingSelfTest method checkPreloadOrder.
/**
* @param first First cache mode.
* @param second Second cache mode.
* @throws Exception If failed.
*/
private void checkPreloadOrder(CacheMode first, CacheMode second) throws Exception {
firstCacheMode = first;
secondCacheMode = second;
Ignite g = startGrid(0);
try {
IgniteCache<Object, Object> cache = g.cache("first");
// Put some data into cache.
for (int i = 0; i < 1000; i++) cache.put(i, i);
for (int i = 1; i < GRID_CNT; i++) startGrid(i);
// For first node in topology replicated preloader gets completed right away.
for (int i = 1; i < GRID_CNT; i++) {
IgniteKernal kernal = (IgniteKernal) grid(i);
GridFutureAdapter<?> fut1 = (GridFutureAdapter<?>) kernal.internalCache(FIRST_CACHE_NAME).preloader().syncFuture();
GridFutureAdapter<?> fut2 = (GridFutureAdapter<?>) kernal.internalCache(SECOND_CACHE_NAME).preloader().syncFuture();
fut1.get();
fut2.get();
long firstSyncTime = times.get(i).get(FIRST_CACHE_NAME);
long secondSyncTime = times.get(i).get(SECOND_CACHE_NAME);
assertTrue(FIRST_CACHE_NAME + " [syncTime=" + firstSyncTime + "], " + SECOND_CACHE_NAME + " [syncTime=" + secondSyncTime + "]", firstSyncTime <= secondSyncTime);
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheP2PUndeploySelfTest method checkP2PUndeploy.
/**
* @param cacheName Cache name.
* @throws Exception If failed.
*/
private void checkP2PUndeploy(final String cacheName) throws Exception {
assert !F.isEmpty(cacheName);
ClassLoader ldr = getExternalClassLoader();
Class valCls = ldr.loadClass(TEST_VALUE);
try {
Ignite ignite1 = startGrid(1);
final IgniteKernal grid2 = (IgniteKernal) startGrid(2);
IgniteCache<Integer, Object> cache1 = ignite1.cache(cacheName);
IgniteCache<Integer, Object> cache2 = grid2.cache(cacheName);
Object v1 = valCls.newInstance();
cache1.put(1, v1);
cache1.put(2, valCls.newInstance());
cache1.put(3, valCls.newInstance());
cache1.put(4, valCls.newInstance());
info("Stored value in cache1 [v=" + v1 + ", ldr=" + v1.getClass().getClassLoader() + ']');
Object v2 = cache2.get(1);
assert v2 != null;
info("Read value from cache2 [v=" + v2 + ", ldr=" + v2.getClass().getClassLoader() + ']');
assert v2 != null;
assert v2.toString().equals(v1.toString());
assert !v2.getClass().getClassLoader().equals(getClass().getClassLoader());
assert v2.getClass().getClassLoader().getClass().getName().contains("GridDeploymentClassLoader");
cache2.localEvict(ImmutableSet.of(2, 3, 4));
// Wait until entries stored to disk.
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return size(cacheName, grid2) > 0;
} catch (IgniteCheckedException e) {
throw new AssertionError(e);
}
}
}, 5000);
stopGrid(1);
assert waitCacheEmpty(cache2, 10000);
for (int i = 0; i < 3; i++) {
long swapSize = size(cacheName, grid2);
if (swapSize > 0) {
if (i < 2) {
U.warn(log, "Swap size check failed (will retry in 1000 ms): " + swapSize);
U.sleep(1000);
continue;
}
fail("Swap size check failed: " + swapSize);
} else if (swapSize == 0)
break;
else
assert false : "Negative swap size: " + swapSize;
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheSlowTxWarnTest method testWarningOutput.
/**
* @throws Exception If failed.
*/
public void testWarningOutput() throws Exception {
try {
IgniteKernal g = (IgniteKernal) startGrid(1);
info(">>> Slow tx timeout is not set, long-live txs simulated.");
checkCache(g, "partitioned", true, false);
checkCache(g, "replicated", true, false);
checkCache(g, "local", true, false);
info(">>> Slow tx timeout is set, long-live tx simulated.");
checkCache(g, "partitioned", true, true);
checkCache(g, "replicated", true, true);
checkCache(g, "local", true, true);
info(">>> Slow tx timeout is set, no long-live txs.");
checkCache(g, "partitioned", false, true);
checkCache(g, "replicated", false, true);
checkCache(g, "local", false, true);
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheVersionMultinodeTest method checkEntryVersion.
/**
* @param key Key.
* @throws Exception If failed.
*/
private void checkEntryVersion(String key) throws Exception {
GridCacheVersion ver = null;
boolean verified = false;
for (int i = 0; i < gridCount(); i++) {
IgniteKernal grid = (IgniteKernal) grid(i);
GridCacheAdapter<Object, Object> cache = grid.context().cache().internalCache(DEFAULT_CACHE_NAME);
GridCacheEntryEx e;
if (cache.affinity().isPrimaryOrBackup(grid.localNode(), key)) {
if (cache instanceof GridNearCacheAdapter)
cache = ((GridNearCacheAdapter<Object, Object>) cache).dht();
e = cache.entryEx(key);
e.unswap();
assertNotNull(e.rawGet());
} else
e = cache.peekEx(key);
if (e != null) {
if (ver != null) {
assertEquals("Non-equal versions for key: " + key, ver, e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version());
verified = true;
} else
ver = e instanceof GridNearCacheEntry ? ((GridNearCacheEntry) e).dhtVersion() : e.version();
}
}
assertTrue(verified);
}
Aggregations