use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.
the class CassandraDirectPersistenceTest method pojoStrategyTransactionTest.
/** */
@Test
@SuppressWarnings("unchecked")
public void pojoStrategyTransactionTest() {
Map<Object, Object> sessionProps = U.newHashMap(1);
Transaction sessionTx = new TestTransaction();
CacheStore productStore = CacheStoreHelper.createCacheStore("product", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/product.xml"), CassandraHelper.getAdminDataSrc(), new TestCacheSession("product", sessionTx, sessionProps));
CacheStore orderStore = CacheStoreHelper.createCacheStore("order", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/order.xml"), CassandraHelper.getAdminDataSrc(), new TestCacheSession("order", sessionTx, sessionProps));
List<CacheEntryImpl<Long, Product>> productEntries = TestsHelper.generateProductEntries();
Map<Long, List<CacheEntryImpl<Long, ProductOrder>>> ordersPerProduct = TestsHelper.generateOrdersPerProductEntries(productEntries, 2);
Collection<Long> productIds = TestsHelper.getProductIds(productEntries);
Collection<Long> orderIds = TestsHelper.getOrderIds(ordersPerProduct);
LOGGER.info("Running POJO strategy transaction write tests");
LOGGER.info("Running single write operation tests");
CassandraHelper.dropTestKeyspaces();
Product product = productEntries.iterator().next().getValue();
ProductOrder order = ordersPerProduct.get(product.getId()).iterator().next().getValue();
productStore.write(productEntries.iterator().next());
orderStore.write(ordersPerProduct.get(product.getId()).iterator().next());
if (productStore.load(product.getId()) != null || orderStore.load(order.getId()) != null) {
throw new RuntimeException("Single write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
}
Map<Long, Product> products = (Map<Long, Product>) productStore.loadAll(productIds);
Map<Long, ProductOrder> orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if ((products != null && !products.isEmpty()) || (orders != null && !orders.isEmpty())) {
throw new RuntimeException("Single write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
}
//noinspection deprecation
orderStore.sessionEnd(true);
//noinspection deprecation
productStore.sessionEnd(true);
Product product1 = (Product) productStore.load(product.getId());
ProductOrder order1 = (ProductOrder) orderStore.load(order.getId());
if (product1 == null || order1 == null) {
throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
}
if (!product.equals(product1) || !order.equals(order1)) {
throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "objects were incorrectly persisted/loaded to/from Cassandra");
}
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if (products == null || products.isEmpty() || orders == null || orders.isEmpty()) {
throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
}
if (products.size() > 1 || orders.size() > 1) {
throw new RuntimeException("Single write operation test failed. There were committed more objects " + "into Cassandra than expected");
}
product1 = products.entrySet().iterator().next().getValue();
order1 = orders.entrySet().iterator().next().getValue();
if (!product.equals(product1) || !order.equals(order1)) {
throw new RuntimeException("Single write operation test failed. Transaction was committed, but " + "objects were incorrectly persisted/loaded to/from Cassandra");
}
LOGGER.info("Single write operation tests passed");
LOGGER.info("Running bulk write operation tests");
CassandraHelper.dropTestKeyspaces();
sessionProps.clear();
productStore.writeAll(productEntries);
for (Long productId : ordersPerProduct.keySet()) orderStore.writeAll(ordersPerProduct.get(productId));
for (Long productId : productIds) {
if (productStore.load(productId) != null) {
throw new RuntimeException("Bulk write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
}
}
for (Long orderId : orderIds) {
if (orderStore.load(orderId) != null) {
throw new RuntimeException("Bulk write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
}
}
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if ((products != null && !products.isEmpty()) || (orders != null && !orders.isEmpty())) {
throw new RuntimeException("Bulk write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
}
//noinspection deprecation
productStore.sessionEnd(true);
//noinspection deprecation
orderStore.sessionEnd(true);
for (CacheEntryImpl<Long, Product> entry : productEntries) {
product = (Product) productStore.load(entry.getKey());
if (!entry.getValue().equals(product)) {
throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "not all objects were persisted into Cassandra");
}
}
for (Long productId : ordersPerProduct.keySet()) {
for (CacheEntryImpl<Long, ProductOrder> entry : ordersPerProduct.get(productId)) {
order = (ProductOrder) orderStore.load(entry.getKey());
if (!entry.getValue().equals(order)) {
throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "not all objects were persisted into Cassandra");
}
}
}
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if (products == null || products.isEmpty() || orders == null || orders.isEmpty()) {
throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
}
if (products.size() < productIds.size() || orders.size() < orderIds.size()) {
throw new RuntimeException("Bulk write operation test failed. There were committed less objects " + "into Cassandra than expected");
}
if (products.size() > productIds.size() || orders.size() > orderIds.size()) {
throw new RuntimeException("Bulk write operation test failed. There were committed more objects " + "into Cassandra than expected");
}
for (CacheEntryImpl<Long, Product> entry : productEntries) {
product = products.get(entry.getKey());
if (!entry.getValue().equals(product)) {
throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "some objects were incorrectly persisted/loaded to/from Cassandra");
}
}
for (Long productId : ordersPerProduct.keySet()) {
for (CacheEntryImpl<Long, ProductOrder> entry : ordersPerProduct.get(productId)) {
order = orders.get(entry.getKey());
if (!entry.getValue().equals(order)) {
throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "some objects were incorrectly persisted/loaded to/from Cassandra");
}
}
}
LOGGER.info("Bulk write operation tests passed");
LOGGER.info("POJO strategy transaction write tests passed");
LOGGER.info("Running POJO strategy transaction delete tests");
LOGGER.info("Running single delete tests");
sessionProps.clear();
Product deletedProduct = productEntries.remove(0).getValue();
ProductOrder deletedOrder = ordersPerProduct.get(deletedProduct.getId()).remove(0).getValue();
productStore.delete(deletedProduct.getId());
orderStore.delete(deletedOrder.getId());
if (productStore.load(deletedProduct.getId()) == null || orderStore.load(deletedOrder.getId()) == null) {
throw new RuntimeException("Single delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
}
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if (products.size() != productIds.size() || orders.size() != orderIds.size()) {
throw new RuntimeException("Single delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
}
//noinspection deprecation
productStore.sessionEnd(true);
//noinspection deprecation
orderStore.sessionEnd(true);
if (productStore.load(deletedProduct.getId()) != null || orderStore.load(deletedOrder.getId()) != null) {
throw new RuntimeException("Single delete operation test failed. Transaction was committed, but " + "objects were not deleted from Cassandra");
}
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if (products.get(deletedProduct.getId()) != null || orders.get(deletedOrder.getId()) != null) {
throw new RuntimeException("Single delete operation test failed. Transaction was committed, but " + "objects were not deleted from Cassandra");
}
LOGGER.info("Single delete tests passed");
LOGGER.info("Running bulk delete tests");
sessionProps.clear();
productStore.deleteAll(productIds);
orderStore.deleteAll(orderIds);
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if (products == null || products.isEmpty() || orders == null || orders.isEmpty()) {
throw new RuntimeException("Bulk delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
}
//noinspection deprecation
orderStore.sessionEnd(true);
//noinspection deprecation
productStore.sessionEnd(true);
products = (Map<Long, Product>) productStore.loadAll(productIds);
orders = (Map<Long, ProductOrder>) orderStore.loadAll(orderIds);
if ((products != null && !products.isEmpty()) || (orders != null && !orders.isEmpty())) {
throw new RuntimeException("Bulk delete operation test failed. Transaction was committed, but " + "objects were not deleted from Cassandra");
}
LOGGER.info("Bulk delete tests passed");
LOGGER.info("POJO strategy transaction delete tests passed");
}
use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.
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 ignite by apache.
the class CacheOsStoreManager method start0.
/** {@inheritDoc} */
@Override
protected void start0() throws IgniteCheckedException {
if (configured()) {
CacheStore store = configuredStore();
assert store != null;
assert !(store instanceof GridCacheWriteBehindStore);
if (store instanceof PlatformCacheStore) {
PlatformProcessor proc = ctx.platform();
proc.registerStore((PlatformCacheStore) store, configuredConvertBinary());
}
}
super.start0();
}
use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.
the class GridCacheJdbcBlobStoreMultithreadedSelfTest method checkOpenedClosedCount.
/**
*
*/
private void checkOpenedClosedCount() {
assertEquals(GRID_CNT, Ignition.allGrids().size());
for (Ignite ignite : Ignition.allGrids()) {
GridCacheContext cctx = ((IgniteKernal) ignite).internalCache(DEFAULT_CACHE_NAME).context();
CacheStore store = cctx.store().configuredStore();
long opened = ((LongAdder8) U.field(store, "opened")).sum();
long closed = ((LongAdder8) U.field(store, "closed")).sum();
assert opened > 0;
assert closed > 0;
assertEquals(opened, closed);
}
}
use of org.apache.ignite.cache.store.CacheStore in project ignite by apache.
the class GridCacheColocatedDebugTest method clearStores.
/**
* Clears all stores.
*
* @param cnt Grid count.
*/
private void clearStores(int cnt) {
for (int i = 0; i < cnt; i++) {
String cacheName = grid(i).configuration().getCacheConfiguration()[0].getName();
GridCacheContext ctx = ((IgniteKernal) grid()).context().cache().internalCache(cacheName).context();
CacheStore store = ctx.store().configuredStore();
((GridCacheTestStore) store).reset();
}
}
Aggregations