Search in sources :

Example 16 with SqlResult

use of com.hazelcast.sql.SqlResult 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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) SqlService(com.hazelcast.sql.SqlService) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 17 with SqlResult

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

Example 18 with SqlResult

use of com.hazelcast.sql.SqlResult 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 SqlResult

use of com.hazelcast.sql.SqlResult 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 SqlResult

use of com.hazelcast.sql.SqlResult 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

SqlResult (com.hazelcast.sql.SqlResult)60 Test (org.junit.Test)38 SqlRow (com.hazelcast.sql.SqlRow)31 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 SqlStatement (com.hazelcast.sql.SqlStatement)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 ArrayList (java.util.ArrayList)9 Job (com.hazelcast.jet.Job)8 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)8 SqlService (com.hazelcast.sql.SqlService)8 JobConfig (com.hazelcast.jet.config.JobConfig)7 JetSqlRow (com.hazelcast.sql.impl.row.JetSqlRow)6 HashMap (java.util.HashMap)5 SqlRowMetadata (com.hazelcast.sql.SqlRowMetadata)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 TimeoutException (java.util.concurrent.TimeoutException)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 IndexConfig (com.hazelcast.config.IndexConfig)3