use of org.apache.calcite.avatica.AvaticaSqlException in project calcite-avatica by apache.
the class AvaticaSqlExceptionTest method testGetters.
@Test
public void testGetters() {
final String msg = "My query failed!";
final int code = 42;
final String sql = "SELECT foo FROM bar;";
final String stacktrace = "My Stack Trace";
final String server = "localhost:8765";
AvaticaSqlException e = new AvaticaSqlException(msg, sql, code, Arrays.asList(stacktrace), server);
assertTrue(e.getMessage().contains(msg));
assertEquals(code, e.getErrorCode());
assertEquals(sql, e.getSQLState());
assertEquals(1, e.getStackTraces().size());
assertEquals(stacktrace, e.getStackTraces().get(0));
assertEquals(server, e.getRemoteServer());
}
use of org.apache.calcite.avatica.AvaticaSqlException in project calcite-avatica by apache.
the class RemoteMetaTest method testExceptionPropagation.
@Test
public void testExceptionPropagation() throws Exception {
final String sql = "SELECT * from EMP LIMIT FOOBARBAZ";
ConnectionSpec.getDatabaseLock().lock();
try (final AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url);
final Statement stmt = conn.createStatement()) {
try {
// invalid SQL
stmt.execute(sql);
fail("Expected an AvaticaSqlException");
} catch (AvaticaSqlException e) {
assertEquals(ErrorResponse.UNKNOWN_ERROR_CODE, e.getErrorCode());
assertEquals(ErrorResponse.UNKNOWN_SQL_STATE, e.getSQLState());
assertTrue("Message should contain original SQL, was '" + e.getMessage() + "'", e.getMessage().contains(sql));
assertEquals(1, e.getStackTraces().size());
final String stacktrace = e.getStackTraces().get(0);
final String substring = "unexpected token: FOOBARBAZ";
assertTrue("Message should contain '" + substring + "', was '" + e.getMessage() + ",", stacktrace.contains(substring));
}
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
Aggregations