Search in sources :

Example 11 with SqlResult

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

the class SqlClientResultTest method when_checkingHasNextWithTimeout_then_timeoutIsLongerThanParam.

@Test
public void when_checkingHasNextWithTimeout_then_timeoutIsLongerThanParam() {
    try (SqlResult result = execute("select * from table(generate_stream(1))")) {
        assertTrue(result.isRowSet());
        ResultIterator<SqlRow> iterator = (ResultIterator<SqlRow>) result.iterator();
        long shortestSleep = Long.MAX_VALUE;
        for (int i = 0; i < 2; i++) {
            long startNanos = System.nanoTime();
            while (iterator.hasNext(10, TimeUnit.MILLISECONDS) == ResultIterator.HasNextResult.TIMEOUT) {
                shortestSleep = Math.min(shortestSleep, System.nanoTime() - startNanos);
                startNanos = System.nanoTime();
            }
            iterator.next();
        }
        assertGreaterOrEquals("shortestSleep", shortestSleep, TimeUnit.MILLISECONDS.toNanos(10));
    }
}
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 12 with SqlResult

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

the class SqlClientResultTest method when_fetchingElementOnClosedResult_then_fail.

@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void when_fetchingElementOnClosedResult_then_fail() {
    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();
        result.close();
        checkSqlException(iterator::hasNext, SqlErrorCode.CANCELLED_BY_USER, "Query was cancelled by the user");
        checkSqlException(iterator::next, SqlErrorCode.CANCELLED_BY_USER, "Query was cancelled by the user");
    }
}
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 13 with SqlResult

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

the class SqlClientCompactQueryTest method testQueryOnPrimitive.

@Test
public void testQueryOnPrimitive() {
    HazelcastInstance client = factory.newHazelcastClient(clientConfig());
    IMap<Integer, Object> map = client.getMap("test");
    for (int i = 0; i < 10; i++) {
        map.put(i, new EmployeeDTO(i, i));
    }
    client.getSql().execute("CREATE MAPPING " + "test" + '(' + "__key INTEGER" + ", age INTEGER" + ", \"rank\" INTEGER" + ", id BIGINT" + ", isHired BOOLEAN" + ", isFired BOOLEAN" + ") TYPE " + IMapSqlConnector.TYPE_NAME + ' ' + "OPTIONS (" + '\'' + OPTION_KEY_FORMAT + "'='" + "int" + '\'' + ", '" + OPTION_VALUE_FORMAT + "'='" + COMPACT_FORMAT + '\'' + ", '" + OPTION_VALUE_COMPACT_TYPE_NAME + "'='" + EmployeeDTO.class.getName() + '\'' + ")");
    SqlResult result = client.getSql().execute("SELECT * FROM test WHERE age >= 5");
    assertThat(result).hasSize(5);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) EmployeeDTO(example.serialization.EmployeeDTO) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with SqlResult

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

the class SqlClientPortableQueryTest method testQueryOnObject.

@Test
public void testQueryOnObject() {
    // To be able to run comparison methods on objects on the server we need the classes
    assumeTrue(clusterHasPortableConfig);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getSerializationConfig().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory());
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    createMapping(client, "test", int.class, PORTABLE_FACTORY_ID, PORTABLE_PARENT_CLASS_ID, 0);
    IMap<Integer, ParentPortable> map = client.getMap("test");
    fillMap(map, 100, ParentPortable::new);
    ChildPortable expected = new ChildPortable(10);
    SqlResult rows = client.getSql().execute("SELECT id FROM test WHERE child = ?", expected);
    SqlRow row = Iterators.getOnlyElement(rows.iterator());
    assertEquals(new Integer(10), row.getObject("id"));
}
Also used : SqlRow(com.hazelcast.sql.SqlRow) HazelcastInstance(com.hazelcast.core.HazelcastInstance) SqlResult(com.hazelcast.sql.SqlResult) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with SqlResult

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

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