use of org.hibernate.vibur.internal.ViburDBCPConnectionProvider in project hibernate-orm by hibernate.
the class ViburDBCPConnectionProviderTest method testSelectStatementWithStatementsCache.
@Test
public void testSelectStatementWithStatementsCache() {
setUpPoolAndDatabase(1, 10);
ConnectionProvider cp = sessionFactory().getServiceRegistry().getService(ConnectionProvider.class);
ViburDBCPDataSource ds = ((ViburDBCPConnectionProvider) cp).getDataSource();
ConcurrentMap<StatementMethod, StatementHolder> mockedStatementCache = mockStatementCache(ds);
doInHibernate(this::sessionFactory, ViburDBCPConnectionProviderTest::executeAndVerifySelect);
// We set above the poolMaxSize = 1, that's why the second session will get and use the same underlying connection.
doInHibernate(this::sessionFactory, ViburDBCPConnectionProviderTest::executeAndVerifySelect);
InOrder inOrder = inOrder(mockedStatementCache);
inOrder.verify(mockedStatementCache).get(key1.capture());
inOrder.verify(mockedStatementCache).putIfAbsent(same(key1.getValue()), val1.capture());
inOrder.verify(mockedStatementCache).get(key2.capture());
assertEquals(1, mockedStatementCache.size());
assertTrue(mockedStatementCache.containsKey(key1.getValue()));
assertEquals(key1.getValue(), key2.getValue());
assertEquals(AVAILABLE, val1.getValue().state().get());
}
Aggregations