Search in sources :

Example 51 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class InformationSchemaQueryTest method testConcurrentUnassignedShardsReferenceResolver.

@Test
public void testConcurrentUnassignedShardsReferenceResolver() throws Exception {
    internalCluster().ensureAtMostNumDataNodes(1);
    execute("create table t1 (col1 integer) " + "clustered into 1 shards " + "with (number_of_replicas=8)");
    execute("create table t2 (col1 integer) " + "clustered into 1 shards " + "with (number_of_replicas=8)");
    ensureYellow();
    final SQLResponse response = execute("select * from sys.shards where table_name in ('t1', 't2') and state='UNASSIGNED' order by schema_name, table_name, id");
    final CountDownLatch latch = new CountDownLatch(40);
    final AtomicReference<AssertionError> lastAssertionError = new AtomicReference<>();
    for (int i = 0; i < 40; i++) {
        final Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                SQLResponse resp = execute("select * from sys.shards where table_name in ('t1', 't2') and state='UNASSIGNED' order by schema_name, table_name, id");
                try {
                    assertThat(resp.rows(), Matchers.equalTo(response.rows()));
                } catch (AssertionError e) {
                    lastAssertionError.set(e);
                }
                latch.countDown();
            }
        });
        t.start();
    }
    latch.await();
    AssertionError assertionError = lastAssertionError.get();
    if (assertionError != null) {
        throw assertionError;
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 52 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByWithWhereClause.

@Test
public void testCountWithGroupByWithWhereClause() throws Exception {
    SQLResponse response = execute("select count(*), race from characters where race = 'Human' group by race");
    assertEquals(1, response.rowCount());
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 53 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testSysOperationsLog.

@Test
public void testSysOperationsLog() throws Exception {
    execute("select count(*), race from characters group by race order by count(*) desc limit 2");
    SQLResponse resp = execute("select count(*) from sys.operations_log");
    assertThat((Long) resp.rows()[0][0], is(0L));
    execute("set global transient stats.enabled = true, stats.operations_log_size=10");
    waitNoPendingTasksOnAll();
    execute("select count(*), race from characters group by race order by count(*) desc limit 2");
    assertBusy(new Runnable() {

        @Override
        public void run() {
            SQLResponse resp = execute("select * from sys.operations_log order by ended limit 3");
            List<String> names = new ArrayList<>();
            for (Object[] objects : resp.rows()) {
                names.add((String) objects[4]);
            }
            assertThat(names, Matchers.anyOf(Matchers.hasItems("distributing collect", "distributing collect"), Matchers.hasItems("collect", "localMerge"), // the select * from sys.operations_log has 2 collect operations (1 per node)
            Matchers.hasItems("collect", "collect"), Matchers.hasItems("distributed merge", "localMerge")));
        }
    }, 10L, TimeUnit.SECONDS);
    execute("reset global stats.enabled, stats.operations_log_size");
    waitNoPendingTasksOnAll();
    resp = execute("select count(*) from sys.operations_log");
    assertThat((Long) resp.rows()[0][0], is(0L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) ArrayList(java.util.ArrayList) List(java.util.List)

Example 54 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnAggAscFuncAndSecondColumnAndLimitAndTooLargeOffset.

@Test
public void testCountWithGroupByOrderOnAggAscFuncAndSecondColumnAndLimitAndTooLargeOffset() throws Exception {
    SQLResponse response = execute("select count(*), gender, race from characters " + "group by race, gender order by count(*) desc, race asc limit 2 offset 20");
    assertEquals(0, response.rows().length);
    assertEquals(0, response.rowCount());
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 55 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testSelectRaw.

@Test
public void testSelectRaw() throws Exception {
    SQLResponse response = execute("select _raw from characters order by name desc limit 1");
    assertEquals("{\"race\":\"Human\",\"gender\":\"female\",\"age\":32,\"birthdate\":276912000000," + "\"name\":\"Trillian\",\"details\":{\"job\":\"Mathematician\"}}\n", TestingHelpers.printedTable(response.rows()));
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Aggregations

SQLResponse (io.crate.testing.SQLResponse)109 Test (org.junit.Test)78 Map (java.util.Map)13 UseJdbc (io.crate.testing.UseJdbc)10 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 PartitionName (io.crate.metadata.PartitionName)4 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)4 Path (java.nio.file.Path)4 BytesRef (org.apache.lucene.util.BytesRef)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TreeMap (java.util.TreeMap)2 List (java.util.List)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ClusterRerouteRequestBuilder (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1