use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlErrorClientTest method testMemberDisconnect_fetch.
@Test
public void testMemberDisconnect_fetch() {
instance1 = newHazelcastInstance(true);
client = newClient();
createMapping(instance1, MAP_NAME, long.class, long.class);
populate(instance1, DEFAULT_CURSOR_BUFFER_SIZE + 1);
// Get the first row.
boolean shutdown = true;
try {
for (SqlRow ignore : client.getSql().execute(query())) {
// Shutdown the member
if (shutdown) {
instance1.shutdown();
shutdown = false;
}
}
fail("Should fail");
} catch (HazelcastSqlException e) {
assertErrorCode(SqlErrorCode.CONNECTION_PROBLEM, e);
}
}
use of com.hazelcast.sql.SqlRow 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");
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlErrorTest method testMemberLeave.
@Test
public void testMemberLeave() throws InterruptedException {
// Start two instances
instance1 = newHazelcastInstance(false);
instance2 = newHazelcastInstance(true);
Semaphore semaphore = new Semaphore(0);
Thread shutdownThread = new Thread(() -> {
try {
// wait until at least one row is received
semaphore.acquire();
} catch (InterruptedException e) {
e.printStackTrace();
}
instance2.shutdown();
});
shutdownThread.start();
// Start query
assertThatThrownBy(() -> {
try (SqlResult res = instance1.getSql().execute("SELECT * FROM TABLE(GENERATE_STREAM(1000))")) {
for (SqlRow ignore : res) {
semaphore.release();
}
}
}).isInstanceOf(HazelcastSqlException.class).hasRootCauseInstanceOf(MemberLeftException.class);
shutdownThread.join();
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlOrderByTest method assertSqlResultCount.
private void assertSqlResultCount(String sql, int expectedCount) {
try (SqlResult res = query(sql)) {
Iterator<SqlRow> rowIterator = res.iterator();
int count = 0;
while (rowIterator.hasNext()) {
rowIterator.next();
count++;
}
assertEquals(expectedCount, count);
assertThrows(NoSuchElementException.class, rowIterator::next);
assertThrows(IllegalStateException.class, res::iterator);
}
}
use of com.hazelcast.sql.SqlRow in project hazelcast by hazelcast.
the class SqlOrderByTest method assertSqlResultOrdered.
private void assertSqlResultOrdered(String sql, List<String> orderFields, List<Boolean> orderDirections, int expectedCount, Integer low, Integer high) {
try (SqlResult res = query(sql)) {
SqlRowMetadata rowMetadata = res.getRowMetadata();
Iterator<SqlRow> rowIterator = res.iterator();
SqlRow prevRow = null;
SqlRow lowRow = null;
SqlRow highRow = null;
int count = 0;
while (rowIterator.hasNext()) {
SqlRow row = rowIterator.next();
assertOrdered(prevRow, row, orderFields, orderDirections, rowMetadata);
prevRow = row;
count++;
if (count == 1) {
lowRow = row;
}
if (!rowIterator.hasNext()) {
highRow = row;
}
}
assertEquals(expectedCount, count);
if (lowRow != null && low != null) {
String fieldName = orderFields.get(0);
Object fieldValue = lowRow.getObject(rowMetadata.findColumn(fieldName));
assertEquals(low, fieldValue);
}
if (highRow != null && high != null) {
String fieldName = orderFields.get(0);
Object fieldValue = highRow.getObject(rowMetadata.findColumn(fieldName));
assertEquals(high, fieldValue);
}
assertThrows(NoSuchElementException.class, rowIterator::next);
assertThrows(IllegalStateException.class, res::iterator);
}
}
Aggregations