Search in sources :

Example 1 with ProductOrder

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

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

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

the class TestsHelper method generateOrdersMap.

/** */
public static Map<Long, ProductOrder> generateOrdersMap(int count) {
    Map<Long, ProductOrder> map = new HashMap<>();
    for (long i = 0; i < count; i++) {
        ProductOrder order = generateRandomOrder(i);
        map.put(order.getId(), order);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 4 with ProductOrder

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

the class TestsHelper method generateOrderEntries.

/** */
public static Collection<CacheEntryImpl<Long, ProductOrder>> generateOrderEntries() {
    Collection<CacheEntryImpl<Long, ProductOrder>> entries = new LinkedList<>();
    for (long i = 0; i < BULK_OPERATION_SIZE; i++) {
        ProductOrder order = generateRandomOrder(i);
        entries.add(new CacheEntryImpl<>(order.getId(), order));
    }
    return entries;
}
Also used : CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) LinkedList(java.util.LinkedList) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder)

Example 5 with ProductOrder

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

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