use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testReleaseSavepoint.
/**
* @throws Exception If failed.
*/
@Test
public void testReleaseSavepoint() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
assert !conn.getMetaData().supportsSavepoints();
// Invalid arg
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.releaseSavepoint(null);
return null;
}
}, SQLException.class, "Savepoint cannot be null");
final Savepoint savepoint = getFakeSavepoint();
checkNotSupported(new RunnableX() {
@Override
public void runx() throws Exception {
conn.releaseSavepoint(savepoint);
}
});
conn.close();
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.releaseSavepoint(savepoint);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testCreateStatement3.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateStatement3() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
int[] rsTypes = new int[] { TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE };
int[] rsConcurs = new int[] { CONCUR_READ_ONLY, ResultSet.CONCUR_UPDATABLE };
int[] rsHoldabilities = new int[] { HOLD_CURSORS_OVER_COMMIT, CLOSE_CURSORS_AT_COMMIT };
DatabaseMetaData meta = conn.getMetaData();
for (final int type : rsTypes) {
for (final int concur : rsConcurs) {
for (final int holdabililty : rsHoldabilities) {
if (meta.supportsResultSetConcurrency(type, concur)) {
assert type == TYPE_FORWARD_ONLY;
assert concur == CONCUR_READ_ONLY;
try (Statement stmt = conn.createStatement(type, concur, holdabililty)) {
assertNotNull(stmt);
assertEquals(type, stmt.getResultSetType());
assertEquals(concur, stmt.getResultSetConcurrency());
assertEquals(holdabililty, stmt.getResultSetHoldability());
}
continue;
}
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
return conn.createStatement(type, concur, holdabililty);
}
}, SQLFeatureNotSupportedException.class, null);
}
}
}
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.createStatement(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testCreateArrayOf.
/**
* @throws Exception If failed.
*/
@Test
public void testCreateArrayOf() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
final String typeName = "varchar";
final String[] elements = new String[] { "apple", "pear" };
// Invalid typename
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.createArrayOf(null, null);
return null;
}
}, SQLException.class, "Type name cannot be null");
// Unsupported
checkNotSupported(new RunnableX() {
@Override
public void runx() throws Exception {
conn.createArrayOf(typeName, elements);
}
});
conn.close();
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.createArrayOf(typeName, elements);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinPreparedStatementSelfTest method testCustomObjectSupportCanBeDisabled.
/**
* Ensure custom object support could be disabled via disabledFeatures connection property
* - start grid and create and fill table such one of the columns was user's object
* - from another connection with disabledFeatures set to {@link JdbcThinFeature#CUSTOM_OBJECT}
* execute query with filter by this object
* - verify that exception is thrown when you try to set custom object as statement param
* @throws SQLException
*/
@Test
public void testCustomObjectSupportCanBeDisabled() throws SQLException {
try (Connection conn = createConnection(JdbcThinFeature.CUSTOM_OBJECT);
PreparedStatement stmt = conn.prepareStatement(SQL_PART + " where objVal is not distinct from ?")) {
Throwable t = GridTestUtils.assertThrowsWithCause(new RunnableX() {
@Override
public void runx() throws Exception {
stmt.setObject(1, new TestObjectField(100, "AAAA"));
}
}, SQLException.class);
Assert.assertThat(t.getMessage(), is(containsString("Custom objects are not supported")));
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionMvccEnabledSelfTest method testSetSavepointName.
/**
* @throws Exception If failed.
*/
@Test
public void testSetSavepointName() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
assert !conn.getMetaData().supportsSavepoints();
// Invalid arg
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.setSavepoint(null);
return null;
}
}, SQLException.class, "Savepoint name cannot be null");
final String name = "savepoint";
// Disallowed in auto-commit mode
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.setSavepoint(name);
return null;
}
}, SQLException.class, "Savepoint cannot be set in auto-commit mode");
conn.setAutoCommit(false);
// Unsupported
checkNotSupported(new RunnableX() {
@Override
public void runx() throws Exception {
conn.setSavepoint(name);
}
});
conn.close();
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.setSavepoint(name);
}
});
}
}
Aggregations