Search in sources :

Example 6 with ProductOrder

use of org.apache.ignite.tests.pojos.ProductOrder in project ignite by apache.

the class TestsHelper method checkOrderMapsEqual.

/** */
public static <K> boolean checkOrderMapsEqual(Map<K, ProductOrder> map1, Map<K, ProductOrder> map2) {
    if (map1 == null || map2 == null || map1.size() != map2.size())
        return false;
    for (K key : map1.keySet()) {
        ProductOrder order1 = map1.get(key);
        ProductOrder order2 = map2.get(key);
        boolean equals = order1 != null && order2 != null && order1.equals(order2);
        if (!equals)
            return false;
    }
    return true;
}
Also used : ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 7 with ProductOrder

use of org.apache.ignite.tests.pojos.ProductOrder in project ignite by apache.

the class IgnitePersistentStoreTest method pojoStrategyTest.

/** */
@Test
public void pojoStrategyTest() {
    Ignition.stopAll(true);
    LOGGER.info("Running POJO strategy write tests");
    Map<Long, Person> personMap1 = TestsHelper.generateLongsPersonsMap();
    Map<PersonId, Person> personMap2 = TestsHelper.generatePersonIdsPersonsMap();
    Map<Long, Product> productsMap = TestsHelper.generateProductsMap();
    Map<Long, ProductOrder> ordersMap = TestsHelper.generateOrdersMap();
    Product product = TestsHelper.generateRandomProduct(-1L);
    ProductOrder order = TestsHelper.generateRandomOrder(-1L);
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        IgniteCache<Long, Person> personCache1 = ignite.getOrCreateCache(new CacheConfiguration<Long, Person>("cache1"));
        IgniteCache<PersonId, Person> personCache2 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache2"));
        IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache3"));
        IgniteCache<PersonId, Person> personCache4 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache4"));
        IgniteCache<Long, Product> productCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Product>("product"));
        IgniteCache<Long, ProductOrder> orderCache = ignite.getOrCreateCache(new CacheConfiguration<Long, ProductOrder>("order"));
        LOGGER.info("Running single operation write tests");
        personCache1.put(1L, TestsHelper.generateRandomPerson(1L));
        PersonId id = TestsHelper.generateRandomPersonId();
        personCache2.put(id, TestsHelper.generateRandomPerson(id.getPersonNumber()));
        id = TestsHelper.generateRandomPersonId();
        personCache3.put(id, TestsHelper.generateRandomPerson(id.getPersonNumber()));
        personCache4.put(id, TestsHelper.generateRandomPerson(id.getPersonNumber()));
        productCache.put(product.getId(), product);
        orderCache.put(order.getId(), order);
        LOGGER.info("Single operation write tests passed");
        LOGGER.info("Running bulk operation write tests");
        personCache1.putAll(personMap1);
        personCache2.putAll(personMap2);
        personCache3.putAll(personMap2);
        personCache4.putAll(personMap2);
        productCache.putAll(productsMap);
        orderCache.putAll(ordersMap);
        LOGGER.info("Bulk operation write tests passed");
    }
    LOGGER.info("POJO strategy write tests passed");
    Ignition.stopAll(true);
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        LOGGER.info("Running POJO strategy read tests");
        IgniteCache<Long, Person> personCache1 = ignite.getOrCreateCache(new CacheConfiguration<Long, Person>("cache1"));
        IgniteCache<PersonId, Person> personCache2 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache2"));
        IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache3"));
        IgniteCache<PersonId, Person> personCache4 = ignite.getOrCreateCache(new CacheConfiguration<PersonId, Person>("cache4"));
        IgniteCache<Long, Product> productCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Product>("product"));
        IgniteCache<Long, ProductOrder> orderCache = ignite.getOrCreateCache(new CacheConfiguration<Long, ProductOrder>("order"));
        LOGGER.info("Running single operation read tests");
        Person person = personCache1.get(1L);
        if (!person.equalsPrimitiveFields(personMap1.get(1L)))
            throw new RuntimeException("Person value was incorrectly deserialized from Cassandra");
        PersonId id = personMap2.keySet().iterator().next();
        person = personCache2.get(id);
        if (!person.equalsPrimitiveFields(personMap2.get(id)))
            throw new RuntimeException("Person value was incorrectly deserialized from Cassandra");
        person = personCache3.get(id);
        if (!person.equals(personMap2.get(id)))
            throw new RuntimeException("Person value was incorrectly deserialized from Cassandra");
        person = personCache4.get(id);
        if (!person.equals(personMap2.get(id)))
            throw new RuntimeException("Person value was incorrectly deserialized from Cassandra");
        Product product1 = productCache.get(product.getId());
        if (!product.equals(product1))
            throw new RuntimeException("Product value was incorrectly deserialized from Cassandra");
        ProductOrder order1 = orderCache.get(order.getId());
        if (!order.equals(order1))
            throw new RuntimeException("Order value was incorrectly deserialized from Cassandra");
        LOGGER.info("Single operation read tests passed");
        LOGGER.info("Running bulk operation read tests");
        Map<Long, Person> persons1 = personCache1.getAll(personMap1.keySet());
        if (!TestsHelper.checkPersonMapsEqual(persons1, personMap1, true))
            throw new RuntimeException("Persons values batch was incorrectly deserialized from Cassandra");
        Map<PersonId, Person> persons2 = personCache2.getAll(personMap2.keySet());
        if (!TestsHelper.checkPersonMapsEqual(persons2, personMap2, true))
            throw new RuntimeException("Person values batch was incorrectly deserialized from Cassandra");
        Map<PersonId, Person> persons3 = personCache3.getAll(personMap2.keySet());
        if (!TestsHelper.checkPersonMapsEqual(persons3, personMap2, false))
            throw new RuntimeException("Person values batch was incorrectly deserialized from Cassandra");
        Map<PersonId, Person> persons4 = personCache4.getAll(personMap2.keySet());
        if (!TestsHelper.checkPersonMapsEqual(persons4, personMap2, false))
            throw new RuntimeException("Person values batch was incorrectly deserialized from Cassandra");
        Map<Long, Product> productsMap1 = productCache.getAll(productsMap.keySet());
        if (!TestsHelper.checkProductMapsEqual(productsMap, productsMap1))
            throw new RuntimeException("Product values batch was incorrectly deserialized from Cassandra");
        Map<Long, ProductOrder> ordersMap1 = orderCache.getAll(ordersMap.keySet());
        if (!TestsHelper.checkOrderMapsEqual(ordersMap, ordersMap1))
            throw new RuntimeException("Order values batch was incorrectly deserialized from Cassandra");
        LOGGER.info("Bulk operation read tests passed");
        LOGGER.info("POJO strategy read tests passed");
        LOGGER.info("Running POJO strategy delete tests");
        personCache1.remove(1L);
        personCache1.removeAll(personMap1.keySet());
        personCache2.remove(id);
        personCache2.removeAll(personMap2.keySet());
        personCache3.remove(id);
        personCache3.removeAll(personMap2.keySet());
        personCache4.remove(id);
        personCache4.removeAll(personMap2.keySet());
        productCache.remove(product.getId());
        productCache.removeAll(productsMap.keySet());
        orderCache.remove(order.getId());
        orderCache.removeAll(ordersMap.keySet());
        LOGGER.info("POJO strategy delete tests passed");
    }
}
Also used : Product(org.apache.ignite.tests.pojos.Product) PersonId(org.apache.ignite.tests.pojos.PersonId) Ignite(org.apache.ignite.Ignite) Person(org.apache.ignite.tests.pojos.Person) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder) Test(org.junit.Test)

