Search in sources :

Example 1 with PersonId

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

the class TestsHelper method generatePersonIdsPersonsEntries.

/** */
public static Collection<CacheEntryImpl<PersonId, Person>> generatePersonIdsPersonsEntries(int cnt) {
    Collection<CacheEntryImpl<PersonId, Person>> entries = new LinkedList<>();
    for (int i = 0; i < cnt; i++) {
        PersonId id = generateRandomPersonId();
        entries.add(new CacheEntryImpl<>(id, generateRandomPerson(id.getPersonNumber())));
    }
    return entries;
}
Also used : CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) PersonId(org.apache.ignite.tests.pojos.PersonId) LinkedList(java.util.LinkedList)

Example 2 with PersonId

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

the class TestsHelper method generatePersonIdsPersonsMap.

/** */
public static Map<PersonId, Person> generatePersonIdsPersonsMap(int cnt) {
    Map<PersonId, Person> map = new HashMap<>();
    for (int i = 0; i < cnt; i++) {
        PersonId id = generateRandomPersonId();
        map.put(id, generateRandomPerson(id.getPersonNumber()));
    }
    return map;
}
Also used : PersonId(org.apache.ignite.tests.pojos.PersonId) HashMap(java.util.HashMap) Person(org.apache.ignite.tests.pojos.Person)

Example 3 with PersonId

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

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

the class IgnitePersistentStoreTest method loadCacheTest.

/** */
@Test
public void loadCacheTest() {
    Ignition.stopAll(true);
    LOGGER.info("Running loadCache test");
    LOGGER.info("Filling Cassandra table with test data");
    CacheStore store = CacheStoreHelper.createCacheStore("personTypes", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-3.xml"), CassandraHelper.getAdminDataSrc());
    Collection<CacheEntryImpl<PersonId, Person>> entries = TestsHelper.generatePersonIdsPersonsEntries();
    //noinspection unchecked
    store.writeAll(entries);
    LOGGER.info("Cassandra table filled with test data");
    LOGGER.info("Running loadCache test");
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        CacheConfiguration<PersonId, Person> ccfg = new CacheConfiguration<>("cache3");
        IgniteCache<PersonId, Person> personCache3 = ignite.getOrCreateCache(ccfg);
        int size = personCache3.size(CachePeekMode.ALL);
        LOGGER.info("Initial cache size " + size);
        LOGGER.info("Loading cache data from Cassandra table");
        String qry = "select * from test1.pojo_test3 limit 3";
        personCache3.loadCache(null, qry);
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by '" + qry + "'", 3, size);
        personCache3.clear();
        personCache3.loadCache(null, new SimpleStatement(qry));
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra table by statement", 3, size);
        personCache3.clear();
        personCache3.loadCache(null);
        size = personCache3.size(CachePeekMode.ALL);
        Assert.assertEquals("Cache data was incorrectly loaded from Cassandra. " + "Expected number of records is " + TestsHelper.getBulkOperationSize() + ", but loaded number of records is " + size, TestsHelper.getBulkOperationSize(), size);
        LOGGER.info("Cache data loaded from Cassandra table");
    }
    LOGGER.info("loadCache test passed");
}
Also used : SimpleStatement(com.datastax.driver.core.SimpleStatement) ClassPathResource(org.springframework.core.io.ClassPathResource) CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) PersonId(org.apache.ignite.tests.pojos.PersonId) Ignite(org.apache.ignite.Ignite) CacheStore(org.apache.ignite.cache.store.CacheStore) Person(org.apache.ignite.tests.pojos.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

PersonId (org.apache.ignite.tests.pojos.PersonId)4 Person (org.apache.ignite.tests.pojos.Person)3 Ignite (org.apache.ignite.Ignite)2 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)2 Test (org.junit.Test)2 SimpleStatement (com.datastax.driver.core.SimpleStatement)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 CacheStore (org.apache.ignite.cache.store.CacheStore)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 Product (org.apache.ignite.tests.pojos.Product)1 ProductOrder (org.apache.ignite.tests.pojos.ProductOrder)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1