use of org.hibernate.SessionFactory in project dropwizard by dropwizard.
the class DAOTestRuleTest method ruleCreatedSessionFactory.
@Test
public void ruleCreatedSessionFactory() {
final SessionFactory sessionFactory = daoTestRule.getSessionFactory();
assertThat(sessionFactory).isNotNull();
}
use of org.hibernate.SessionFactory 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.SessionFactory in project hibernate-orm by hibernate.
the class DropSchemaDuringJtaTxnTest method testDropDuringActiveJtaTransaction.
@Test
public void testDropDuringActiveJtaTransaction() throws Exception {
final SessionFactory sessionFactory = buildSessionFactory();
JtaPlatformStandardTestingImpl.INSTANCE.transactionManager().begin();
try {
sessionFactory.close();
} finally {
JtaPlatformStandardTestingImpl.INSTANCE.transactionManager().commit();
}
}
use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class QueryRegionImplTest method testQueryUpdate.
@Test
public void testQueryUpdate() throws Exception {
withQueryRegion((sessionFactory, region) -> {
ExceptionHolder holder = new ExceptionHolder();
CyclicBarrier barrier = new CyclicBarrier(2);
withSession(sessionFactory, session -> region.put(session, KEY, VALUE1));
Thread updater = new Thread() {
@Override
public void run() {
try {
withSession(sessionFactory, (session) -> {
assertEquals(VALUE1, region.get(session, KEY));
region.put(session, KEY, VALUE2);
assertEquals(VALUE2, region.get(session, KEY));
barrier.await(5, TimeUnit.SECONDS);
barrier.await(5, TimeUnit.SECONDS);
region.put(session, KEY, VALUE3);
assertEquals(VALUE3, region.get(session, KEY));
barrier.await(5, TimeUnit.SECONDS);
barrier.await(5, TimeUnit.SECONDS);
});
} catch (AssertionFailedError e) {
holder.addAssertionFailure(e);
barrier.reset();
} catch (Exception e) {
holder.addException(e);
barrier.reset();
}
}
};
Thread reader = new Thread() {
@Override
public void run() {
try {
withSession(sessionFactory, (session) -> {
assertEquals(VALUE1, region.get(session, KEY));
barrier.await(5, TimeUnit.SECONDS);
assertEquals(VALUE1, region.get(session, KEY));
barrier.await(5, TimeUnit.SECONDS);
barrier.await(5, TimeUnit.SECONDS);
assertEquals(VALUE1, region.get(session, KEY));
barrier.await(5, TimeUnit.SECONDS);
});
} catch (AssertionFailedError e) {
holder.addAssertionFailure(e);
barrier.reset();
} catch (Exception e) {
holder.addException(e);
barrier.reset();
}
}
};
updater.start();
reader.start();
updater.join();
reader.join();
holder.checkExceptions();
assertEquals(VALUE3, callWithSession(sessionFactory, session -> region.get(session, KEY)));
});
}
use of org.hibernate.SessionFactory in project hibernate-orm by hibernate.
the class CorrectnessTestCase method beforeClass.
@BeforeClassOnce
public void beforeClass() {
TestResourceTracker.testStarted(getClass().getSimpleName());
Arrays.asList(new File(System.getProperty("java.io.tmpdir")).listFiles((dir, name) -> name.startsWith("family_") || name.startsWith("invalidations-"))).stream().forEach(f -> f.delete());
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.DRIVER, "org.h2.Driver").applySetting(Environment.URL, "jdbc:h2:mem:" + getDbName() + ";TRACE_LEVEL_FILE=4").applySetting(Environment.DIALECT, H2Dialect.class.getName()).applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CACHE_REGION_FACTORY, FailingInfinispanRegionFactory.class.getName()).applySetting(TestInfinispanRegionFactory.CACHE_MODE, cacheMode).applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.GENERATE_STATISTICS, "false");
applySettings(ssrb);
sessionFactories = new SessionFactory[NUM_NODES];
for (int i = 0; i < NUM_NODES; ++i) {
StandardServiceRegistry registry = ssrb.build();
Metadata metadata = buildMetadata(registry);
sessionFactories[i] = metadata.buildSessionFactory();
}
}
Aggregations