Example 8 with ProductOrder

use of org.apache.ignite.tests.pojos.ProductOrder in project ignite by apache.

the class IgnitePersistentStoreTest method pojoStrategyTransactionTest.

/** */
@SuppressWarnings("unchecked")
private void pojoStrategyTransactionTest(Ignite ignite, TransactionConcurrency concurrency, TransactionIsolation isolation) {
    LOGGER.info("-----------------------------------------------------------------------------------");
    LOGGER.info("Running POJO transaction tests using " + concurrency + " concurrency and " + isolation + " isolation level");
    LOGGER.info("-----------------------------------------------------------------------------------");
    CacheStore productStore = CacheStoreHelper.createCacheStore("product", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/product.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore orderStore = CacheStoreHelper.createCacheStore("order", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/order.xml"), CassandraHelper.getAdminDataSrc());
    Map<Long, Product> productsMap = TestsHelper.generateProductsMap(5);
    Map<Long, Product> productsMap1;
    Map<Long, ProductOrder> ordersMap = TestsHelper.generateOrdersMap(5);
    Map<Long, ProductOrder> ordersMap1;
    Product product = TestsHelper.generateRandomProduct(-1L);
    ProductOrder order = TestsHelper.generateRandomOrder(-1L, -1L, new Date());
    IgniteTransactions txs = ignite.transactions();
    IgniteCache<Long, Product> productCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Product>("product"));
    IgniteCache<Long, ProductOrder> orderCache = ignite.getOrCreateCache(new CacheConfiguration<Long, ProductOrder>("order"));
    LOGGER.info("Running POJO strategy write tests");
    LOGGER.info("Running single operation write tests");
    Transaction tx = txs.txStart(concurrency, isolation);
    try {
        productCache.put(product.getId(), product);
        orderCache.put(order.getId(), order);
        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(productsMap.keySet());
        Map<Long, ProductOrder> orders = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        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");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    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");
    }
    LOGGER.info("Single operation write tests passed");
    LOGGER.info("Running bulk operation write tests");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.putAll(productsMap);
        orderCache.putAll(ordersMap);
        productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
        ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        if ((productsMap1 != null && !productsMap1.isEmpty()) || (ordersMap1 != null && !ordersMap1.isEmpty())) {
            throw new RuntimeException("Bulk write operation test failed. Transaction wasn't committed yet, but " + "objects were already persisted into Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
    ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
    if (productsMap1 == null || productsMap1.isEmpty() || ordersMap1 == null || ordersMap1.isEmpty()) {
        throw new RuntimeException("Bulk write operation test failed. Transaction was committed, but " + "no objects were persisted into Cassandra");
    }
    if (productsMap1.size() < productsMap.size() || ordersMap1.size() < ordersMap.size()) {
        throw new RuntimeException("Bulk write operation test failed. There were committed less objects " + "into Cassandra than expected");
    }
    if (productsMap1.size() > productsMap.size() || ordersMap1.size() > ordersMap.size()) {
        throw new RuntimeException("Bulk write operation test failed. There were committed more objects " + "into Cassandra than expected");
    }
    for (Map.Entry<Long, Product> entry : productsMap.entrySet()) {
        product = productsMap1.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 (Map.Entry<Long, ProductOrder> entry : ordersMap.entrySet()) {
        order = ordersMap1.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 operation write tests passed");
    LOGGER.info("POJO strategy write tests passed");
    LOGGER.info("Running POJO strategy delete tests");
    LOGGER.info("Running single delete tests");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.remove(-1L);
        orderCache.remove(-1L);
        if (productStore.load(-1L) == null || orderStore.load(-1L) == null) {
            throw new RuntimeException("Single delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    if (productStore.load(-1L) != null || orderStore.load(-1L) != 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");
    tx = txs.txStart(concurrency, isolation);
    try {
        productCache.removeAll(productsMap.keySet());
        orderCache.removeAll(ordersMap.keySet());
        productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
        ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
        if (productsMap1.size() != productsMap.size() || ordersMap1.size() != ordersMap.size()) {
            throw new RuntimeException("Bulk delete operation test failed. Transaction wasn't committed yet, but " + "objects were already deleted from Cassandra");
        }
        tx.commit();
    } finally {
        U.closeQuiet(tx);
    }
    productsMap1 = (Map<Long, Product>) productStore.loadAll(productsMap.keySet());
    ordersMap1 = (Map<Long, ProductOrder>) orderStore.loadAll(ordersMap.keySet());
    if ((productsMap1 != null && !productsMap1.isEmpty()) || (ordersMap1 != null && !ordersMap1.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 delete tests passed");
    LOGGER.info("-----------------------------------------------------------------------------------");
    LOGGER.info("Passed POJO transaction tests for " + concurrency + " concurrency and " + isolation + " isolation level");
    LOGGER.info("-----------------------------------------------------------------------------------");
}
Also used : Product(org.apache.ignite.tests.pojos.Product) IgniteTransactions(org.apache.ignite.IgniteTransactions) ClassPathResource(org.springframework.core.io.ClassPathResource) Date(java.util.Date) Transaction(org.apache.ignite.transactions.Transaction) CacheStore(org.apache.ignite.cache.store.CacheStore) Map(java.util.Map) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 9 with ProductOrder

use of org.apache.ignite.tests.pojos.ProductOrder 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");
}
Also used : TestCacheSession(org.apache.ignite.tests.utils.TestCacheSession) TestTransaction(org.apache.ignite.tests.utils.TestTransaction) Product(org.apache.ignite.tests.pojos.Product) ClassPathResource(org.springframework.core.io.ClassPathResource) CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) Transaction(org.apache.ignite.transactions.Transaction) TestTransaction(org.apache.ignite.tests.utils.TestTransaction) List(java.util.List) CacheStore(org.apache.ignite.cache.store.CacheStore) Map(java.util.Map) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder) Test(org.junit.Test)

Aggregations

ProductOrder (org.apache.ignite.tests.pojos.ProductOrder)9 Product (org.apache.ignite.tests.pojos.Product)6 Map (java.util.Map)4 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)4 HashMap (java.util.HashMap)3 CacheStore (org.apache.ignite.cache.store.CacheStore)3 Test (org.junit.Test)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Person (org.apache.ignite.tests.pojos.Person)2 Transaction (org.apache.ignite.transactions.Transaction)2 Date (java.util.Date)1 Ignite (org.apache.ignite.Ignite)1 IgniteTransactions (org.apache.ignite.IgniteTransactions)1 PersonId (org.apache.ignite.tests.pojos.PersonId)1 TestCacheSession (org.apache.ignite.tests.utils.TestCacheSession)1 TestTransaction (org.apache.ignite.tests.utils.TestTransaction)1