use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class BasicWarmupClosure method doWarmup.
/**
* @param grids Grids to warmup.
*/
private void doWarmup(Iterable<Ignite> grids) throws Exception {
Ignite first = F.first(grids);
ExecutorService svc = Executors.newFixedThreadPool(threadCnt);
try {
for (IgniteCacheProxy cache : ((IgniteKernal) first).caches()) {
if (!cache.context().userCache())
continue;
IgniteInternalCache<Object, Object> cache0 = cache.context().cache();
for (String warmupMethod : warmupMethods) {
Collection<Future> futs = new ArrayList<>(threadCnt);
for (int i = 0; i < threadCnt; i++) {
Callable call;
switch(warmupMethod) {
case "get":
{
call = new GetCallable(cache0);
break;
}
case "put":
{
call = new PutCallable(cache0);
break;
}
case "putx":
{
call = new PutxCallable(cache0);
break;
}
case "remove":
{
call = new RemoveCallable(cache0);
break;
}
case "removex":
{
call = new RemovexCallable(cache0);
break;
}
case "putIfAbsent":
{
call = new PutIfAbsentCallable(cache0);
break;
}
case "replace":
{
call = new ReplaceCallable(cache0);
break;
}
default:
throw new IgniteCheckedException("Unsupported warmup method: " + warmupMethod);
}
futs.add(svc.submit(call));
}
out("Running warmup [cacheName=" + U.maskName(cache.getName()) + ", method=" + warmupMethod + ']');
for (Future fut : futs) fut.get();
for (int key = 0; key < keyRange; key++) cache0.getAndRemove(key);
}
}
} finally {
svc.shutdownNow();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCachePreloadingEvictionsSelfTest method checkCachesConsistency.
/**
* @param ignite1 Grid 1.
* @param ignite2 Grid 2.
* @throws Exception If failed.
*/
private void checkCachesConsistency(Ignite ignite1, Ignite ignite2) throws Exception {
IgniteKernal g1 = (IgniteKernal) ignite1;
IgniteKernal g2 = (IgniteKernal) ignite2;
GridCacheAdapter<Integer, Object> cache1 = g1.internalCache(DEFAULT_CACHE_NAME);
GridCacheAdapter<Integer, Object> cache2 = g2.internalCache(DEFAULT_CACHE_NAME);
// Sleeping to allow the cache sizes to settle down.
U.sleep(3000);
info("Cache1 size: " + cache1.size(ALL_PEEK_MODES));
info("Cache2 size: " + cache2.size(ALL_PEEK_MODES));
assert cache1.size(ALL_PEEK_MODES) == cache2.size(ALL_PEEK_MODES) : "Sizes do not match [s1=" + cache1.size(ALL_PEEK_MODES) + ", s2=" + cache2.size(ALL_PEEK_MODES) + ']';
for (Integer key : cache1.keySet()) {
Object e = cache1.localPeek(key, new CachePeekMode[] { CachePeekMode.ONHEAP });
if (e != null)
assert cache2.containsKey(key) : "Cache2 does not contain key: " + key;
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheStopSelfTest method testStopMultithreaded.
/**
* @throws Exception If failed.
*/
@Test
public void testStopMultithreaded() throws Exception {
try {
startGrid(0);
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
startGridsMultiThreaded(1, 3);
final AtomicInteger threadIdx = new AtomicInteger(0);
final IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = threadIdx.getAndIncrement();
IgniteKernal node = (IgniteKernal) ignite(idx % 3 + 1);
IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
while (true) {
try {
cacheOperations(node, cache);
} catch (Exception ignored) {
if (node.isStopping())
break;
}
}
return null;
}
}, 20, "tx-node-stop-thread");
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteKernal node = (IgniteKernal) ignite(0);
IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
while (!fut1.isDone()) {
try {
cacheOperations(node, cache);
} catch (Exception ignore) {
// No-op.
}
}
return null;
}
}, 2, "tx-thread");
Thread.sleep(3000);
final AtomicInteger nodeIdx = new AtomicInteger(1);
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = nodeIdx.getAndIncrement();
log.info("Stop node: " + idx);
ignite(idx).close();
return null;
}
}, 3, "stop-node");
fut1.get();
fut2.get();
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheMvccManagerSelfTest method testCandidates.
/**
* @param gridCnt Grid count.
* @throws Exception If failed.
*/
private void testCandidates(int gridCnt) throws Exception {
try {
Ignite ignite = startGridsMultiThreaded(gridCnt);
IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
Transaction tx = ignite.transactions().txStart();
cache.put(1, 1);
tx.commit();
for (int i = 0; i < gridCnt; i++) {
assert ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME).context().mvcc().localCandidates().isEmpty();
assert ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME).context().mvcc().remoteCandidates().isEmpty();
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteKernal in project ignite by apache.
the class GridCacheSequenceApiSelfAbstractTest method testCacheSets.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheSets() throws Exception {
// Make new atomic sequence in cache.
IgniteAtomicSequence seq = grid().atomicSequence(UUID.randomUUID().toString(), 0, true);
seq.incrementAndGet();
final String cacheName = DataStructuresProcessor.ATOMICS_CACHE_NAME + "@default-ds-group";
GridCacheAdapter cache = ((IgniteKernal) grid()).internalCache(cacheName);
assertNotNull(cache);
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
grid().cache(cacheName);
return null;
}
}, IllegalStateException.class, null);
for (String seqName : seqNames) assert null != cache.get(new GridCacheInternalKeyImpl(seqName, "default-ds-group"));
}
Aggregations