Search in sources :

Example 1 with Product

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

the class TestsHelper method generateOrdersPerProductEntries.

/** */
public static Map<Long, List<CacheEntryImpl<Long, ProductOrder>>> generateOrdersPerProductEntries(Collection<CacheEntryImpl<Long, Product>> products, int ordersPerProductCount) {
    Map<Long, List<CacheEntryImpl<Long, ProductOrder>>> map = new HashMap<>();
    for (CacheEntryImpl<Long, Product> entry : products) {
        List<CacheEntryImpl<Long, ProductOrder>> orders = new LinkedList<>();
        for (long i = 0; i < ordersPerProductCount; i++) {
            ProductOrder order = generateRandomOrder(entry.getKey());
            orders.add(new CacheEntryImpl<>(order.getId(), order));
        }
        map.put(entry.getKey(), orders);
    }
    return map;
}
Also used : CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) HashMap(java.util.HashMap) Product(org.apache.ignite.tests.pojos.Product) List(java.util.List) LinkedList(java.util.LinkedList) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder) LinkedList(java.util.LinkedList)

Example 2 with Product

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

the class TestsHelper method generateOrdersPerProductMap.

/** */
public static Map<Long, Map<Long, ProductOrder>> generateOrdersPerProductMap(Map<Long, Product> products, int ordersPerProductCount) {
    Map<Long, Map<Long, ProductOrder>> map = new HashMap<>();
    for (Map.Entry<Long, Product> entry : products.entrySet()) {
        Map<Long, ProductOrder> orders = new HashMap<>();
        for (long i = 0; i < ordersPerProductCount; i++) {
            ProductOrder order = generateRandomOrder(entry.getKey());
            orders.put(order.getId(), order);
        }
        map.put(entry.getKey(), orders);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Product(org.apache.ignite.tests.pojos.Product) HashMap(java.util.HashMap) Map(java.util.Map) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 3 with Product

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

the class TestsHelper method checkProductMapsEqual.

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

Example 4 with Product

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

the class CassandraDirectPersistenceTest method pojoStrategyTest.

/** */
@Test
@SuppressWarnings("unchecked")
public void pojoStrategyTest() {
    CacheStore store1 = CacheStoreHelper.createCacheStore("longTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-1.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore store2 = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-2.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore store3 = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore store4 = CacheStoreHelper.createCacheStore("persons", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-4.xml"), CassandraHelper.getAdminDataSrc());
    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());
    Collection<CacheEntryImpl<Long, Person>> entries1 = TestsHelper.generateLongsPersonsEntries();
    Collection<CacheEntryImpl<PersonId, Person>> entries2 = TestsHelper.generatePersonIdsPersonsEntries();
    Collection<CacheEntryImpl<PersonId, Person>> entries3 = TestsHelper.generatePersonIdsPersonsEntries();
    Collection<CacheEntryImpl<Long, Product>> productEntries = TestsHelper.generateProductEntries();
    Collection<CacheEntryImpl<Long, ProductOrder>> orderEntries = TestsHelper.generateOrderEntries();
    LOGGER.info("Running POJO strategy write tests");
    LOGGER.info("Running single write operation tests");
    store1.write(entries1.iterator().next());
    store2.write(entries2.iterator().next());
    store3.write(entries3.iterator().next());
    store4.write(entries3.iterator().next());
    productStore.write(productEntries.iterator().next());
    orderStore.write(orderEntries.iterator().next());
    LOGGER.info("Single write operation tests passed");
    LOGGER.info("Running bulk write operation tests");
    store1.writeAll(entries1);
    store2.writeAll(entries2);
    store3.writeAll(entries3);
    store4.writeAll(entries3);
    productStore.writeAll(productEntries);
    orderStore.writeAll(orderEntries);
    LOGGER.info("Bulk write operation tests passed");
    LOGGER.info("POJO strategy write tests passed");
    LOGGER.info("Running POJO strategy read tests");
    LOGGER.info("Running single read operation tests");
    Person person = (Person) store1.load(entries1.iterator().next().getKey());
    if (!entries1.iterator().next().getValue().equalsPrimitiveFields(person))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    person = (Person) store2.load(entries2.iterator().next().getKey());
    if (!entries2.iterator().next().getValue().equalsPrimitiveFields(person))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    person = (Person) store3.load(entries3.iterator().next().getKey());
    if (!entries3.iterator().next().getValue().equals(person))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    person = (Person) store4.load(entries3.iterator().next().getKey());
    if (!entries3.iterator().next().getValue().equals(person))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    Product product = (Product) productStore.load(productEntries.iterator().next().getKey());
    if (!productEntries.iterator().next().getValue().equals(product))
        throw new RuntimeException("Product values were incorrectly deserialized from Cassandra");
    ProductOrder order = (ProductOrder) orderStore.load(orderEntries.iterator().next().getKey());
    if (!orderEntries.iterator().next().getValue().equals(order))
        throw new RuntimeException("Order values were incorrectly deserialized from Cassandra");
    LOGGER.info("Single read operation tests passed");
    LOGGER.info("Running bulk read operation tests");
    Map persons = store1.loadAll(TestsHelper.getKeys(entries1));
    if (!TestsHelper.checkPersonCollectionsEqual(persons, entries1, true))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    persons = store2.loadAll(TestsHelper.getKeys(entries2));
    if (!TestsHelper.checkPersonCollectionsEqual(persons, entries2, true))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    persons = store3.loadAll(TestsHelper.getKeys(entries3));
    if (!TestsHelper.checkPersonCollectionsEqual(persons, entries3, false))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    persons = store4.loadAll(TestsHelper.getKeys(entries3));
    if (!TestsHelper.checkPersonCollectionsEqual(persons, entries3, false))
        throw new RuntimeException("Person values were incorrectly deserialized from Cassandra");
    Map products = productStore.loadAll(TestsHelper.getKeys(productEntries));
    if (!TestsHelper.checkProductCollectionsEqual(products, productEntries))
        throw new RuntimeException("Product values were incorrectly deserialized from Cassandra");
    Map orders = orderStore.loadAll(TestsHelper.getKeys(orderEntries));
    if (!TestsHelper.checkOrderCollectionsEqual(orders, orderEntries))
        throw new RuntimeException("Order values were incorrectly deserialized from Cassandra");
    LOGGER.info("Bulk read operation tests passed");
    LOGGER.info("POJO strategy read tests passed");
    LOGGER.info("Running POJO strategy delete tests");
    store1.delete(entries1.iterator().next().getKey());
    store1.deleteAll(TestsHelper.getKeys(entries1));
    store2.delete(entries2.iterator().next().getKey());
    store2.deleteAll(TestsHelper.getKeys(entries2));
    store3.delete(entries3.iterator().next().getKey());
    store3.deleteAll(TestsHelper.getKeys(entries3));
    store4.delete(entries3.iterator().next().getKey());
    store4.deleteAll(TestsHelper.getKeys(entries3));
    productStore.delete(productEntries.iterator().next().getKey());
    productStore.deleteAll(TestsHelper.getKeys(productEntries));
    orderStore.delete(orderEntries.iterator().next().getKey());
    orderStore.deleteAll(TestsHelper.getKeys(orderEntries));
    LOGGER.info("POJO strategy delete tests passed");
}
Also used : CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) Product(org.apache.ignite.tests.pojos.Product) CacheStore(org.apache.ignite.cache.store.CacheStore) Person(org.apache.ignite.tests.pojos.Person) Map(java.util.Map) ClassPathResource(org.springframework.core.io.ClassPathResource) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder) Test(org.junit.Test)

Example 5 with Product

use of org.apache.ignite.tests.pojos.Product 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)

Aggregations

Product (org.apache.ignite.tests.pojos.Product)7 ProductOrder (org.apache.ignite.tests.pojos.ProductOrder)6 Map (java.util.Map)4 CacheStore (org.apache.ignite.cache.store.CacheStore)3 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)3 Test (org.junit.Test)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 HashMap (java.util.HashMap)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 LinkedList (java.util.LinkedList)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