use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class ThinClientAbstractPartitionAwarenessTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setConsistentId(igniteInstanceName);
CacheConfiguration ccfg0 = new CacheConfiguration().setName(REPL_CACHE_NAME).setCacheMode(CacheMode.REPLICATED);
CacheConfiguration ccfg1 = new CacheConfiguration().setName(PART_CUSTOM_AFFINITY_CACHE_NAME).setCacheMode(CacheMode.PARTITIONED).setAffinity(new CustomAffinityFunction());
CacheConfiguration ccfg2 = new CacheConfiguration().setName(PART_CACHE_NAME).setCacheMode(CacheMode.PARTITIONED).setKeyConfiguration(new CacheKeyConfiguration(TestNotAnnotatedAffinityKey.class.getName(), "affinityKey"), new CacheKeyConfiguration(TestAnnotatedAffinityKey.class));
CacheConfiguration ccfg3 = new CacheConfiguration().setName(PART_CACHE_0_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(0);
CacheConfiguration ccfg4 = new CacheConfiguration().setName(PART_CACHE_1_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(1);
CacheConfiguration ccfg5 = new CacheConfiguration().setName(PART_CACHE_3_BACKUPS_NAME).setCacheMode(CacheMode.PARTITIONED).setBackups(3);
return cfg.setCacheConfiguration(ccfg0, ccfg1, ccfg2, ccfg3, ccfg4, ccfg5);
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class AffinityKeyNameAndValueFieldNameConflictTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
CacheConfiguration ccfg = new CacheConfiguration(PERSON_CACHE);
if (qryEntityCfg) {
CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(keyCls.getName(), "name");
cfg.setCacheKeyConfiguration(keyCfg);
QueryEntity entity = new QueryEntity();
entity.setKeyType(keyCls.getName());
entity.setValueType(Person.class.getName());
if (keyFieldSpecified)
entity.setKeyFields(Stream.of("name").collect(Collectors.toSet()));
entity.addQueryField("id", Integer.class.getName(), null);
entity.addQueryField("name", String.class.getName(), null);
ccfg.setQueryEntities(F.asList(entity));
} else {
CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(keyCls);
cfg.setCacheKeyConfiguration(keyCfg);
ccfg.setIndexedTypes(keyCls, Person.class);
}
cfg.setCacheConfiguration(ccfg);
return cfg;
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class PojoIndexLocalQueryTest 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");
}
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunAbstractTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
// Enables template with default test configuration
cfg.setCacheConfiguration(F.concat(cfg.getCacheConfiguration(), cacheConfiguration(igniteInstanceName).setName("*")));
((TcpCommunicationSpi) cfg.getCommunicationSpi()).setSharedMemoryPort(-1);
cfg.setMarshaller(new BinaryMarshaller());
// TODO remove key configuration when https://issues.apache.org/jira/browse/IGNITE-5795 is fixed.
cfg.setCacheKeyConfiguration(new CacheKeyConfiguration(Person.Key.class.getName(), "orgId"));
AlwaysFailoverSpi failSpi = new AlwaysFailoverSpi();
failSpi.setMaximumFailoverAttempts(MAX_FAILOVER_ATTEMPTS);
cfg.setFailoverSpi(failSpi);
return cfg;
}
use of org.apache.ignite.cache.CacheKeyConfiguration in project ignite by apache.
the class IgniteCachelessQueriesSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(gridName);
CacheKeyConfiguration keyCfg = new CacheKeyConfiguration("MyCache", "affKey");
cfg.setCacheKeyConfiguration(keyCfg);
cfg.setPeerClassLoadingEnabled(false);
return cfg;
}
Aggregations