use of org.apache.calcite.avatica.AvaticaStatement in project calcite-avatica by apache.
the class RemoteMetaTest method testCancel.
/** Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1301">[CALCITE-1301]
* Add cancel flag to AvaticaStatement</a>. */
@Test
public void testCancel() throws Exception {
ConnectionSpec.getDatabaseLock().lock();
try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) {
final AvaticaStatement statement = conn.createStatement();
final String sql = "select * from (values ('a', 1), ('b', 2))";
final ResultSet rs = statement.executeQuery(sql);
int count = 0;
loop: for (; ; ) {
switch(count++) {
case 0:
assertThat(rs.next(), is(true));
break;
case 1:
rs.getStatement().cancel();
try {
boolean x = rs.next();
fail("expected exception, got " + x);
} catch (SQLException e) {
assertThat(e.getMessage(), is("Statement canceled"));
}
break loop;
default:
fail("count: " + count);
}
}
assertThat(count, is(2));
assertThat(statement.isClosed(), is(false));
rs.close();
assertThat(statement.isClosed(), is(false));
statement.close();
assertThat(statement.isClosed(), is(true));
statement.close();
assertThat(statement.isClosed(), is(true));
} finally {
ConnectionSpec.getDatabaseLock().unlock();
}
}
Aggregations