use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlErrorAbstractTest method checkUserCancel.
@SuppressWarnings("StatementWithEmptyBody")
protected void checkUserCancel(boolean useClient) {
instance1 = newHazelcastInstance(true);
client = newClient();
HazelcastInstance target = useClient ? client : instance1;
try (SqlResult res = target.getSql().execute("select * from table(generate_stream(1))")) {
sleepSeconds(1);
res.close();
try {
for (SqlRow ignore : res) {
// No-op.
}
fail("Exception is not thrown");
} catch (HazelcastSqlException e) {
assertErrorCode(SqlErrorCode.CANCELLED_BY_USER, e);
}
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientResultTest method when_checkingHasNextWithTimeout_then_timeoutOccurs.
@Test
public void when_checkingHasNextWithTimeout_then_timeoutOccurs() {
try (SqlResult result = execute("select * from table(generate_stream(1))")) {
assertTrue(result.isRowSet());
ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
int timeoutCount = 0;
for (int i = 0; i < 2; i++) {
while (iterator.hasNext(10, TimeUnit.MILLISECONDS) == ResultIterator.HasNextResult.TIMEOUT) {
timeoutCount++;
}
iterator.next();
}
assertNotEquals(0, timeoutCount);
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientResultTest method when_executingValidQuery.
@Test
public void when_executingValidQuery() {
try (SqlResult result = execute("SELECT * FROM " + MAP_NAME)) {
assertEquals(2, result.getRowMetadata().getColumnCount());
assertEquals(-1, result.updateCount());
assertTrue(result.isRowSet());
Iterator<SqlRow> iterator = result.iterator();
iterator.next();
iterator.next();
assertFalse(iterator.hasNext());
checkIllegalStateException(result::iterator, "Iterator can be requested only once");
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlErrorClientTest method testRowError_deserialization.
@Test
public void testRowError_deserialization() {
try {
instance1 = newHazelcastInstance(true);
client = newClient();
Map<Integer, BadValue> localMap = new HashMap<>();
IMap<Integer, BadValue> map = instance1.getMap(MAP_NAME);
createMapping(instance1, MAP_NAME, int.class, BadValue.class);
for (int i = 0; i < DEFAULT_CURSOR_BUFFER_SIZE + 1; i++) {
localMap.put(i, new BadValue());
}
map.putAll(localMap);
try (SqlResult result = client.getSql().execute("SELECT __key, this FROM " + MAP_NAME)) {
Iterator<SqlRow> iterator = result.iterator();
SqlRow firstRow = iterator.next();
firstRow.getObject("__key");
firstRow.getObject("this");
BadValue.READ_ERROR.set(true);
SqlRow secondRow = iterator.next();
secondRow.getObject("__key");
assertThatThrownBy(() -> secondRow.getObject("this")).isInstanceOf(HazelcastSerializationException.class).hasMessageContaining("Failed to deserialize query result value");
}
} finally {
BadValue.READ_ERROR.set(false);
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlTestSupport method assertRowsAnyOrder.
/**
* Execute a query and wait until it completes. Assert that the returned
* rows contain the expected rows, in any order.
*
* @param instance Hazelcast Instance to be used
* @param sql The query
* @param arguments The query arguments
* @param expectedRows Expected rows
*/
public static void assertRowsAnyOrder(HazelcastInstance instance, String sql, List<Object> arguments, Collection<Row> expectedRows) {
SqlStatement statement = new SqlStatement(sql);
arguments.forEach(statement::addParameter);
SqlService sqlService = instance.getSql();
List<Row> actualRows = new ArrayList<>();
try (SqlResult result = sqlService.execute(statement)) {
result.iterator().forEachRemaining(row -> actualRows.add(new Row(row)));
}
assertThat(actualRows).containsExactlyInAnyOrderElementsOf(expectedRows);
}
Aggregations