Search in sources :

Example 46 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlErrorAbstractTest method checkUserCancel.

@SuppressWarnings("StatementWithEmptyBody")
protected void checkUserCancel(boolean useClient) {
    instance1 = newHazelcastInstance(true);
    client = newClient();
    HazelcastInstance target = useClient ? client : instance1;
    try (SqlResult res = target.getSql().execute("select * from table(generate_stream(1))")) {
        sleepSeconds(1);
        res.close();
        try {
            for (SqlRow ignore : res) {
            // No-op.
            }
            fail("Exception is not thrown");
        } catch (HazelcastSqlException e) {
            assertErrorCode(SqlErrorCode.CANCELLED_BY_USER, e);
        }
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException)

Example 47 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlClientResultTest method when_checkingHasNextWithTimeout_then_timeoutOccurs.

@Test
public void when_checkingHasNextWithTimeout_then_timeoutOccurs() {
    try (SqlResult result = execute("select * from table(generate_stream(1))")) {
        assertTrue(result.isRowSet());
        ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
        int timeoutCount = 0;
        for (int i = 0; i < 2; i++) {
            while (iterator.hasNext(10, TimeUnit.MILLISECONDS) == ResultIterator.HasNextResult.TIMEOUT) {
                timeoutCount++;
            }
            iterator.next();
        }
        assertNotEquals(0, timeoutCount);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ResultIterator(com.hazelcast.sql.impl.ResultIterator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlClientResultTest method when_executingValidQuery.

@Test
public void when_executingValidQuery() {
    try (SqlResult result = execute("SELECT * FROM " + MAP_NAME)) {
        assertEquals(2, result.getRowMetadata().getColumnCount());
        assertEquals(-1, result.updateCount());
        assertTrue(result.isRowSet());
        Iterator<SqlRow> iterator = result.iterator();
        iterator.next();
        iterator.next();
        assertFalse(iterator.hasNext());
        checkIllegalStateException(result::iterator, "Iterator can be requested only once");
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlErrorClientTest method testRowError_deserialization.

@Test
public void testRowError_deserialization() {
    try {
        instance1 = newHazelcastInstance(true);
        client = newClient();
        Map<Integer, BadValue> localMap = new HashMap<>();
        IMap<Integer, BadValue> map = instance1.getMap(MAP_NAME);
        createMapping(instance1, MAP_NAME, int.class, BadValue.class);
        for (int i = 0; i < DEFAULT_CURSOR_BUFFER_SIZE + 1; i++) {
            localMap.put(i, new BadValue());
        }
        map.putAll(localMap);
        try (SqlResult result = client.getSql().execute("SELECT __key, this FROM " + MAP_NAME)) {
            Iterator<SqlRow> iterator = result.iterator();
            SqlRow firstRow = iterator.next();
            firstRow.getObject("__key");
            firstRow.getObject("this");
            BadValue.READ_ERROR.set(true);
            SqlRow secondRow = iterator.next();
            secondRow.getObject("__key");
            assertThatThrownBy(() -> secondRow.getObject("this")).isInstanceOf(HazelcastSerializationException.class).hasMessageContaining("Failed to deserialize query result value");
        }
    } finally {
        BadValue.READ_ERROR.set(false);
    }
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SqlResult(com.hazelcast.sql.SqlResult) HashMap(java.util.HashMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with SqlResult

use of com.hazelcast.sql.SqlResult in project hazelcast by hazelcast.

the class SqlTestSupport method assertRowsAnyOrder.

/**
 * Execute a query and wait until it completes. Assert that the returned
 * rows contain the expected rows, in any order.
 *
 * @param instance     Hazelcast Instance to be used
 * @param sql          The query
 * @param arguments    The query arguments
 * @param expectedRows Expected rows
 */
public static void assertRowsAnyOrder(HazelcastInstance instance, String sql, List<Object> arguments, Collection<Row> expectedRows) {
    SqlStatement statement = new SqlStatement(sql);
    arguments.forEach(statement::addParameter);
    SqlService sqlService = instance.getSql();
    List<Row> actualRows = new ArrayList<>();
    try (SqlResult result = sqlService.execute(statement)) {
        result.iterator().forEachRemaining(row -> actualRows.add(new Row(row)));
    }
    assertThat(actualRows).containsExactlyInAnyOrderElementsOf(expectedRows);
}
Also used : SqlStatement(com.hazelcast.sql.SqlStatement) SqlResult(com.hazelcast.sql.SqlResult) SqlService(com.hazelcast.sql.SqlService) ArrayList(java.util.ArrayList) SqlRow(com.hazelcast.sql.SqlRow) JetSqlRow(com.hazelcast.sql.impl.row.JetSqlRow)

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