Search in sources :

Example 6 with FbWireDatabase

use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.

the class TestV10Database method testCancelOperation_abortSupported.

@Test
public void testCancelOperation_abortSupported() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        try {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            assumeTrue("expected database attached", db.isAttached());
            db.cancelOperation(ISCConstants.fb_cancel_abort);
            assertFalse("Expected database not attached after abort", db.isAttached());
            assertFalse("Expected connection closed after abort", gdsConnection.isConnected());
        } finally {
            safelyClose(db);
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 7 with FbWireDatabase

use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.

the class TestV10Database 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 (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        db.dropDatabase();
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 8 with FbWireDatabase

use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.

the class TestV10Database method testAttach_NonExistentDatabase.

/**
 * Tests if attaching to a non-existent database results in an exception
 */
@Test
public void testAttach_NonExistentDatabase() throws Exception {
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        try {
            gdsConnection.socketConnect();
            FbWireDatabase db = gdsConnection.identify();
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            fail("Expected the attach to fail because the database doesn't exist");
        } catch (SQLException e) {
            // NOTE: Not using expectedException because of the final assertion that isConnected is false
            // TODO Is this actually the right SQLState?
            assertThat("Expected SQLState for 'Client unable to establish connection' (08001)", e, sqlStateEquals("08001"));
            // TODO Seems to be the least specific error, deeper in there is a more specific 335544734 (isc_io_open_err)
            assertThat("Expected isc_io_error (335544344)", e, errorCodeEquals(ISCConstants.isc_io_error));
        }
        assertFalse(gdsConnection.isConnected());
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) SQLException(java.sql.SQLException) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 9 with FbWireDatabase

use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.

the class TestV10OutputBlob method testUsingCancelledBlob.

/**
 * Test whether a cancelled blob cannot be used (indicating it was indeed cancelled).
 */
@Test
public void testUsingCancelledBlob() throws Exception {
    expectedException.expect(SQLException.class);
    expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_bad_segstr_id), message(startsWith(getFbMessage(ISCConstants.isc_bad_segstr_id)))));
    final int testId = 1;
    final byte[] baseContent = generateBaseContent();
    final int requiredSize = 256;
    final byte[] testBytes = generateBlobContent(baseContent, requiredSize);
    try (FbWireDatabase db = createDatabaseConnection()) {
        final SimpleStatementListener listener = new SimpleStatementListener();
        final FbTransaction transaction = getTransaction(db);
        try {
            final FbStatement statement = db.createStatement(transaction);
            statement.addStatementListener(listener);
            final FbBlob blob = db.createBlobForOutput(transaction, null);
            blob.open();
            int bytesWritten = 0;
            while (bytesWritten < testBytes.length) {
                // TODO the interface for writing blobs should be simpler
                byte[] buffer = new byte[Math.min(blob.getMaximumSegmentSize(), testBytes.length - bytesWritten)];
                System.arraycopy(testBytes, bytesWritten, buffer, 0, buffer.length);
                blob.putSegment(buffer);
                bytesWritten += buffer.length;
            }
            blob.cancel();
            statement.prepare(INSERT_BLOB_TABLE);
            final DatatypeCoder datatypeCoder = db.getDatatypeCoder();
            FieldValue param1 = new FieldValue(datatypeCoder.encodeInt(testId));
            FieldValue param2 = new FieldValue(datatypeCoder.encodeLong(blob.getBlobId()));
            statement.execute(RowValue.of(param1, param2));
            statement.close();
        } finally {
            transaction.commit();
        }
    }
}
Also used : SimpleStatementListener(org.firebirdsql.gds.ng.wire.SimpleStatementListener) DatatypeCoder(org.firebirdsql.gds.ng.DatatypeCoder) FieldValue(org.firebirdsql.gds.ng.fields.FieldValue) FbStatement(org.firebirdsql.gds.ng.FbStatement) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Example 10 with FbWireDatabase

use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.

the class TestV10OutputBlob method testIsEof_afterOpen.

/**
 * Test if blob is not eof after open.
 */
@Test
public void testIsEof_afterOpen() throws Exception {
    try (FbWireDatabase db = createDatabaseConnection()) {
        final FbTransaction transaction = getTransaction(db);
        try {
            FbBlob blob = db.createBlobForOutput(transaction, null);
            assumeTrue("Output blob before open should be eof", blob.isEof());
            blob.open();
            assertFalse("Output blob after open should not be eof", blob.isEof());
        } finally {
            transaction.commit();
        }
    }
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Aggregations

FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)27 Test (org.junit.Test)23 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)13 FbBlob (org.firebirdsql.gds.ng.FbBlob)11 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)11 FBManager (org.firebirdsql.management.FBManager)9 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 IOException (java.io.IOException)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)1 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1 StatementState (org.firebirdsql.gds.ng.StatementState)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 Ignore (org.junit.Ignore)1