use of org.hibernate.test.cache.infinispan.functional.entities.Name in project hibernate-orm by hibernate.
the class CacheKeysFactoryTest method test.
private void test(String cacheKeysFactory, String keyClassName) throws Exception {
SessionFactory sessionFactory = getSessionFactory(cacheKeysFactory);
withTxSession(false, sessionFactory, s -> {
Person person = new Person("John", "Black", 39);
s.persist(person);
});
TestInfinispanRegionFactory regionFactory = (TestInfinispanRegionFactory) ((CacheImplementor) sessionFactory.getCache()).getRegionFactory();
Cache<Object, Object> cache = regionFactory.getCacheManager().getCache(Person.class.getName());
Iterator<Object> iterator = cache.getAdvancedCache().getDataContainer().keySet().iterator();
assertTrue(iterator.hasNext());
Object key = iterator.next();
assertEquals(keyClassName, key.getClass().getSimpleName());
withTxSession(false, sessionFactory, s -> {
Person person = s.load(Person.class, new Name("John", "Black"));
assertEquals(39, person.getAge());
});
}
use of org.hibernate.test.cache.infinispan.functional.entities.Name in project hibernate-orm by hibernate.
the class EqualityTest method testEqualityFromType.
@Test
public void testEqualityFromType() throws Exception {
Person john = new Person("John", "Black", 26);
Person peter = new Person("Peter", "White", 32);
withTxSession(s -> {
s.persist(john);
s.persist(peter);
});
Statistics statistics = sessionFactory().getStatistics();
statistics.clear();
for (int i = 0; i < 5; ++i) {
withTxSession(s -> {
Person p1 = s.get(Person.class, john.getName());
assertPersonEquals(john, p1);
Person p2 = s.get(Person.class, peter.getName());
assertPersonEquals(peter, p2);
Person p3 = s.get(Person.class, new Name("Foo", "Bar"));
assertNull(p3);
});
}
assertTrue(statistics.getSecondLevelCacheHitCount() > 0);
assertTrue(statistics.getSecondLevelCacheMissCount() > 0);
}
Aggregations