Search in sources :

Example 6 with Person

use of org.apache.ignite.tests.pojos.Person 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) SimplePersonId(org.apache.ignite.tests.pojos.SimplePersonId) PersonId(org.apache.ignite.tests.pojos.PersonId) Ignite(org.apache.ignite.Ignite) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Person(org.apache.ignite.tests.pojos.Person) ProductOrder(org.apache.ignite.tests.pojos.ProductOrder) Test(org.junit.Test)

Example 7 with Person

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

the class TestsHelper method generateRandomPerson.

/**
 */
public static Person generateRandomPerson(long personNum) {
    int phonesCnt = RANDOM.nextInt(4);
    List<String> phones = new LinkedList<>();
    for (int i = 0; i < phonesCnt; i++) phones.add(randomNumber(4));
    return new Person(personNum, randomString(4), randomString(4), (short) RANDOM.nextInt(100), RANDOM.nextBoolean(), RANDOM.nextLong(), RANDOM.nextFloat(), new Date(), phones);
}
Also used : SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Person(org.apache.ignite.tests.pojos.Person) LinkedList(java.util.LinkedList) Date(java.util.Date)

Example 8 with Person

use of org.apache.ignite.tests.pojos.Person 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 : SimplePersonId(org.apache.ignite.tests.pojos.SimplePersonId) PersonId(org.apache.ignite.tests.pojos.PersonId) HashMap(java.util.HashMap) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Person(org.apache.ignite.tests.pojos.Person)

Aggregations

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