use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientTest method when_resultClosed_then_jobCancelled_withNoResults.
@Test
public void when_resultClosed_then_jobCancelled_withNoResults() {
/*
There was an issue that RootResultConsumerSink didn't check for failures, unless
it had some items in the inbox.
*/
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
logger.info("before select");
SqlResult result = sqlService.execute("SELECT * FROM TABLE(GENERATE_STREAM(0))");
logger.info("after execute returned");
Job job = awaitSingleRunningJob(client);
logger.info("Job is running.");
result.close();
logger.info("after res.close() returned");
assertJobStatusEventually(job, FAILED);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlErrorClientTest method testMemberDisconnect_close.
@Test
public void testMemberDisconnect_close() {
instance1 = newHazelcastInstance(true);
client = newClient();
createMapping(instance1, MAP_NAME, long.class, long.class);
populate(instance1, DEFAULT_CURSOR_BUFFER_SIZE + 1);
try {
SqlResult result = client.getSql().execute(query());
instance1.shutdown();
for (SqlRow ignore : result) {
// No-op.
}
result.close();
fail("Should fail");
} catch (HazelcastSqlException e) {
assertErrorCode(SqlErrorCode.CONNECTION_PROBLEM, e);
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlErrorTest method testMemberLeave.
@Test
public void testMemberLeave() throws InterruptedException {
// Start two instances
instance1 = newHazelcastInstance(false);
instance2 = newHazelcastInstance(true);
Semaphore semaphore = new Semaphore(0);
Thread shutdownThread = new Thread(() -> {
try {
// wait until at least one row is received
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
instance2.shutdown();
});
shutdownThread.start();
// Start query
assertThatThrownBy(() -> {
try (SqlResult res = instance1.getSql().execute("SELECT * FROM TABLE(GENERATE_STREAM(1000))")) {
for (SqlRow ignore : res) {
semaphore.release();
}
}
}).isInstanceOf(HazelcastSqlException.class).hasRootCauseInstanceOf(MemberLeftException.class);
shutdownThread.join();
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlOrderByTest method assertSqlResultCount.
private void assertSqlResultCount(String sql, int expectedCount) {
try (SqlResult res = query(sql)) {
Iterator<SqlRow> rowIterator = res.iterator();
int count = 0;
while (rowIterator.hasNext()) {
rowIterator.next();
count++;
}
assertEquals(expectedCount, count);
assertThrows(NoSuchElementException.class, rowIterator::next);
assertThrows(IllegalStateException.class, res::iterator);
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlOrderByTest method assertSqlResultOrdered.
private void assertSqlResultOrdered(String sql, List<String> orderFields, List<Boolean> orderDirections, int expectedCount, Integer low, Integer high) {
try (SqlResult res = query(sql)) {
SqlRowMetadata rowMetadata = res.getRowMetadata();
Iterator<SqlRow> rowIterator = res.iterator();
SqlRow prevRow = null;
SqlRow lowRow = null;
SqlRow highRow = null;
int count = 0;
while (rowIterator.hasNext()) {
SqlRow row = rowIterator.next();
assertOrdered(prevRow, row, orderFields, orderDirections, rowMetadata);
prevRow = row;
count++;
if (count == 1) {
lowRow = row;
}
if (!rowIterator.hasNext()) {
highRow = row;
}
}
assertEquals(expectedCount, count);
if (lowRow != null && low != null) {
String fieldName = orderFields.get(0);
Object fieldValue = lowRow.getObject(rowMetadata.findColumn(fieldName));
assertEquals(low, fieldValue);
}
if (highRow != null && high != null) {
String fieldName = orderFields.get(0);
Object fieldValue = highRow.getObject(rowMetadata.findColumn(fieldName));
assertEquals(high, fieldValue);
}
assertThrows(NoSuchElementException.class, rowIterator::next);
assertThrows(IllegalStateException.class, res::iterator);
}
}
Aggregations