use of javax.cache.Cache in project ignite by apache.
the class SqlSystemViewsSelfTest method testIoStatisticsViews.
/**
* Test IO statistics SQL system views for cache groups.
*
* @throws Exception
*/
@Test
public void testIoStatisticsViews() throws Exception {
Ignite ignite = startGrid(getTestIgniteInstanceName(), getPdsConfiguration("node0"));
ignite.cluster().active(true);
execSql("CREATE TABLE TST(id INTEGER PRIMARY KEY, name VARCHAR, age integer)");
for (int i = 0; i < 500; i++) execSql("INSERT INTO TST(id, name, age) VALUES (" + i + ",'name-" + i + "'," + i + 1 + ")");
String sql1 = "SELECT CACHE_GROUP_ID, CACHE_GROUP_NAME, PHYSICAL_READS, LOGICAL_READS FROM " + systemSchemaName() + ".LOCAL_CACHE_GROUPS_IO";
List<List<?>> res1 = execSql(sql1);
Map<?, ?> map = res1.stream().collect(Collectors.toMap(k -> k.get(1), v -> v.get(3)));
assertEquals(2, map.size());
assertTrue(map.containsKey("SQL_PUBLIC_TST"));
assertTrue((Long) map.get("SQL_PUBLIC_TST") > 0);
assertTrue(map.containsKey(DEFAULT_CACHE_NAME));
sql1 = "SELECT CACHE_GROUP_ID, CACHE_GROUP_NAME, PHYSICAL_READS, LOGICAL_READS FROM " + systemSchemaName() + ".LOCAL_CACHE_GROUPS_IO WHERE CACHE_GROUP_NAME='SQL_PUBLIC_TST'";
assertEquals(1, execSql(sql1).size());
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteWalReaderTest method testRebalanceFlag.
/**
* Tests transaction generation and WAL for putAll cache operation.
*
* @throws Exception if failed.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DISABLE_WAL_DURING_REBALANCING, value = "false")
public void testRebalanceFlag() throws Exception {
backupCnt = 1;
IgniteEx ignite = startGrid("node0");
Ignite ignite1 = startGrid(1);
ignite.cluster().state(ACTIVE);
IgniteCache<Integer, IndexedObject> cache = ignite.cache(CACHE_NAME);
int cntEntries = 100;
List<Integer> keys = findKeys(ignite.localNode(), cache, cntEntries, 0, 0);
Map<Integer, IndexedObject> map = new TreeMap<>();
for (Integer key : keys) map.putIfAbsent(key, new IndexedObject(key));
cache.putAll(map);
Ignite ignite2 = startGrid(2);
ignite.cluster().setBaselineTopology(ignite2.cluster().topologyVersion());
backupCnt = 0;
awaitPartitionMapExchange(false, true, null);
String subfolderName1 = genDbSubfolderName(ignite, 0);
String subfolderName2 = genDbSubfolderName(ignite1, 1);
String subfolderName3 = genDbSubfolderName(ignite2, 2);
stopAllGrids();
String workDir = U.defaultWorkDirectory();
IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
Map<GridCacheOperation, Integer> operationsFound = new EnumMap<>(GridCacheOperation.class);
IgniteInClosure<DataRecord> drHnd = dataRecord -> {
for (int i = 0; i < dataRecord.entryCount(); i++) {
DataEntry entry = dataRecord.get(i);
GridCacheOperation op = entry.op();
Integer cnt = operationsFound.get(op);
operationsFound.put(op, cnt == null ? 1 : (cnt + 1));
}
};
scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName1).filesOrDirs(workDir + "/db/wal/" + subfolderName1, workDir + "/db/wal/archive/" + subfolderName1), 1, 1, null, drHnd);
primary = false;
scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName2).filesOrDirs(workDir + "/db/wal/" + subfolderName2, workDir + "/db/wal/archive/" + subfolderName2), 1, 1, null, drHnd);
rebalance = true;
scanIterateAndCount(factory, createIteratorParametersBuilder(workDir, subfolderName3).filesOrDirs(workDir + "/db/wal/" + subfolderName3, workDir + "/db/wal/archive/" + subfolderName3), 1, 0, null, drHnd);
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteWalReaderTest method testIteratorWithCurrentKernelContext.
/**
* Tests WAL iterator which uses shared cache context of currently started Ignite node.
*/
@Test
public void testIteratorWithCurrentKernelContext() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
int cntEntries = 100;
putDummyRecords(ignite, cntEntries);
String workDir = U.defaultWorkDirectory();
IgniteWalIteratorFactory factory = new IgniteWalIteratorFactory(log);
IteratorParametersBuilder iterParametersBuilder = createIteratorParametersBuilder(workDir, genDbSubfolderName(ignite, 0)).filesOrDirs(workDir).binaryMetadataFileStoreDir(null).marshallerMappingFileStoreDir(null).sharedContext(ignite.context().cache().context());
AtomicInteger cnt = new AtomicInteger();
IgniteBiInClosure<Object, Object> objConsumer = (key, val) -> {
if (val instanceof IndexedObject) {
assertEquals(key, ((IndexedObject) val).iVal);
assertEquals(key, cnt.getAndIncrement());
}
};
iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), objConsumer, null);
assertEquals(cntEntries, cnt.get());
// Test without converting non primary types.
iterParametersBuilder.keepBinary(true);
cnt.set(0);
IgniteBiInClosure<Object, Object> binObjConsumer = (key, val) -> {
if (val instanceof BinaryObject) {
assertEquals(key, ((BinaryObject) val).field("iVal"));
assertEquals(key, cnt.getAndIncrement());
}
};
iterateAndCountDataRecord(factory.iterator(iterParametersBuilder.copy()), binObjConsumer, null);
assertEquals(cntEntries, cnt.get());
}
use of javax.cache.Cache in project ignite by apache.
the class GridCommonAbstractTest method assertCountersSame.
/**
* @param partId Partition.
* @param withReserveCntr {@code True} to compare reserve counters. Because reserve counters are synced during
* @param cacheName Cache name.
* PME invoking with {@code true} makes sense only after PME was finished.
*/
protected void assertCountersSame(int partId, boolean withReserveCntr, String cacheName) throws AssertionFailedError {
PartitionUpdateCounter cntr0 = null;
List<T3<String, @Nullable PartitionUpdateCounter, Boolean>> cntrMap = G.allGrids().stream().filter(ignite -> !ignite.configuration().isClientMode()).map(ignite -> new T3<>(ignite.name(), counter(partId, cacheName, ignite.name()), ignite.affinity(cacheName).isPrimary(ignite.cluster().localNode(), partId))).collect(toList());
for (T3<String, PartitionUpdateCounter, Boolean> cntr : cntrMap) {
if (cntr.get2() == null)
continue;
if (cntr0 != null) {
assertEquals("Expecting same counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0, cntr.get2());
if (withReserveCntr)
assertEquals("Expecting same reservation counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0.reserved(), cntr.get2().reserved());
}
cntr0 = cntr.get2();
}
}
use of javax.cache.Cache in project ignite by apache.
the class IgniteCacheReplicatedQuerySelfTest method testClientOnlyNode.
/**
* @throws Exception If failed.
*/
@Test
public void testClientOnlyNode() throws Exception {
try (Ignite g = startClientGrid("client")) {
IgniteCache<Integer, Integer> c = jcache(g, Integer.class, Integer.class);
for (int i = 0; i < 10; i++) c.put(i, i);
// Client cache should be empty.
assertEquals(0, c.localSize());
Collection<Cache.Entry<Integer, Integer>> res = c.query(new SqlQuery<Integer, Integer>(Integer.class, "_key >= 5 order by _key")).getAll();
assertEquals(5, res.size());
int i = 5;
for (Cache.Entry<Integer, Integer> e : res) {
assertEquals(i, e.getKey().intValue());
assertEquals(i, e.getValue().intValue());
i++;
}
}
}
Aggregations