use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestFBConnectionTimeout method normalConnectionWithTimeoutFromProperty.
/**
* Test if a normal connection will work when the timeout is specified in the connection properties.
*/
@Test
public void normalConnectionWithTimeoutFromProperty() throws Exception {
// Reset DriverManager timeout
DriverManager.setLoginTimeout(0);
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try {
Properties properties = FBTestProperties.getDefaultPropertiesForConnection();
properties.setProperty("connectTimeout", "1");
Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties);
connection.close();
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestJnaDatabase method testDrop_NotAttached.
@Test
public void testDrop_NotAttached() throws Exception {
expectedException.expect(SQLException.class);
expectedException.expectMessage(startsWith("The connection is not attached to a database"));
expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_CONNECTION_ERROR));
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try {
JnaDatabase db = factory.connect(connectionInfo);
db.dropDatabase();
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestV10Service method testStartServiceAction.
/**
* Test for service action.
* <p>
* Replicates the behavior of {@link FBStatisticsManager#getHeaderPage()}.
* </p>
*/
@Test
public void testStartServiceAction() throws Exception {
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try (WireServiceConnection gdsConnection = createConnection()) {
gdsConnection.socketConnect();
try (FbWireService service = gdsConnection.identify()) {
assertEquals("Unexpected FbWireService implementation", getExpectedServiceType(), service.getClass());
service.attach();
ServiceRequestBuffer actionSrb = service.createServiceRequestBuffer();
actionSrb.addArgument(isc_action_svc_db_stats);
actionSrb.addArgument(isc_spb_dbname, getDatabasePath());
actionSrb.addArgument(isc_spb_options, isc_spb_sts_hdr_pages);
service.startServiceAction(actionSrb);
ServiceRequestBuffer infoSrb = service.createServiceRequestBuffer();
infoSrb.addArgument(isc_info_svc_to_eof);
int bufferSize = 1024;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
boolean processing = true;
while (processing) {
byte[] buffer = service.getServiceInfo(null, infoSrb, bufferSize);
switch(buffer[0]) {
case isc_info_svc_to_eof:
int dataLength = iscVaxInteger2(buffer, 1);
if (dataLength == 0) {
if (buffer[3] != isc_info_end) {
throw new SQLException("Unexpected end of stream reached.");
} else {
processing = false;
break;
}
}
bos.write(buffer, 3, dataLength);
break;
case isc_info_truncated:
bufferSize = bufferSize * 2;
break;
case isc_info_end:
processing = false;
break;
}
}
String headerPage = service.getEncoding().decodeFromCharset(bos.toByteArray());
assertThat("Expected database header page content", headerPage, allOf(startsWith("\nDatabase"), containsString("Database header page information"), containsString("*END*\n")));
}
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestV10Database method testDetach_NotAttached.
@Test
public void testDetach_NotAttached() throws Exception {
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try (WireDatabaseConnection gdsConnection = createConnection()) {
gdsConnection.socketConnect();
FbWireDatabase db = gdsConnection.identify();
assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
// Detach for connected but not attached should work
db.close();
assertFalse("Expected connection closed after detach", gdsConnection.isConnected());
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestV10Database method checkCancelOperationNotSupported.
private void checkCancelOperationNotSupported(int kind) throws Exception {
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try (WireDatabaseConnection gdsConnection = createConnection()) {
gdsConnection.socketConnect();
try (FbWireDatabase db = gdsConnection.identify()) {
assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
db.attach();
assertTrue("expected database attached", db.isAttached());
expectedException.expect(allOf(isA(SQLFeatureNotSupportedException.class), message(startsWith("Cancel Operation isn't supported in this version of the wire protocol"))));
db.cancelOperation(kind);
}
} finally {
defaultDatabaseTearDown(fbManager);
}
}
Aggregations