Search in sources :

Example 21 with SqlResult

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

the class SqlTestSupport method assertRowsOrdered.

/**
 * Execute a query and wait until it completes. Assert that the returned
 * rows contain the expected rows, in the given order.
 *
 * @param sql          The query
 * @param expectedRows Expected rows
 */
public static void assertRowsOrdered(String sql, List<Row> expectedRows) {
    SqlService sqlService = instance().getSql();
    List<Row> actualRows = new ArrayList<>();
    try (SqlResult result = sqlService.execute(sql)) {
        result.iterator().forEachRemaining(row -> actualRows.add(new Row(row)));
    }
    assertThat(actualRows).containsExactlyElementsOf(expectedRows);
}
Also used : 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)

Example 22 with SqlResult

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

the class PlanExecutorTest method test_dropMappingExecution.

@Test
@Parameters({ "true", "false" })
public void test_dropMappingExecution(boolean ifExists) {
    // given
    String name = "name";
    DropMappingPlan plan = new DropMappingPlan(planKey(), name, ifExists, planExecutor);
    // when
    SqlResult result = planExecutor.execute(plan);
    // then
    assertThat(result.updateCount()).isEqualTo(0);
    verify(catalog).removeMapping(name, ifExists);
}
Also used : DropMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.DropMappingPlan) SqlResult(com.hazelcast.sql.SqlResult) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 23 with SqlResult

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

the class PlanExecutorTest method test_createMappingExecution.

@Test
@Parameters({ "true, false", "false, true" })
public void test_createMappingExecution(boolean replace, boolean ifNotExists) {
    // given
    Mapping mapping = mapping();
    CreateMappingPlan plan = new CreateMappingPlan(planKey(), mapping, replace, ifNotExists, planExecutor);
    // when
    SqlResult result = planExecutor.execute(plan);
    // then
    assertThat(result.updateCount()).isEqualTo(0);
    verify(catalog).createMapping(mapping, replace, ifNotExists);
}
Also used : SqlResult(com.hazelcast.sql.SqlResult) Mapping(com.hazelcast.sql.impl.schema.Mapping) CreateMappingPlan(com.hazelcast.jet.sql.impl.SqlPlanImpl.CreateMappingPlan) Parameters(junitparams.Parameters) Test(org.junit.Test)

Example 24 with SqlResult

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

the class SqlResultImplTest method when_closed_then_iteratorFails.

@Test
public // test for https://github.com/hazelcast/hazelcast-jet/issues/2697
void when_closed_then_iteratorFails() {
    SqlResult sqlResult = instance().getSql().execute("select * from table(generate_stream(1))");
    sqlResult.close();
    Iterator<SqlRow> iterator = sqlResult.iterator();
    assertThatThrownBy(() -> iterator.forEachRemaining(ConsumerEx.noop()));
}
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 25 with SqlResult

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

the class SqlResultImplTest method when_hasNextInterrupted_then_interrupted.

@Test
public void when_hasNextInterrupted_then_interrupted() {
    // this query is a continuous one, but never returns any rows (all are filtered out)
    SqlResult sqlResult = instance().getSql().execute("select * from table(generate_stream(1)) where v < 0");
    AtomicBoolean interruptedOk = new AtomicBoolean();
    Thread t = new Thread(() -> {
        try {
            sqlResult.iterator().hasNext();
        } catch (Throwable e) {
            if (e.getCause() instanceof RuntimeException && e.getCause().getCause() instanceof InterruptedException) {
                interruptedOk.set(true);
            } else {
                logger.severe("Unexpected exception caught", e);
            }
        }
    });
    t.start();
    t.interrupt();
    assertTrueEventually(() -> assertTrue(interruptedOk.get()));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlResult(com.hazelcast.sql.SqlResult) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) 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