use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.
the class CassandraDirectPersistenceTest method blobStrategyTest.
/**
*/
@Test
@SuppressWarnings("unchecked")
public void blobStrategyTest() {
CacheStore store1 = CacheStoreHelper.createCacheStore("longTypes", new ClassPathResource("org/apache/ignite/tests/persistence/blob/persistence-settings-1.xml"), CassandraHelper.getAdminDataSrc());
CacheStore store2 = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/blob/persistence-settings-2.xml"), CassandraHelper.getAdminDataSrc());
CacheStore store3 = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/blob/persistence-settings-3.xml"), CassandraHelper.getAdminDataSrc());
Collection<CacheEntryImpl<Long, Long>> longEntries = TestsHelper.generateLongsEntries();
Collection<CacheEntryImpl<Long, Person>> personEntries = TestsHelper.generateLongsPersonsEntries();
LOGGER.info("Running BLOB strategy write tests");
LOGGER.info("Running single write operation tests");
store1.write(longEntries.iterator().next());
store2.write(personEntries.iterator().next());
store3.write(personEntries.iterator().next());
LOGGER.info("Single write operation tests passed");
LOGGER.info("Running bulk write operation tests");
store1.writeAll(longEntries);
store2.writeAll(personEntries);
store3.writeAll(personEntries);
LOGGER.info("Bulk write operation tests passed");
LOGGER.info("BLOB strategy write tests passed");
LOGGER.info("Running BLOB strategy read tests");
LOGGER.info("Running single read operation tests");
Long longVal = (Long) store1.load(longEntries.iterator().next().getKey());
if (!longEntries.iterator().next().getValue().equals(longVal))
throw new RuntimeException("Long values were incorrectly deserialized from Cassandra");
Person personVal = (Person) store2.load(personEntries.iterator().next().getKey());
if (!personEntries.iterator().next().getValue().equals(personVal))
throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
personVal = (Person) store3.load(personEntries.iterator().next().getKey());
if (!personEntries.iterator().next().getValue().equals(personVal))
throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
LOGGER.info("Single read operation tests passed");
LOGGER.info("Running bulk read operation tests");
Map longValues = store1.loadAll(TestsHelper.getKeys(longEntries));
if (!TestsHelper.checkCollectionsEqual(longValues, longEntries))
throw new RuntimeException("Long values were incorrectly deserialized from Cassandra");
Map personValues = store2.loadAll(TestsHelper.getKeys(personEntries));
if (!TestsHelper.checkPersonCollectionsEqual(personValues, personEntries, false))
throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
personValues = store3.loadAll(TestsHelper.getKeys(personEntries));
if (!TestsHelper.checkPersonCollectionsEqual(personValues, personEntries, false))
throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
LOGGER.info("Bulk read operation tests passed");
LOGGER.info("BLOB strategy read tests passed");
LOGGER.info("Running BLOB strategy delete tests");
store1.delete(longEntries.iterator().next().getKey());
store1.deleteAll(TestsHelper.getKeys(longEntries));
store2.delete(personEntries.iterator().next().getKey());
store2.deleteAll(TestsHelper.getKeys(personEntries));
store3.delete(personEntries.iterator().next().getKey());
store3.deleteAll(TestsHelper.getKeys(personEntries));
LOGGER.info("BLOB strategy delete tests passed");
}
use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.
the class CassandraDirectPersistenceTest method primitiveStrategyTest.
/**
*/
@Test
@SuppressWarnings("unchecked")
public void primitiveStrategyTest() {
CacheStore store1 = CacheStoreHelper.createCacheStore("longTypes", new ClassPathResource("org/apache/ignite/tests/persistence/primitive/persistence-settings-1.xml"), CassandraHelper.getAdminDataSrc());
CacheStore store2 = CacheStoreHelper.createCacheStore("stringTypes", new ClassPathResource("org/apache/ignite/tests/persistence/primitive/persistence-settings-2.xml"), CassandraHelper.getAdminDataSrc());
Collection<CacheEntryImpl<Long, Long>> longEntries = TestsHelper.generateLongsEntries();
Collection<CacheEntryImpl<String, String>> strEntries = TestsHelper.generateStringsEntries();
Collection<Long> fakeLongKeys = TestsHelper.getKeys(longEntries);
fakeLongKeys.add(-1L);
fakeLongKeys.add(-2L);
fakeLongKeys.add(-3L);
fakeLongKeys.add(-4L);
Collection<String> fakeStrKeys = TestsHelper.getKeys(strEntries);
fakeStrKeys.add("-1");
fakeStrKeys.add("-2");
fakeStrKeys.add("-3");
fakeStrKeys.add("-4");
LOGGER.info("Running PRIMITIVE strategy write tests");
LOGGER.info("Running single write operation tests");
store1.write(longEntries.iterator().next());
store2.write(strEntries.iterator().next());
LOGGER.info("Single write operation tests passed");
LOGGER.info("Running bulk write operation tests");
store1.writeAll(longEntries);
store2.writeAll(strEntries);
LOGGER.info("Bulk write operation tests passed");
LOGGER.info("PRIMITIVE strategy write tests passed");
LOGGER.info("Running PRIMITIVE strategy read tests");
LOGGER.info("Running single read operation tests");
LOGGER.info("Running real keys read tests");
Long longVal = (Long) store1.load(longEntries.iterator().next().getKey());
if (!longEntries.iterator().next().getValue().equals(longVal))
throw new RuntimeException("Long values were incorrectly deserialized from Cassandra");
String strVal = (String) store2.load(strEntries.iterator().next().getKey());
if (!strEntries.iterator().next().getValue().equals(strVal))
throw new RuntimeException("String values were incorrectly deserialized from Cassandra");
LOGGER.info("Running fake keys read tests");
longVal = (Long) store1.load(-1L);
if (longVal != null)
throw new RuntimeException("Long value with fake key '-1' was found in Cassandra");
strVal = (String) store2.load("-1");
if (strVal != null)
throw new RuntimeException("String value with fake key '-1' was found in Cassandra");
LOGGER.info("Single read operation tests passed");
LOGGER.info("Running bulk read operation tests");
LOGGER.info("Running real keys read tests");
Map longValues = store1.loadAll(TestsHelper.getKeys(longEntries));
if (!TestsHelper.checkCollectionsEqual(longValues, longEntries))
throw new RuntimeException("Long values were incorrectly deserialized from Cassandra");
Map strValues = store2.loadAll(TestsHelper.getKeys(strEntries));
if (!TestsHelper.checkCollectionsEqual(strValues, strEntries))
throw new RuntimeException("String values were incorrectly deserialized from Cassandra");
LOGGER.info("Running fake keys read tests");
longValues = store1.loadAll(fakeLongKeys);
if (!TestsHelper.checkCollectionsEqual(longValues, longEntries))
throw new RuntimeException("Long values were incorrectly deserialized from Cassandra");
strValues = store2.loadAll(fakeStrKeys);
if (!TestsHelper.checkCollectionsEqual(strValues, strEntries))
throw new RuntimeException("String values were incorrectly deserialized from Cassandra");
LOGGER.info("Bulk read operation tests passed");
LOGGER.info("PRIMITIVE strategy read tests passed");
LOGGER.info("Running PRIMITIVE strategy delete tests");
LOGGER.info("Deleting real keys");
store1.delete(longEntries.iterator().next().getKey());
store1.deleteAll(TestsHelper.getKeys(longEntries));
store2.delete(strEntries.iterator().next().getKey());
store2.deleteAll(TestsHelper.getKeys(strEntries));
LOGGER.info("Deleting fake keys");
store1.delete(-1L);
store2.delete("-1");
store1.deleteAll(fakeLongKeys);
store2.deleteAll(fakeStrKeys);
LOGGER.info("PRIMITIVE strategy delete tests passed");
}
use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.
the class GridCacheColocatedDebugTest method checkStore.
/**
* @param ignite Grid to take store from.
* @param map Expected values in store.
* @throws Exception If failed.
*/
private void checkStore(Ignite ignite, Map<Integer, String> map) throws Exception {
String cacheName = ignite.configuration().getCacheConfiguration()[1].getName();
GridCacheContext ctx = ((IgniteKernal) ignite).context().cache().internalCache(cacheName).context();
CacheStore store = ctx.store().configuredStore();
assertEquals(map, ((GridCacheTestStore) store).getMap());
}
use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.
the class GridCacheReloadSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.CACHE_STORE);
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.EVICTION);
if (nearEnabled)
MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.NEAR_CACHE);
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalHost("127.0.0.1");
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500"));
discoSpi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discoSpi);
CacheConfiguration cacheCfg = defaultCacheConfiguration();
cacheCfg.setName(CACHE_NAME);
cacheCfg.setCacheMode(cacheMode);
LruEvictionPolicy plc = new LruEvictionPolicy();
plc.setMaxSize(MAX_CACHE_ENTRIES);
cacheCfg.setEvictionPolicy(plc);
cacheCfg.setOnheapCacheEnabled(true);
cacheCfg.setNearConfiguration(nearEnabled ? new NearCacheConfiguration() : null);
final CacheStore store = new CacheStoreAdapter<Integer, Integer>() {
@Override
public Integer load(Integer key) {
return key;
}
@Override
public void write(javax.cache.Cache.Entry<? extends Integer, ? extends Integer> e) {
// No-op.
}
@Override
public void delete(Object key) {
// No-op.
}
};
cacheCfg.setCacheStoreFactory(singletonFactory(store));
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
cacheCfg.setLoadPreviousValue(true);
if (cacheMode == PARTITIONED)
cacheCfg.setBackups(1);
cfg.setCacheConfiguration(cacheCfg);
return cfg;
}
use of org.apache.ignite.cache.store.CacheStore in project gridgain by gridgain.
the class IgniteCacheAbstractTest method cacheConfiguration.
/**
* @param igniteInstanceName Ignite instance name.
* @return Cache configuration.
* @throws Exception In case of error.
*/
@SuppressWarnings("unchecked")
protected CacheConfiguration cacheConfiguration(String igniteInstanceName) throws Exception {
CacheConfiguration cfg = defaultCacheConfiguration();
cfg.setCacheMode(cacheMode());
cfg.setAtomicityMode(atomicityMode());
cfg.setWriteSynchronizationMode(writeSynchronization());
cfg.setNearConfiguration(nearConfiguration());
cfg.setCacheLoaderFactory(loaderFactory());
if (cfg.getCacheLoaderFactory() != null)
cfg.setReadThrough(true);
cfg.setCacheWriterFactory(writerFactory());
if (cfg.getCacheWriterFactory() != null)
cfg.setWriteThrough(true);
Factory<CacheStore> storeFactory = cacheStoreFactory();
if (storeFactory != null) {
cfg.setCacheStoreFactory(storeFactory);
cfg.setReadThrough(true);
cfg.setWriteThrough(true);
cfg.setLoadPreviousValue(true);
cfg.setWriteBehindEnabled(writeBehindEnabled());
cfg.setWriteBehindCoalescing(writeBehindCoalescing());
}
if (cacheMode() == PARTITIONED)
cfg.setBackups(1);
cfg.setOnheapCacheEnabled(onheapCacheEnabled());
return cfg;
}
Aggregations