Search in sources :

Example 16 with SqlRow

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);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with SqlRow

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");
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlService(com.hazelcast.sql.SqlService) Test(org.junit.Test)

Example 18 with SqlRow

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();
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) Semaphore(java.util.concurrent.Semaphore) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 19 with SqlRow

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);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult)

Example 20 with SqlRow

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);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) SqlRowMetadata(com.hazelcast.sql.SqlRowMetadata)

Aggregations

SqlRow (com.hazelcast.sql.SqlRow)65 Test (org.junit.Test)35 SqlResult (com.hazelcast.sql.SqlResult)29 QuickTest (com.hazelcast.test.annotation.QuickTest)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)17 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)13 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)11 ArrayList (java.util.ArrayList)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 SqlStatement (com.hazelcast.sql.SqlStatement)7 SqlService (com.hazelcast.sql.SqlService)5 HashSet (java.util.HashSet)5 SqlColumnType (com.hazelcast.sql.SqlColumnType)3 ClientConfig (com.hazelcast.client.config.ClientConfig)2 Config (com.hazelcast.config.Config)2 IndexConfig (com.hazelcast.config.IndexConfig)2 HazelcastException (com.hazelcast.core.HazelcastException)2 ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)2 IMap (com.hazelcast.map.IMap)2 SqlColumnMetadata (com.hazelcast.sql.SqlColumnMetadata)2