Search in sources :

Example 6 with FBManager

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);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase)

Example 7 with 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);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) Connection(java.sql.Connection) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) FbConnectionProperties(org.firebirdsql.gds.ng.FbConnectionProperties) Test(org.junit.Test)

Example 8 with 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);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with 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);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) Test(org.junit.Test)

Example 10 with 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);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) Test(org.junit.Test)

Aggregations

FBManager (org.firebirdsql.management.FBManager)26 Test (org.junit.Test)17 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)9 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)9 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)8 Connection (java.sql.Connection)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 FBTestProperties (org.firebirdsql.common.FBTestProperties)2 ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)2 FbConnectionProperties (org.firebirdsql.gds.ng.FbConnectionProperties)2 FBDriver (org.firebirdsql.jdbc.FBDriver)2 GDSType (org.firebirdsql.gds.impl.GDSType)1 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)1 AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)1 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)1 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)1