use of com.hazelcast.sql.SqlService in project hazelcast by hazelcast.
the class SqlTestSupport method createIndex.
static void createIndex(HazelcastInstance instance, String name, String mapName, IndexType type, String... attributes) {
SqlService sqlService = instance.getSql();
StringBuilder sb = new StringBuilder("CREATE INDEX IF NOT EXISTS ");
sb.append(name);
sb.append(" ON ");
sb.append(mapName);
sb.append(" ( ");
for (int i = 0; i < attributes.length; ++i) {
if (attributes.length - i - 1 == 0) {
sb.append(attributes[i]);
} else {
sb.append(attributes[i]).append(", ");
}
}
sb.append(" ) ");
sb.append(" TYPE ");
sb.append(type.name());
sqlService.execute(sb.toString());
}
use of com.hazelcast.sql.SqlService 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.SqlService in project hazelcast by hazelcast.
the class SqlClientTest method test_jetJobReturnRowsToClientFrom.
@Test
public void test_jetJobReturnRowsToClientFrom() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
int itemCount = 10_000;
TestBatchSqlConnector.create(sqlService, "t", itemCount);
SqlResult result = sqlService.execute("SELECT v FROM t");
BitSet seenValues = new BitSet(itemCount);
for (SqlRow r : result) {
Integer v = r.getObject(0);
assertFalse("value already seen: " + v, seenValues.get(v));
seenValues.set(v);
}
assertEquals(itemCount, seenValues.cardinality());
}
use of com.hazelcast.sql.SqlService in project hazelcast by hazelcast.
the class SqlClientTest method when_clientDisconnects_then_jobCancelled.
@Test
public void when_clientDisconnects_then_jobCancelled() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
sqlService.execute("SELECT * FROM TABLE(GENERATE_STREAM(100))");
Job job = awaitSingleRunningJob(instance());
client.shutdown();
assertJobStatusEventually(job, FAILED);
assertThatThrownBy(job::join).hasMessageContaining("QueryException: Client cannot be reached");
}
use of com.hazelcast.sql.SqlService in project hazelcast by hazelcast.
the class SqlClientTest method when_resultClosed_then_executionContextCleanedUp.
// test for https://github.com/hazelcast/hazelcast/issues/19897
@Test
public void when_resultClosed_then_executionContextCleanedUp() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sql = client.getSql();
IMap<Integer, Integer> map = instance().getMap("map");
Map<Integer, Integer> tmpMap = new HashMap<>();
for (int i = 0; i < 100_000; i++) {
tmpMap.put(i, i);
if (i % 10_000 == 0) {
map.putAll(tmpMap);
tmpMap.clear();
}
}
createMapping("map", Integer.class, Integer.class);
for (int i = 0; i < 100; i++) {
SqlResult result = sql.execute("SELECT * FROM map");
result.close();
}
JetServiceBackend jetService = getJetServiceBackend(instance());
Collection<ExecutionContext> contexts = jetService.getJobExecutionService().getExecutionContexts();
// Assert that all ExecutionContexts are eventually cleaned up
// This assert will fail if a network packet arrives after the JobExecutionService#FAILED_EXECUTION_EXPIRY_NS
// time. Hopefully Jenkins isn't that slow.
assertTrueEventually(() -> {
String remainingContexts = contexts.stream().map(c -> idToString(c.executionId())).collect(Collectors.joining(", "));
assertEquals("remaining execIds: " + remainingContexts, 0, contexts.size());
}, 5);
// assert that failedJobs is also cleaned up
ConcurrentMap<Long, Long> failedJobs = jetService.getJobExecutionService().getFailedJobs();
assertTrueEventually(() -> assertEquals(0, failedJobs.size()));
}
Aggregations