use of javax.cache.Cache in project ignite by apache.
the class CacheMvccBasicContinuousQueryTest method testCachingMaxSize.
/**
* @throws Exception If failed.
*/
@Test
public void testCachingMaxSize() throws Exception {
Ignite node = startGrids(1);
final IgniteCache cache = node.createCache(cacheConfiguration(cacheMode(), FULL_SYNC, 1, 2).setCacheMode(CacheMode.PARTITIONED).setIndexedTypes(Integer.class, Integer.class));
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
// No-op.
}
});
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
try (Transaction tx = node.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
for (int i = 0; i < TX_SIZE_THRESHOLD + 1; i++) cache.query(new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values (" + i + ", 1)")).getAll();
tx.commit();
}
}
return null;
}
}, CacheException.class, "Transaction is too large. Consider reducing transaction size");
}
use of javax.cache.Cache in project ignite by apache.
the class ScanQueriesTopologyMappingTest method testLocalCacheQueryMapping.
/**
*/
@Test
public void testLocalCacheQueryMapping() throws Exception {
IgniteEx ign0 = startGrid(0);
IgniteCache<Object, Object> cache = ign0.createCache(new CacheConfiguration<>(GridAbstractTest.DEFAULT_CACHE_NAME).setCacheMode(CacheMode.LOCAL));
cache.put(1, 2);
startGrid(1);
ScanQuery<Object, Object> qry = new ScanQuery<>();
{
List<Cache.Entry<Object, Object>> res0 = grid(0).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
assertEquals(1, res0.size());
assertEquals(1, res0.get(0).getKey());
assertEquals(2, res0.get(0).getValue());
}
{
List<Cache.Entry<Object, Object>> res1 = grid(1).cache(GridAbstractTest.DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
}
use of javax.cache.Cache in project ignite by apache.
the class ScanQueriesTopologyMappingTest method checkQueryWithRebalance.
/**
*/
private void checkQueryWithRebalance(CacheMode cacheMode) throws Exception {
IgniteEx ign0 = startGrid(0);
IgniteCache<Object, Object> cache0 = ign0.createCache(new CacheConfiguration<>(GridAbstractTest.DEFAULT_CACHE_NAME).setCacheMode(cacheMode));
cache0.put(1, 2);
blockRebalanceSupplyMessages(ign0, DEFAULT_CACHE_NAME, getTestIgniteInstanceName(1));
startGrid(1);
client = true;
startGrid(10);
int part = ign0.affinity(DEFAULT_CACHE_NAME).partition(1);
for (int i = 0; i < 100; i++) {
for (Ignite ign : G.allGrids()) {
IgniteCache<Object, Object> cache = ign.cache(DEFAULT_CACHE_NAME);
// check scan query
List<Cache.Entry<Object, Object>> res = cache.query(new ScanQuery<>()).getAll();
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
res = new ArrayList<>();
// check iterator
for (Cache.Entry<Object, Object> entry : cache) {
res.add(entry);
}
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
// check scan query by partition
res = cache.query(new ScanQuery<>(part)).getAll();
assertEquals(1, res.size());
assertEquals(1, res.get(0).getKey());
assertEquals(2, res.get(0).getValue());
}
ScanQuery<Object, Object> qry = new ScanQuery<>().setLocal(true);
{
List<Cache.Entry<Object, Object>> res0 = grid(0).cache(DEFAULT_CACHE_NAME).query(qry).getAll();
assertEquals(1, res0.size());
assertEquals(1, res0.get(0).getKey());
assertEquals(2, res0.get(0).getValue());
}
{
List<Cache.Entry<Object, Object>> res1 = grid(1).cache(DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
{
List<Cache.Entry<Object, Object>> res1 = grid(10).cache(DEFAULT_CACHE_NAME).query(qry).getAll();
assertTrue(res1.isEmpty());
}
}
}
use of javax.cache.Cache in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method afterTest.
/**
* {@inheritDoc}
*/
@Override
protected void afterTest() throws Exception {
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
if (grid(i).cluster().nodes().size() != gridCount())
return false;
}
return true;
}
}, 3000);
for (int i = 0; i < gridCount(); i++) assertEquals(gridCount(), grid(i).cluster().nodes().size());
for (int i = 0; i < gridCount(); i++) {
for (int j = 0; j < 5; j++) {
try {
IgniteCache<Object, Object> cache = grid(i).cache(DEFAULT_CACHE_NAME);
for (Cache.Entry<Object, Object> entry : cache.localEntries(new CachePeekMode[] { CachePeekMode.ALL })) cache.remove(entry.getKey());
break;
} catch (IgniteException e) {
if (j == 4)
throw new Exception("Failed to clear cache for grid: " + i, e);
U.warn(log, "Failed to clear cache for grid (will retry in 500 ms) [gridIdx=" + i + ", err=" + e.getMessage() + ']');
U.sleep(500);
}
}
}
// Wait for all routines are unregistered
GridTestUtils.waitForCondition(new PA() {
@Override
public boolean apply() {
for (int i = 0; i < gridCount(); i++) {
GridContinuousProcessor proc = grid(i).context().continuous();
if (!((Map) U.field(proc, "rmtInfos")).isEmpty())
return false;
}
return true;
}
}, 3000);
for (int i = 0; i < gridCount(); i++) {
GridContinuousProcessor proc = grid(i).context().continuous();
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "locInfos")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "rmtInfos")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "startFuts")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "stopFuts")).size());
assertEquals(String.valueOf(i), 0, ((Map) U.field(proc, "bufCheckThreads")).size());
CacheContinuousQueryManager mgr = grid(i).context().cache().internalCache(DEFAULT_CACHE_NAME).context().continuousQueries();
assertEquals(0, ((Map) U.field(mgr, "lsnrs")).size());
}
}
use of javax.cache.Cache in project ignite by apache.
the class CacheKeepBinaryIterationTest method doTestLocalEntries.
/**
* @param ccfg Cache configuration.
*/
private void doTestLocalEntries(final CacheConfiguration<Object, Object> ccfg, boolean keepBinary, boolean primitives) throws Exception {
IgniteCache<Object, Object> cache = grid(0).createCache(ccfg);
assertEquals(0, cache.size());
try {
for (int i = 0; i < KEYS; i++) if (primitives)
cache.put(i, i);
else
cache.put(new QueryTestKey(i), new QueryTestValue(i));
for (int i = 0; i < getServerNodeCount(); i++) {
IgniteCache<Object, Object> cache0 = grid(i).cache(ccfg.getName());
if (keepBinary)
cache0 = cache0.withKeepBinary();
for (CachePeekMode mode : CachePeekMode.values()) {
int size = 0;
for (Cache.Entry<Object, Object> e : cache0.localEntries(mode)) {
Object key = e.getKey();
Object val = e.getValue();
if (!primitives) {
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, keepBinary == key instanceof BinaryObject);
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, keepBinary == val instanceof BinaryObject);
} else {
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, key instanceof Integer);
assertTrue("Got unexpected object: " + key.getClass() + ", keepBinary: " + keepBinary, val instanceof Integer);
}
++size;
}
if (mode == CachePeekMode.ALL || mode == CachePeekMode.PRIMARY || mode == CachePeekMode.BACKUP || (mode == CachePeekMode.NEAR && i == 0 && ccfg.getNearConfiguration() != null))
assertTrue("Zero result at mode: " + mode, size > 0);
}
}
} finally {
if (ccfg.getEvictionPolicy() != null) {
// TODO: IGNITE-3462. Fixes evictionPolicy issues at cache destroy.
stopAllGrids();
startGridsMultiThreaded(getServerNodeCount());
} else
grid(0).destroyCache(ccfg.getName());
}
}
Aggregations