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");
}
}
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;
}
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;
}
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);
}
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");
}
Aggregations