use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class BasicJavaTypesIndexTest method createPopulateAndVerify.
/**
* Executes test scenario: <ul>
* <li>Create cache</li>
* <li>Populate cache with random data</li>
* <li>Verify range query on created table</li>
* <li>Verify that table stores the same data as the generated dataset</li>
* <li>Destroy cache</li>
* </ul>
*
* @param idxCls Index type class.
* @param comp Comparator to sort data set to perform range check.
* If {@code null} range check will not be performed.
* @param keyCls Key type class. Will be used to generate KEY object
* for cache operations. If {@code null} idxCls will be used.
* @param <Key> Type of the key in terms of the cache.
* @param <Idx> Type of the indexed field.
*/
private <Key extends ClassWrapper, Idx> void createPopulateAndVerify(Class<Idx> idxCls, @Nullable Comparator<Idx> comp, @Nullable Class<Key> keyCls) {
Ignite ign = grid(0);
String tblName = idxCls.getSimpleName().toUpperCase() + "_TBL" + TBL_ID.incrementAndGet();
try {
// Create cache
LinkedHashMap<String, String> fields = new LinkedHashMap<>(2);
fields.put("idxVal", idxCls.getName());
fields.put("val", Integer.class.getName());
QueryEntity qe = new QueryEntity(keyCls == null ? idxCls.getName() : keyCls.getName(), Integer.class.getName()).setTableName(tblName).setValueFieldName("val").setFields(fields);
String idxName;
String idxFieldName;
if (keyCls == null) {
qe.setKeyFieldName("idxVal");
idxName = PK_IDX_NAME;
idxFieldName = KEY_FIELD_NAME;
} else {
idxFieldName = "idxVal";
qe.setKeyFields(Collections.singleton(idxFieldName));
if (keyCls.equals(TestKeyWithAff.class))
idxName = AFFINITY_KEY_IDX_NAME;
else {
idxName = "IDXVAL_IDX";
qe.setIndexes(Collections.singleton(new QueryIndex(idxFieldName, true, idxName)));
}
}
IgniteCache<Object, Integer> cache = ign.createCache(new CacheConfiguration<Object, Integer>(tblName + "_CACHE").setKeyConfiguration(new CacheKeyConfiguration((keyCls != null ? keyCls : idxCls).getName(), "idxVal")).setQueryEntities(Collections.singletonList(qe)).setSqlSchema("PUBLIC"));
// Then populate it with random data
Map<Idx, Integer> data = new TreeMap<>(comp);
if (keyCls == null)
populateTable(data, cache, idxCls);
else
populateTable(data, cache, keyCls, idxCls);
// Perform necessary verifications
if (comp != null)
verifyRange(data, tblName, idxFieldName, idxName, comp);
verifyEach(data, tblName, idxFieldName, idxName);
} finally {
// Destroy cache
ign.destroyCache(tblName + "_CACHE");
}
}
Aggregations