Search in sources :

Example 11 with SqlRow

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

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

use of com.hazelcast.sql.SqlRow 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 14 with SqlRow

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

Example 15 with SqlRow

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

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