use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlTestSupport method assertRowsOrdered.
/**
* Execute a query and wait until it completes. Assert that the returned
* rows contain the expected rows, in the given order.
*
* @param sql The query
* @param expectedRows Expected rows
*/
public static void assertRowsOrdered(String sql, List<Row> expectedRows) {
SqlService sqlService = instance().getSql();
List<Row> actualRows = new ArrayList<>();
try (SqlResult result = sqlService.execute(sql)) {
result.iterator().forEachRemaining(row -> actualRows.add(new Row(row)));
}
assertThat(actualRows).containsExactlyElementsOf(expectedRows);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class PlanExecutorTest method test_dropMappingExecution.
@Test
@Parameters({ "true", "false" })
public void test_dropMappingExecution(boolean ifExists) {
// given
String name = "name";
DropMappingPlan plan = new DropMappingPlan(planKey(), name, ifExists, planExecutor);
// when
SqlResult result = planExecutor.execute(plan);
// then
assertThat(result.updateCount()).isEqualTo(0);
verify(catalog).removeMapping(name, ifExists);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class PlanExecutorTest method test_createMappingExecution.
@Test
@Parameters({ "true, false", "false, true" })
public void test_createMappingExecution(boolean replace, boolean ifNotExists) {
// given
Mapping mapping = mapping();
CreateMappingPlan plan = new CreateMappingPlan(planKey(), mapping, replace, ifNotExists, planExecutor);
// when
SqlResult result = planExecutor.execute(plan);
// then
assertThat(result.updateCount()).isEqualTo(0);
verify(catalog).createMapping(mapping, replace, ifNotExists);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlResultImplTest method when_closed_then_iteratorFails.
@Test
public // test for https://github.com/hazelcast/hazelcast-jet/issues/2697
void when_closed_then_iteratorFails() {
SqlResult sqlResult = instance().getSql().execute("select * from table(generate_stream(1))");
sqlResult.close();
Iterator<SqlRow> iterator = sqlResult.iterator();
assertThatThrownBy(() -> iterator.forEachRemaining(ConsumerEx.noop()));
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlResultImplTest method when_hasNextInterrupted_then_interrupted.
@Test
public void when_hasNextInterrupted_then_interrupted() {
// this query is a continuous one, but never returns any rows (all are filtered out)
SqlResult sqlResult = instance().getSql().execute("select * from table(generate_stream(1)) where v < 0");
AtomicBoolean interruptedOk = new AtomicBoolean();
Thread t = new Thread(() -> {
try {
sqlResult.iterator().hasNext();
} catch (Throwable e) {
if (e.getCause() instanceof RuntimeException && e.getCause().getCause() instanceof InterruptedException) {
interruptedOk.set(true);
} else {
logger.severe("Unexpected exception caught", e);
}
}
});
t.start();
t.interrupt();
assertTrueEventually(() -> assertTrue(interruptedOk.get()));
}
Aggregations