Search in sources :

Example 1 with SimplePerson

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

the class IgnitePersistentStoreTest method pojoStrategySimpleObjectsTest.

/**
 */
@Test
public void pojoStrategySimpleObjectsTest() {
    Ignition.stopAll(true);
    LOGGER.info("Running POJO strategy write tests for simple objects");
    Map<SimplePersonId, SimplePerson> personMap5 = TestsHelper.generateSimplePersonIdsPersonsMap();
    Map<SimplePersonId, SimplePerson> personMap6 = TestsHelper.generateSimplePersonIdsPersonsMap();
    try (Ignite ignite = Ignition.start("org/apache/ignite/tests/persistence/pojo/ignite-config.xml")) {
        IgniteCache<SimplePersonId, SimplePerson> personCache5 = ignite.getOrCreateCache(new CacheConfiguration<SimplePersonId, SimplePerson>("cache5"));
        IgniteCache<SimplePersonId, SimplePerson> personCache6 = ignite.getOrCreateCache(new CacheConfiguration<SimplePersonId, SimplePerson>("cache6"));
        LOGGER.info("Running single operation write tests");
        SimplePersonId id = TestsHelper.generateRandomSimplePersonId();
        personCache5.put(id, TestsHelper.generateRandomSimplePerson(id.personNum));
        personCache6.put(id, TestsHelper.generateRandomSimplePerson(id.personNum));
        LOGGER.info("Single operation write tests passed");
        LOGGER.info("Running bulk operation write tests");
        personCache5.putAll(personMap5);
        personCache6.putAll(personMap6);
        LOGGER.info("Bulk operation write tests passed");
    }
    LOGGER.info("POJO strategy write tests for simple objects 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 for simple objects");
        IgniteCache<SimplePersonId, SimplePerson> personCache5 = ignite.getOrCreateCache(new CacheConfiguration<SimplePersonId, SimplePerson>("cache5"));
        IgniteCache<SimplePersonId, SimplePerson> personCache6 = ignite.getOrCreateCache(new CacheConfiguration<SimplePersonId, SimplePerson>("cache6"));
        LOGGER.info("Running single operation read tests");
        SimplePersonId id = personMap5.keySet().iterator().next();
        SimplePerson person = personCache5.get(id);
        if (!person.equalsPrimitiveFields(personMap5.get(id)))
            throw new RuntimeException("SimplePerson value was incorrectly deserialized from Cassandra");
        id = personMap6.keySet().iterator().next();
        person = personCache6.get(id);
        if (!person.equals(personMap6.get(id)))
            throw new RuntimeException("SimplePerson value was incorrectly deserialized from Cassandra");
        LOGGER.info("Single operation read tests passed");
        LOGGER.info("Running bulk operation read tests");
        Map<SimplePersonId, SimplePerson> persons5 = personCache5.getAll(personMap5.keySet());
        if (!TestsHelper.checkSimplePersonMapsEqual(persons5, personMap5, true))
            throw new RuntimeException("SimplePerson values batch was incorrectly deserialized from Cassandra");
        Map<SimplePersonId, SimplePerson> persons6 = personCache6.getAll(personMap6.keySet());
        if (!TestsHelper.checkSimplePersonMapsEqual(persons6, personMap6, false))
            throw new RuntimeException("SimplePerson values batch was incorrectly deserialized from Cassandra");
        LOGGER.info("Bulk operation read tests passed");
        LOGGER.info("POJO strategy read tests for simple objects passed");
        LOGGER.info("Running POJO strategy delete tests for simple objects");
        personCache5.remove(id);
        personCache5.removeAll(personMap5.keySet());
        personCache6.remove(id);
        personCache6.removeAll(personMap6.keySet());
        LOGGER.info("POJO strategy delete tests for simple objects passed");
    }
}
Also used : SimplePersonId(org.apache.ignite.tests.pojos.SimplePersonId) Ignite(org.apache.ignite.Ignite) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Test(org.junit.Test)

Example 2 with SimplePerson

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

the class TestsHelper method generateSimplePersonIdsPersonsMap.

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

Example 3 with SimplePerson

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

the class TestsHelper method generateSimplePersonIdsPersonsEntries.

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

Example 4 with SimplePerson

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

the class TestsHelper method generateRandomSimplePerson.

/**
 */
