Search in sources :

Example 1 with TestInfinispanRegionFactory

use of org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory 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());
    });
}
Also used : SessionFactory(org.hibernate.SessionFactory) Person(org.hibernate.test.cache.infinispan.functional.entities.Person) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Name(org.hibernate.test.cache.infinispan.functional.entities.Name)

Example 2 with TestInfinispanRegionFactory

use of org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory in project hibernate-orm by hibernate.

the class PutFromLoadValidatorUnitTest method regionFactory.

private static InfinispanRegionFactory regionFactory(EmbeddedCacheManager cm) {
    Properties properties = new Properties();
    properties.put(TestInfinispanRegionFactory.TIME_SERVICE, TIME_SERVICE);
    InfinispanRegionFactory regionFactory = new TestInfinispanRegionFactory(properties);
    regionFactory.setCacheManager(cm);
    regionFactory.start(CacheTestUtil.sfOptionsForStart(), properties);
    return regionFactory;
}
Also used : InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Properties(java.util.Properties) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)

Aggregations

TestInfinispanRegionFactory (org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory)2 Properties (java.util.Properties)1 SessionFactory (org.hibernate.SessionFactory)1 InfinispanRegionFactory (org.hibernate.cache.infinispan.InfinispanRegionFactory)1 Name (org.hibernate.test.cache.infinispan.functional.entities.Name)1 Person (org.hibernate.test.cache.infinispan.functional.entities.Person)1