Search in sources :

Example 1 with Person

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

the class TestsHelper method checkPersonMapsEqual.

/** */
public static <K> boolean checkPersonMapsEqual(Map<K, Person> map1, Map<K, Person> map2, boolean primitiveFieldsOnly) {
    if (map1 == null || map2 == null || map1.size() != map2.size())
        return false;
    for (K key : map1.keySet()) {
        Person person1 = map1.get(key);
        Person person2 = map2.get(key);
        boolean equals = person1 != null && person2 != null && (primitiveFieldsOnly ? person1.equalsPrimitiveFields(person2) : person1.equals(person2));
        if (!equals)
            return false;
    }
    return true;
}
Also used : Person(org.apache.ignite.tests.pojos.Person)

Example 2 with Person

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

the class IgnitePersistentStoreTest method blobStrategyTest.

/** */
@Test
public void blobStrategyTest() {
    Ignition.stopAll(true);
    Map<Long, Long> longMap = TestsHelper.generateLongsMap();
    Map<Long, Person> personMap = TestsHelper.generateLongsPersonsMap();
    LOGGER.info("Running BLOB strategy write tests");
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/blob/ignite-config.xml")) {
        IgniteCache<Long, Long> longCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Long>("cache1"));
        IgniteCache<Long, Person> personCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Person>("cache2"));
        LOGGER.info("Running single operation write tests");
        longCache.put(1L, 1L);
        personCache.put(1L, TestsHelper.generateRandomPerson(1L));
        LOGGER.info("Single operation write tests passed");
        LOGGER.info("Running bulk operation write tests");
        longCache.putAll(longMap);
        personCache.putAll(personMap);
        LOGGER.info("Bulk operation write tests passed");
    }
    LOGGER.info("BLOB strategy write tests passed");
    Ignition.stopAll(true);
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/blob/ignite-config.xml")) {
        LOGGER.info("Running BLOB strategy read tests");
        IgniteCache<Long, Long> longCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Long>("cache1"));
        IgniteCache<Long, Person> personCache = ignite.getOrCreateCache(new CacheConfiguration<Long, Person>("cache2"));
        LOGGER.info("Running single operation read tests");
        Long longVal = longCache.get(1L);
        if (!longVal.equals(longMap.get(1L)))
            throw new RuntimeException("Long value was incorrectly deserialized from Cassandra");
        Person person = personCache.get(1L);
        if (!person.equals(personMap.get(1L)))
            throw new RuntimeException("Person value was incorrectly deserialized from Cassandra");
        LOGGER.info("Single operation read tests passed");
        LOGGER.info("Running bulk operation read tests");
        Map<Long, Long> longMap1 = longCache.getAll(longMap.keySet());
        if (!TestsHelper.checkMapsEqual(longMap, longMap1))
            throw new RuntimeException("Long values batch was incorrectly deserialized from Cassandra");
        Map<Long, Person> personMap1 = personCache.getAll(personMap.keySet());
        if (!TestsHelper.checkPersonMapsEqual(personMap, personMap1, false))
            throw new RuntimeException("Person values batch was incorrectly deserialized from Cassandra");
        LOGGER.info("Bulk operation read tests passed");
        LOGGER.info("BLOB strategy read tests passed");
        LOGGER.info("Running BLOB strategy delete tests");
        longCache.remove(1L);
        longCache.removeAll(longMap.keySet());
        personCache.remove(1L);
        personCache.removeAll(personMap.keySet());
        LOGGER.info("BLOB strategy delete tests passed");
    }
}
Also used : Ignite(org.apache.ignite.Ignite) Person(org.apache.ignite.tests.pojos.Person) Test(org.junit.Test)

Example 3 with Person

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

Example 5 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), RANDOM.nextInt(100), RANDOM.nextBoolean(), RANDOM.nextLong(), RANDOM.nextFloat(), new Date(), phones);
}
Also used : Person(org.apache.ignite.tests.pojos.Person) LinkedList(java.util.LinkedList) Date(java.util.Date)

Aggregations

Person (org.apache.ignite.tests.pojos.Person)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 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