Search in sources :

Example 41 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByNullArgs.

@Test
// NPE because of unused null parameter
@UseJdbc(0)
public void testCountWithGroupByNullArgs() throws Exception {
    SQLResponse response = execute("select count(*), race from characters group by race", new Object[] { null });
    assertEquals(3, response.rowCount());
}
Also used : SQLResponse(io.crate.testing.SQLResponse) UseJdbc(io.crate.testing.UseJdbc)

Example 42 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testSetMultipleStatement.

@Test
// set has no rowcount
@UseJdbc(0)
public void testSetMultipleStatement() throws Exception {
    SQLResponse response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue()));
    assertThat((Boolean) response.rows()[0][1], is(CrateSettings.STATS_ENABLED.defaultValue()));
    response = execute("set global persistent stats.operations_log_size=1024, stats.enabled=false");
    assertThat(response.rowCount(), is(1L));
    response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(1024));
    assertThat((Boolean) response.rows()[0][1], is(false));
    response = execute("reset global stats.operations_log_size, stats.enabled");
    assertThat(response.rowCount(), is(1L));
    waitNoPendingTasksOnAll();
    response = execute("select settings['stats']['operations_log_size'], settings['stats']['enabled'] from sys.cluster");
    assertThat(response.rowCount(), is(1L));
    assertThat((Integer) response.rows()[0][0], is(CrateSettings.STATS_OPERATIONS_LOG_SIZE.defaultValue()));
    assertThat((Boolean) response.rows()[0][1], is(CrateSettings.STATS_ENABLED.defaultValue()));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) UseJdbc(io.crate.testing.UseJdbc)

Example 43 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testGlobalAggregateWithoutNulls.

@Test
public void testGlobalAggregateWithoutNulls() throws Exception {
    SQLResponse firstResp = execute("select sum(age) from characters");
    SQLResponse secondResp = execute("select sum(age) from characters where age is not null");
    assertEquals(firstResp.rowCount(), secondResp.rowCount());
    assertEquals(firstResp.rows()[0][0], secondResp.rows()[0][0]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 44 with SQLResponse

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

the class CopyIntegrationTest method testCopyToDirectory.

@Test
public void testCopyToDirectory() throws Exception {
    this.setup.groupBySetup();
    String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
    SQLResponse response = execute("copy characters to DIRECTORY ?", new Object[] { uriTemplate });
    assertThat(response.rowCount(), is(7L));
    String[] list = folder.getRoot().list();
    assertThat(list, is(notNullValue()));
    assertThat(list.length, greaterThanOrEqualTo(1));
    for (String file : list) {
        assertThat(file, startsWith("characters_"));
    }
    List<String> lines = new ArrayList<>(7);
    DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json");
    for (Path path : stream) {
        lines.addAll(Files.readAllLines(path, StandardCharsets.UTF_8));
    }
    assertThat(lines.size(), is(7));
    for (String line : lines) {
        assertThat(line, startsWith("{"));
        assertThat(line, endsWith("}"));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 45 with SQLResponse

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

the class CopyIntegrationTest method testCopyToWithCompression.

@Test
public void testCopyToWithCompression() throws Exception {
    execute("create table singleshard (name string) clustered into 1 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into singleshard (name) values ('foo')");
    execute("refresh table singleshard");
    String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
    SQLResponse response = execute("copy singleshard to DIRECTORY ? with (compression='gzip')", new Object[] { uriTemplate });
    assertThat(response.rowCount(), is(1L));
    String[] list = folder.getRoot().list();
    assertThat(list, is(notNullValue()));
    assertThat(list.length, is(1));
    String file = list[0];
    assertThat(file, both(startsWith("singleshard_")).and(endsWith(".json.gz")));
    long size = Files.size(Paths.get(folder.getRoot().toURI().resolve(file)));
    assertThat(size, is(35L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

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