use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientResultTest method when_checkingHasNextWithTimeout_then_timeoutIsLongerThanParam.
@Test
public void when_checkingHasNextWithTimeout_then_timeoutIsLongerThanParam() {
try (SqlResult result = execute("select * from table(generate_stream(1))")) {
assertTrue(result.isRowSet());
ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
long shortestSleep = Long.MAX_VALUE;
for (int i = 0; i < 2; i++) {
long startNanos = System.nanoTime();
while (iterator.hasNext(10, TimeUnit.MILLISECONDS) == ResultIterator.HasNextResult.TIMEOUT) {
shortestSleep = Math.min(shortestSleep, System.nanoTime() - startNanos);
startNanos = System.nanoTime();
}
iterator.next();
}
assertGreaterOrEquals("shortestSleep", shortestSleep, TimeUnit.MILLISECONDS.toNanos(10));
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientResultTest method when_fetchingElementOnClosedResult_then_fail.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void when_fetchingElementOnClosedResult_then_fail() {
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();
result.close();
checkSqlException(iterator::hasNext, SqlErrorCode.CANCELLED_BY_USER, "Query was cancelled by the user");
checkSqlException(iterator::next, SqlErrorCode.CANCELLED_BY_USER, "Query was cancelled by the user");
}
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientCompactQueryTest method testQueryOnPrimitive.
@Test
public void testQueryOnPrimitive() {
HazelcastInstance client = factory.newHazelcastClient(clientConfig());
IMap<Integer, Object> map = client.getMap("test");
for (int i = 0; i < 10; i++) {
map.put(i, new EmployeeDTO(i, i));
}
client.getSql().execute("CREATE MAPPING " + "test" + '(' + "__key INTEGER" + ", age INTEGER" + ", \"rank\" INTEGER" + ", id BIGINT" + ", isHired BOOLEAN" + ", isFired BOOLEAN" + ") TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + "int" + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + EmployeeDTO.class.getName() + '\'' + ")");
SqlResult result = client.getSql().execute("SELECT * FROM test WHERE age >= 5");
assertThat(result).hasSize(5);
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientPortableQueryTest method testQueryOnObject.
@Test
public void testQueryOnObject() {
// To be able to run comparison methods on objects on the server we need the classes
assumeTrue(clusterHasPortableConfig);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getSerializationConfig().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
createMapping(client, "test", int.class, PORTABLE_FACTORY_ID, PORTABLE_PARENT_CLASS_ID, 0);
IMap<Integer, ParentPortable> map = client.getMap("test");
fillMap(map, 100, ParentPortable::new);
ChildPortable expected = new ChildPortable(10);
SqlResult rows = client.getSql().execute("SELECT id FROM test WHERE child = ?", expected);
SqlRow row = Iterators.getOnlyElement(rows.iterator());
assertEquals(new Integer(10), row.getObject("id"));
}
use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.
the class SqlClientTest method when_jobFails_then_clientFindsOut.
@Test
public void when_jobFails_then_clientFindsOut() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
sqlService.execute("CREATE MAPPING t TYPE " + TestFailingSqlConnector.TYPE_NAME);
assertThatThrownBy(() -> {
SqlResult result = sqlService.execute("SELECT * FROM t");
for (SqlRow r : result) {
System.out.println(r);
}
}).hasMessageContaining("mock failure");
}
Aggregations