use of org.firebirdsql.common.BlackholeServer in project jaybird by FirebirdSQL.
the class WireDatabaseConnectionTest method testSocketTimeout_noResponse.
/**
* Tests the connect timeout if the server does not respond.
*/
@Test
public void testSocketTimeout_noResponse() throws Exception {
BlackholeServer server = new BlackholeServer();
Thread thread = new Thread(server);
thread.start();
long startTime = System.currentTimeMillis();
try {
connectionInfo.setPortNumber(server.getPort());
connectionInfo.setDatabaseName("somedb");
connectionInfo.setSoTimeout(2000);
WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionInfo);
gdsConnection.socketConnect();
gdsConnection.identify();
fail("Expected connection to fail");
} catch (SQLTimeoutException e) {
long endTime = System.currentTimeMillis();
long difference = endTime - startTime;
assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS);
} catch (SQLException e) {
e.printStackTrace();
fail("Expected SQLTimeoutException to be thrown");
} finally {
server.stop();
thread.join();
}
}
use of org.firebirdsql.common.BlackholeServer in project jaybird by FirebirdSQL.
the class WireDatabaseConnectionTest method testConnectTimeout_noResponse.
/**
* Tests the connect timeout if the server does not respond.
*/
@Test
public void testConnectTimeout_noResponse() throws Exception {
BlackholeServer server = new BlackholeServer();
Thread thread = new Thread(server);
thread.start();
long startTime = System.currentTimeMillis();
try {
connectionInfo.setPortNumber(server.getPort());
connectionInfo.setDatabaseName("somedb");
connectionInfo.setConnectTimeout(2);
WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionInfo);
gdsConnection.socketConnect();
gdsConnection.identify();
fail("Expected connection to fail");
} catch (SQLTimeoutException e) {
long endTime = System.currentTimeMillis();
long difference = endTime - startTime;
assertEquals("Expected error code for \"Unable to complete network request\"", 335544721, e.getErrorCode());
assertEquals("Unexpected timeout duration (in ms)", 2000, difference, TIMEOUT_DELTA_MS);
} catch (SQLException e) {
e.printStackTrace();
fail("Expected SQLTimeoutException to be thrown");
} finally {
server.stop();
thread.join();
}
}
Aggregations