use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteCacheLockFailoverSelfTest method testUnlockPrimaryLeft.
/**
* @throws Exception If failed.
*/
public void testUnlockPrimaryLeft() throws Exception {
GridCacheAdapter<Integer, Integer> cache = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
Integer key = backupKey(grid(0).cache(DEFAULT_CACHE_NAME));
cache.lock(key, 0);
stopGrid(1);
cache.unlock(key);
GridCacheEntryEx entry = cache.peekEx(key);
assertTrue("Remote MVCC is not empty: " + entry, entry == null || entry.remoteMvccSnapshot().isEmpty());
startGrid(1);
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteCacheLockFailoverSelfTest method testLockFailover.
/**
* @throws Exception If failed.
*/
public void testLockFailover() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
Integer key = backupKey(cache);
final AtomicBoolean stop = new AtomicBoolean();
IgniteInternalFuture<?> restartFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!stop.get()) {
stopGrid(1);
U.sleep(500);
startGrid(1);
}
return null;
}
});
try {
long end = System.currentTimeMillis() + 60_000;
long iter = 0;
while (System.currentTimeMillis() < end) {
if (iter % 100 == 0)
log.info("Iteration: " + iter);
iter++;
GridCacheAdapter<Object, Object> adapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
IgniteInternalFuture<Boolean> fut = adapter.lockAsync(key, 0);
try {
fut.get(30_000);
U.sleep(1);
} catch (IgniteFutureTimeoutException e) {
info("Entry: " + adapter.peekEx(key));
fail("Lock timeout [fut=" + fut + ", err=" + e + ']');
} catch (Exception e) {
log.error("Error: " + e);
} finally {
adapter.unlock(key);
}
}
} finally {
stop.set(true);
restartFut.get();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheSyncReplicatedPreloadSelfTest method testNodeRestart.
/**
* @throws Exception If test failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testNodeRestart() throws Exception {
int keyCnt = 1000;
int retries = 20;
Ignite g0 = startGrid(0);
Ignite g1 = startGrid(1);
for (int i = 0; i < keyCnt; i++) g0.cache(DEFAULT_CACHE_NAME).put(i, i);
assertEquals(keyCnt, ((IgniteKernal) g0).internalCache(DEFAULT_CACHE_NAME).size());
assertEquals(keyCnt, ((IgniteKernal) g1).internalCache(DEFAULT_CACHE_NAME).size());
for (int n = 0; n < retries; n++) {
info("Starting additional grid node...");
Ignite g2 = startGrid(2);
assertEquals(keyCnt, ((IgniteKernal) g2).internalCache(DEFAULT_CACHE_NAME).size());
info("Stopping additional grid node...");
stopGrid(2);
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class HadoopJobTrackerSelfTest method checkStatus.
/**
* Checks job execution status.
*
* @param jobId Job ID.
* @param complete Completion status.
* @throws Exception If failed.
*/
private void checkStatus(HadoopJobId jobId, boolean complete) throws Exception {
for (int i = 0; i < gridCount(); i++) {
IgniteKernal kernal = (IgniteKernal) grid(i);
Hadoop hadoop = kernal.hadoop();
HadoopJobStatus stat = hadoop.status(jobId);
assert stat != null;
IgniteInternalFuture<?> fut = hadoop.finishFuture(jobId);
if (!complete)
assertFalse(fut.isDone());
else {
info("Waiting for status future completion on node [idx=" + i + ", nodeId=" + kernal.getLocalNodeId() + ']');
fut.get();
}
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class IgniteCacheExpiryPolicyWithStoreAbstractTest method checkTtl.
/**
* @param key Key.
* @param ttl TTL.
* @param primaryOnly If {@code true} expect entries only on primary node.
* @throws Exception If failed.
*/
private void checkTtl(Object key, final long ttl, boolean primaryOnly) throws Exception {
boolean found = 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 = null;
try {
e = cache.entryEx(key);
e.unswap();
} catch (GridDhtInvalidPartitionException ignore) {
// No-op.
}
if ((e == null || e.rawGet() == null) && cache.context().isNear())
e = cache.context().near().dht().peekEx(key);
if (e == null || e.rawGet() == null)
e = null;
if (e == null) {
if (primaryOnly)
assertTrue("Not found " + key, !grid.affinity(DEFAULT_CACHE_NAME).isPrimary(grid.localNode(), key));
else
assertTrue("Not found " + key, !grid.affinity(DEFAULT_CACHE_NAME).isPrimaryOrBackup(grid.localNode(), key));
} else {
found = true;
if (ttl > 0)
assertTrue(e.expireTime() > 0);
else
assertEquals(0, e.expireTime());
}
}
assertTrue(found);
}
Aggregations