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);
}
}
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);
}
}
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());
}
}
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();
}
}
}
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();
}
}
}
Aggregations