use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testClosedHandler_throwsException.
/**
* Calling any Connection method (except isClosed() and close()) on a proxy
* that was closed by closing the handler should throw an SQLException
* mentioning the connection was forcibly closed; the owner should not be
* notified of the exception.
*
* TODO: Consider testing for all Connection methods
*
* @throws SQLException
*/
@Test
public void testClosedHandler_throwsException() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
context.checking(new Expectations() {
{
connectionHandleReleaseExpectations(this, physicalConnection);
allowing(pooled).releaseConnectionHandler(handler);
allowing(pooled).fireConnectionClosed();
never(pooled).fireConnectionError(with(any(SQLException.class)));
}
});
Connection proxy = handler.getProxy();
handler.close();
expectedException.expect(SQLException.class);
expectedException.expectMessage(PooledConnectionHandler.FORCIBLY_CLOSED_MESSAGE);
proxy.clearWarnings();
}
use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testDoubleClose_allowed.
/**
* Calling close() on a closed proxy should not throw an exception.
*
* @throws SQLException
*/
@Test
public void testDoubleClose_allowed() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
context.checking(new Expectations() {
{
ignoring(physicalConnection);
ignoring(pooled);
}
});
Connection proxy = handler.getProxy();
proxy.close();
// Expectation: no exception for double close
proxy.close();
}
use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testProxyClose_IsClosed.
/**
* The isClosed() method of PooledConnectionHandler and its proxy should
* report <code>true</code> after proxy close.
*
* @throws SQLException
*/
@Test
public void testProxyClose_IsClosed() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
context.checking(new Expectations() {
{
connectionHandleReleaseExpectations(this, physicalConnection);
allowing(pooled).releaseConnectionHandler(handler);
allowing(pooled).fireConnectionClosed();
}
});
Connection proxy = handler.getProxy();
proxy.close();
assertTrue("Handler of closed proxy should report isClosed() true", handler.isClosed());
assertTrue("Closed proxy should report isClosed() true", proxy.isClosed());
}
use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testHandlerClose_NoNotify.
/**
* Closing the PooledConnectionHandler should not notify the owner and not
* close the physical connection.
*
* @throws SQLException
*/
@Test
public void testHandlerClose_NoNotify() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
context.checking(new Expectations() {
{
connectionHandleReleaseExpectations(this, physicalConnection);
allowing(pooled).releaseConnectionHandler(handler);
never(physicalConnection).close();
never(pooled).fireConnectionClosed();
}
});
handler.close();
}
use of org.firebirdsql.jdbc.FirebirdConnection in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testProxyClose_Notify.
/**
* Closing the Proxy of the PooledConnectionHandler should notify the owner
* but not close the physical connection.
*
* @throws SQLException
*/
@Test
public void testProxyClose_Notify() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
context.checking(new Expectations() {
{
connectionHandleReleaseExpectations(this, physicalConnection);
allowing(pooled).releaseConnectionHandler(handler);
never(physicalConnection).close();
oneOf(pooled).fireConnectionClosed();
}
});
handler.getProxy().close();
}
Aggregations