use of org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue in project ignite by apache.
the class IgniteCacheAbstractFieldsQuerySelfTest method testCacheMetaData.
/** @throws Exception If failed. */
public void testCacheMetaData() throws Exception {
for (String cacheName : grid(0).cacheNames()) ((IgniteKernal) grid(0)).getCache(cacheName).getAndPut(new GridCacheInternalKeyImpl("LONG"), new GridCacheAtomicLongValue(0));
try {
Collection<GridCacheSqlMetadata> metas = ((IgniteKernal) grid(0)).getCache(intCache.getName()).context().queries().sqlMetadata();
assert metas != null;
for (GridCacheSqlMetadata meta : metas) {
Collection<String> types = meta.types();
assertNotNull(types);
if (personCache.getName().equals(meta.cacheName())) {
assertEquals("Invalid types size", 1, types.size());
assert types.contains("Person");
if (binaryMarshaller) {
assert Object.class.getName().equals(meta.keyClass("Person"));
assert Object.class.getName().equals(meta.valueClass("Person"));
} else {
assert AffinityKey.class.getName().equals(meta.keyClass("Person"));
assert Person.class.getName().equals(meta.valueClass("Person"));
}
Map<String, String> fields = meta.fields("Person");
assert fields != null;
assert fields.size() == 3;
if (binaryMarshaller) {
assert Integer.class.getName().equals(fields.get("AGE"));
assert Integer.class.getName().equals(fields.get("ORGID"));
} else {
assert int.class.getName().equals(fields.get("AGE"));
assert int.class.getName().equals(fields.get("ORGID"));
}
assert String.class.getName().equals(fields.get("NAME"));
Collection<GridCacheSqlIndexMetadata> indexes = meta.indexes("Person");
assertNotNull("Indexes should be defined", indexes);
assertEquals(2, indexes.size());
Set<String> idxFields = new HashSet<>();
Iterator<GridCacheSqlIndexMetadata> it = indexes.iterator();
Collection<String> indFlds = it.next().fields();
assertNotNull("Fields for first index should be defined", indFlds);
assertEquals("First index should have one field", indFlds.size(), 1);
Iterator<String> indFldIt = indFlds.iterator();
idxFields.add(indFldIt.next());
indFlds = it.next().fields();
assertNotNull("Fields for second index should be defined", indFlds);
assertEquals("Second index should have one field", indFlds.size(), 1);
indFldIt = indFlds.iterator();
idxFields.add(indFldIt.next());
assertTrue(idxFields.contains("AGE"));
assertTrue(idxFields.contains("ORGID"));
} else if (orgCache.getName().equals(meta.cacheName())) {
assertEquals("Invalid types size", 1, types.size());
assert types.contains("Organization");
if (binaryMarshaller)
assert Object.class.getName().equals(meta.valueClass("Organization"));
else
assert Organization.class.getName().equals(meta.valueClass("Organization"));
assert String.class.getName().equals(meta.keyClass("Organization"));
Map<String, String> fields = meta.fields("Organization");
assert fields != null;
assertEquals("Fields: " + fields, 2, fields.size());
if (binaryMarshaller) {
assert Integer.class.getName().equals(fields.get("ID"));
} else {
assert int.class.getName().equals(fields.get("ID"));
}
assert String.class.getName().equals(fields.get("NAME"));
} else if (intCache.getName().equals(meta.cacheName())) {
assertEquals("Invalid types size", 1, types.size());
assert types.contains("Integer");
assert Integer.class.getName().equals(meta.valueClass("Integer"));
assert Integer.class.getName().equals(meta.keyClass("Integer"));
Map<String, String> fields = meta.fields("Integer");
assert fields != null;
assert fields.size() == 2;
assert Integer.class.getName().equals(fields.get("_KEY"));
assert Integer.class.getName().equals(fields.get("_VAL"));
} else if (strCache.getName().equals(meta.cacheName())) {
assertEquals("Invalid types size", 1, types.size());
assert types.contains("String");
assert String.class.getName().equals(meta.valueClass("String"));
assert String.class.getName().equals(meta.keyClass("String"));
Map<String, String> fields = meta.fields("String");
assert fields != null;
assert fields.size() == 2;
assert String.class.getName().equals(fields.get("_KEY"));
assert String.class.getName().equals(fields.get("_VAL"));
} else if (DEFAULT_CACHE_NAME.equals(meta.cacheName()))
assertTrue("Invalid types size", types.isEmpty());
else
fail("Unknown cache: " + meta.cacheName());
}
} finally {
((IgniteKernal) grid(0)).getCache(intCache.getName()).remove(new GridCacheInternalKeyImpl("LONG"));
}
}
use of org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue in project ignite by apache.
the class GridCachePartitionedNodeRestartTxSelfTest method checkCustom.
/**
* Test {@link GridCacheInternalKey}/{@link GridCacheAtomicLongValue}.
* @param name Name.
* @throws Exception If failed.
*/
private void checkCustom(String name) throws Exception {
for (int i = INIT_GRID_NUM; i < 20; i++) {
startGrid(i);
assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode();
try (Transaction tx = grid(i).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
GridCacheInternalKey key = new GridCacheInternalKeyImpl(name);
GridCacheAtomicLongValue atomicVal = ((GridCacheAtomicLongValue) grid(i).cache(DEFAULT_CACHE_NAME).get(key));
assertNotNull(atomicVal);
assertEquals("Custom check failed for node: " + i, (long) i, atomicVal.get());
atomicVal.set(i + 1);
grid(i).cache(DEFAULT_CACHE_NAME).put(key, atomicVal);
tx.commit();
}
stopGrid(i);
}
}
use of org.apache.ignite.internal.processors.datastructures.GridCacheAtomicLongValue in project ignite by apache.
the class GridCachePartitionedNodeRestartTxSelfTest method prepareCustom.
/**
* Prepare test environment.
* @param key Key.
* @throws Exception If failed.
*/
private void prepareCustom(String key) throws Exception {
// Start nodes.
for (int i = 0; i < INIT_GRID_NUM; i++) assert startGrid(i) != null;
for (int i = 0; i < INIT_GRID_NUM; i++) assert PARTITIONED == grid(i).cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class).getCacheMode();
try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
// Put custom data
grid(0).cache(DEFAULT_CACHE_NAME).put(new GridCacheInternalKeyImpl(key), new GridCacheAtomicLongValue(INIT_GRID_NUM));
tx.commit();
}
stopGrid(0);
}
Aggregations