use of org.apache.ignite.IgniteCache in project ignite by apache.
the class CacheClientStoreSelfTest method testPartitionedLoadFromClient.
/**
* Load cache created on client as REPLICATED and see if it only loaded on servers
*/
public void testPartitionedLoadFromClient() throws Exception {
cacheMode = CacheMode.PARTITIONED;
factory = new Factory3();
startGrids(2);
Ignite client = startGrid("client-1");
IgniteCache cache = client.cache(CACHE_NAME);
cache.loadCache(null);
assertEquals(0, cache.localSize(CachePeekMode.ALL));
assertEquals(10, grid(0).cache(CACHE_NAME).localSize(CachePeekMode.ALL));
assertEquals(10, grid(1).cache(CACHE_NAME).localSize(CachePeekMode.ALL));
assert !loadedFromClient : "Loaded data from client!";
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class CacheConfigurationLeakTest method testCacheCreateLeak.
/**
* @throws Exception If failed.
*/
public void testCacheCreateLeak() throws Exception {
final Ignite ignite = grid();
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer idx) {
for (int i = 0; i < 100; i++) {
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setName("cache-" + idx + "-" + i);
ccfg.setEvictionPolicy(new LruEvictionPolicy(1000));
ccfg.setOnheapCacheEnabled(true);
IgniteCache<Object, Object> cache = ignite.createCache(ccfg);
for (int k = 0; k < 5000; k++) cache.put(k, new byte[1024]);
ignite.destroyCache(cache.getName());
}
}
}, 5, "cache-thread");
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class CacheInterceptorPartitionCounterRandomOperationsTest method waitAndCheckEvent.
/**
* @param cache Ignite cache.
* @param partCntrs Partition counters.
* @param aff Affinity function.
* @param key Key.
* @param val Value.
* @param oldVal Old value.
* @param rmv Remove operation.
* @throws Exception If failed.
*/
private void waitAndCheckEvent(IgniteCache<Object, Object> cache, Map<Integer, Long> partCntrs, Affinity<Object> aff, Object key, Object val, Object oldVal, boolean rmv) throws Exception {
Collection<BlockingQueue<Cache.Entry<TestKey, TestValue>>> entries = getInterceptorQueues(cache, key, rmv);
assert !entries.isEmpty();
if (val == null && oldVal == null) {
checkNoEvent(entries);
return;
}
for (BlockingQueue<Cache.Entry<TestKey, TestValue>> evtsQueue : entries) {
Cache.Entry<TestKey, TestValue> entry = evtsQueue.poll(5, SECONDS);
assertNotNull("Failed to wait for event [key=" + key + ", val=" + val + ", oldVal=" + oldVal + ']', entry);
assertEquals(key, entry.getKey());
assertEquals(rmv ? oldVal : val, entry.getValue());
long cntr = partCntrs.get(aff.partition(key));
CacheInterceptorEntry interceptorEntry = entry.unwrap(CacheInterceptorEntry.class);
assertNotNull(cntr);
assertNotNull(interceptorEntry);
assertEquals(cntr, interceptorEntry.getPartitionUpdateCounter());
assertNull(evtsQueue.peek());
}
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class CacheMetricsEntitiesCountTest method fillCache.
/**
* @param igniteIdx Ignite index.
* @param cacheIdx Cache index.
*/
private void fillCache(int igniteIdx, int cacheIdx) {
log.info("Filling cache, igniteIdx=" + igniteIdx + ", cacheIdx=" + cacheIdx);
IgniteCache cache = grid(igniteIdx).cache(CACHE_PREFIX + cacheIdx);
for (int i = 0; i < ENTITIES_CNT; i++) cache.put("key" + igniteIdx + "-" + i, i);
}
use of org.apache.ignite.IgniteCache in project ignite by apache.
the class CacheSerializableTransactionsTest method testNoReadLockConflictMultiNode.
/**
* @throws Exception If failed.
*/
public void testNoReadLockConflictMultiNode() throws Exception {
Ignite ignite0 = ignite(0);
for (final CacheConfiguration<Integer, Integer> ccfg : cacheConfigurations()) {
logCacheInfo(ccfg);
final AtomicInteger putKey = new AtomicInteger(1_000_000);
ignite0.createCache(ccfg);
try {
final int THREADS = 64;
IgniteCache<Integer, Integer> cache0 = ignite0.cache(ccfg.getName());
List<Integer> readKeys = testKeys(cache0);
for (final Integer readKey : readKeys) {
final CyclicBarrier barrier = new CyclicBarrier(THREADS);
cache0.put(readKey, Integer.MIN_VALUE);
final AtomicInteger idx = new AtomicInteger();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
Ignite ignite = ignite(idx.incrementAndGet() % (CLIENTS + SRVS));
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
cache.get(readKey);
barrier.await();
cache.put(putKey.incrementAndGet(), 0);
tx.commit();
}
return null;
}
}, THREADS, "test-thread");
assertEquals((Integer) Integer.MIN_VALUE, cache0.get(readKey));
cache0.put(readKey, readKey);
assertEquals(readKey, cache0.get(readKey));
}
} finally {
destroyCache(ccfg.getName());
}
}
}
Aggregations