use of com.hazelcast.sql.SqlService in project hazelcast by hazelcast.
the class SqlJobManagementTest method when_clientDisconnects_then_jobContinues.
@Test
public void when_clientDisconnects_then_jobContinues() {
HazelcastInstance client = factory().newHazelcastClient();
SqlService sqlService = client.getSql();
createMapping("dest", Long.class, Long.class);
sqlService.execute("CREATE JOB testJob AS SINK INTO dest SELECT v, v FROM TABLE(GENERATE_STREAM(100))");
Job job = instance().getJet().getJob("testJob");
assertNotNull(job);
assertJobStatusEventually(job, RUNNING);
// When
client.shutdown();
sleepSeconds(1);
// Then
assertEquals(RUNNING, job.getStatus());
}
use of com.hazelcast.sql.SqlService in project hazelcast by hazelcast.
the class SqlTestSupport method assertRowsEventuallyInAnyOrder.
/**
* Execute a query and wait for the results to contain all the {@code
* expectedRows}. Suitable for streaming queries that don't terminate, but
* return a deterministic set of rows. Rows can arrive in any order.
* <p>
* After all expected rows are received, the method further waits a little
* more if any extra rows are received, and fails, if they are.
*
* @param sql The query
* @param arguments The query arguments
* @param expectedRows Expected rows
*/
public static void assertRowsEventuallyInAnyOrder(String sql, List<Object> arguments, Collection<Row> expectedRows) {
SqlService sqlService = instance().getSql();
CompletableFuture<Void> future = new CompletableFuture<>();
Deque<Row> rows = new ArrayDeque<>();
Thread thread = new Thread(() -> {
SqlStatement statement = new SqlStatement(sql);
arguments.forEach(statement::addParameter);
try (SqlResult result = sqlService.execute(statement)) {
ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
for (int i = 0; i < expectedRows.size() && iterator.hasNext() || iterator.hasNext(50, TimeUnit.MILLISECONDS) == YES; i++) {
rows.add(new Row(iterator.next()));
}
future.complete(null);
} catch (Throwable e) {
e.printStackTrace();
future.completeExceptionally(e);
}
});
thread.start();
try {
try {
future.get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) {
thread.interrupt();
thread.join();
}
} catch (Exception e) {
throw sneakyThrow(e);
}
List<Row> actualRows = new ArrayList<>(rows);
assertThat(actualRows).containsExactlyInAnyOrderElementsOf(expectedRows);
}
use of com.hazelcast.sql.SqlService 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.SqlService 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.SqlService in project hazelcast by hazelcast.
the class LightJobBench method sqlBench.
@Test
public void sqlBench() {
int warmUpIterations = 100;
int realIterations = 200;
SqlService sqlService = inst.getSql();
logger.info("will submit " + warmUpIterations + " jobs");
SqlTestSupport.createMapping(inst, "m", int.class, int.class);
inst.getMap("m").put(1, 1);
int numRows = 0;
for (int i = 0; i < warmUpIterations; i++) {
for (SqlRow ignored : sqlService.execute("select * from m")) {
numRows++;
}
}
logger.info("warmup jobs done, starting benchmark");
long start = System.nanoTime();
for (int i = 0; i < realIterations; i++) {
for (SqlRow ignored : sqlService.execute("select * from m")) {
numRows++;
}
}
long elapsedMicros = NANOSECONDS.toMicros(System.nanoTime() - start);
System.out.println(numRows);
System.out.println(realIterations + " queries run in " + (elapsedMicros / realIterations) + " us/job");
}
Aggregations