use of com.hazelcast.sql.SqlRow 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.SqlRow 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.SqlRow 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.SqlRow 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");
}
use of com.hazelcast.sql.SqlRow 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);
}
}
Aggregations