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 JdbcThinConnectionSelfTest method testRollbackSavePoint.
/**
* @throws Exception If failed.
*/
@Test
public void testRollbackSavePoint() 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.rollback(null);
return null;
}
}, SQLException.class, "Invalid savepoint");
final Savepoint savepoint = getFakeSavepoint();
// Disallowed in auto-commit mode
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.rollback(savepoint);
return null;
}
}, SQLException.class, "Auto-commit mode");
conn.close();
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.rollback(savepoint);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionSelfTest method testGetSetClientInfoProperties.
/**
* @throws Exception If failed.
*/
@Test
public void testGetSetClientInfoProperties() throws Exception {
try (Connection conn = DriverManager.getConnection(urlWithPartitionAwarenessProp)) {
final String name = "ApplicationName";
final String val = "SelfTest";
final Properties props = new Properties();
props.setProperty(name, val);
conn.setClientInfo(props);
Properties propsResult = conn.getClientInfo();
assertNotNull(propsResult);
assertTrue(propsResult.isEmpty());
conn.close();
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.getClientInfo();
}
});
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.setClientInfo(props);
return null;
}
}, SQLClientInfoException.class, "Connection is closed");
}
}
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);
}
});
}
}
use of org.apache.ignite.testframework.GridTestUtils.RunnableX in project ignite by apache.
the class JdbcThinConnectionMvccEnabledSelfTest method testCommit.
/**
* @throws Exception If failed.
*/
@Test
public void testCommit() throws Exception {
try (Connection conn = DriverManager.getConnection(URL)) {
assertTrue(conn.getMetaData().supportsTransactions());
// Should not be called in auto-commit mode
assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
conn.commit();
return null;
}
}, SQLException.class, "Transaction cannot be committed explicitly in auto-commit mode");
conn.setAutoCommit(false);
conn.commit();
conn.close();
// Exception when called on closed connection
checkConnectionClosed(new RunnableX() {
@Override
public void runx() throws Exception {
conn.commit();
}
});
}
}
Aggregations