public static SimplePerson generateRandomSimplePerson(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 SimplePerson(personNum, randomString(4), randomString(4), (short) RANDOM.nextInt(100), RANDOM.nextBoolean(), RANDOM.nextLong(), RANDOM.nextFloat(), new Date(), phones);
}
Also used : LinkedList(java.util.LinkedList) Date(java.util.Date) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson)

Example 5 with SimplePerson

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

the class CassandraDirectPersistenceTest method pojoStrategySimpleObjectsTest.

/**
 */
@Test
@SuppressWarnings("unchecked")
public void pojoStrategySimpleObjectsTest() {
    CacheStore store5 = CacheStoreHelper.createCacheStore("persons5", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-5.xml"), CassandraHelper.getAdminDataSrc());
    CacheStore store6 = CacheStoreHelper.createCacheStore("persons6", new ClassPathResource("org/apache/ignite/tests/persistence/pojo/persistence-settings-6.xml"), CassandraHelper.getAdminDataSrc());
    Collection<CacheEntryImpl<SimplePersonId, SimplePerson>> entries5 = TestsHelper.generateSimplePersonIdsPersonsEntries();
    Collection<CacheEntryImpl<SimplePersonId, SimplePerson>> entries6 = TestsHelper.generateSimplePersonIdsPersonsEntries();
    LOGGER.info("Running POJO strategy write tests for simple objects");
    LOGGER.info("Running single write operation tests");
    store5.write(entries5.iterator().next());
    store6.write(entries6.iterator().next());
    LOGGER.info("Single write operation tests passed");
    LOGGER.info("Running bulk write operation tests");
    store5.writeAll(entries5);
    store6.writeAll(entries6);
    LOGGER.info("Bulk write operation tests passed");
    LOGGER.info("POJO strategy write tests for simple objects passed");
    LOGGER.info("Running POJO simple objects strategy read tests");
    LOGGER.info("Running single read operation tests");
    SimplePerson person = (SimplePerson) store5.load(entries5.iterator().next().getKey());
    if (!entries5.iterator().next().getValue().equalsPrimitiveFields(person))
        throw new RuntimeException("SimplePerson values were incorrectly deserialized from Cassandra");
    person = (SimplePerson) store6.load(entries6.iterator().next().getKey());
    if (!entries6.iterator().next().getValue().equalsPrimitiveFields(person))
        throw new RuntimeException("SimplePerson values were incorrectly deserialized from Cassandra");
    LOGGER.info("Single read operation tests passed");
    LOGGER.info("Running bulk read operation tests");
    Map persons = store5.loadAll(TestsHelper.getKeys(entries5));
    if (!TestsHelper.checkSimplePersonCollectionsEqual(persons, entries5, true))
        throw new RuntimeException("SimplePerson values were incorrectly deserialized from Cassandra");
    persons = store6.loadAll(TestsHelper.getKeys(entries6));
    if (!TestsHelper.checkSimplePersonCollectionsEqual(persons, entries6, true))
        throw new RuntimeException("SimplePerson values were incorrectly deserialized from Cassandra");
    LOGGER.info("Bulk read operation tests passed");
    LOGGER.info("POJO strategy read tests for simple objects passed");
    LOGGER.info("Running POJO strategy delete tests for simple objects");
    store5.delete(entries5.iterator().next().getKey());
    store5.deleteAll(TestsHelper.getKeys(entries5));
    store6.delete(entries6.iterator().next().getKey());
    store6.deleteAll(TestsHelper.getKeys(entries6));
    LOGGER.info("POJO strategy delete tests for simple objects passed");
}
Also used : CacheEntryImpl(org.apache.ignite.internal.processors.cache.CacheEntryImpl) CacheStore(org.apache.ignite.cache.store.CacheStore) Map(java.util.Map) ClassPathResource(org.springframework.core.io.ClassPathResource) SimplePerson(org.apache.ignite.tests.pojos.SimplePerson) Test(org.junit.Test)

Aggregations

SimplePerson (org.apache.ignite.tests.pojos.SimplePerson)6 SimplePersonId (org.apache.ignite.tests.pojos.SimplePersonId)3 LinkedList (java.util.LinkedList)2 CacheEntryImpl (org.apache.ignite.internal.processors.cache.CacheEntryImpl)2 PersonId (org.apache.ignite.tests.pojos.PersonId)2 Test (org.junit.Test)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Ignite (org.apache.ignite.Ignite)1 CacheStore (org.apache.ignite.cache.store.CacheStore)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1