use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestV12Database method checkCancelOperationSupported.
private void checkCancelOperationSupported(int kind, String kindName) 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());
db.cancelOperation(kind);
assertTrue("Expected database still attached after " + kindName, db.isAttached());
assertTrue("Expected connection still open after " + kindName, gdsConnection.isConnected());
}
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestFBConnectionTimeout method normalConnectionWithTimeoutFromDriverManager.
/**
* Test if a normal connection will work when the timeout is specified through DriverManager
*/
@Test
public void normalConnectionWithTimeoutFromDriverManager() throws Exception {
// Reset DriverManager timeout
DriverManager.setLoginTimeout(2);
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try {
Properties properties = FBTestProperties.getDefaultPropertiesForConnection();
Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties);
connection.close();
} finally {
// Reset to default
DriverManager.setLoginTimeout(0);
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestJnaService 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 (JnaService service = factory.serviceConnect(connectionInfo)) {
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 TestJnaDatabase method testCancelOperation_abortSupported.
@Test
public void testCancelOperation_abortSupported() throws Exception {
// TODO Investigate why this doesn't work.
assumeThat("Test doesn't work with embedded protocol", FBTestProperties.GDS_TYPE, not(oneOf(EmbeddedGDSFactoryPlugin.EMBEDDED_TYPE_NAME)));
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try {
JnaDatabase db = factory.connect(connectionInfo);
try {
db.attach();
assumeTrue("expected database attached", db.isAttached());
assumeTrue("Test requires cancel support", supportInfoFor(db).supportsCancelOperation());
db.cancelOperation(ISCConstants.fb_cancel_abort);
assertFalse("Expected database not attached after abort", db.isAttached());
} finally {
safelyClose(db);
}
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.
the class TestJnaDatabase method testBasicAttach.
@Test
public void testBasicAttach() throws Exception {
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try (JnaDatabase db = factory.connect(connectionInfo)) {
db.attach();
assertTrue("Expected isAttached() to return true", db.isAttached());
MatcherAssert.assertThat("Expected non-zero connection handle", db.getHandle(), not(equalTo(0)));
assertNotNull("Expected version string to be not null", db.getServerVersion());
assertNotEquals("Expected version should not be invalid", GDSServerVersion.INVALID_VERSION, db.getServerVersion());
} finally {
defaultDatabaseTearDown(fbManager);
}
}
Aggregations