Search in sources :

Example 46 with SQLResponse

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

the class InformationSchemaQueryTest method testConcurrentInformationSchemaQueries.

@Test
public void testConcurrentInformationSchemaQueries() throws Exception {
    final SQLResponse response = execute("select * from information_schema.columns " + "order by table_schema, table_name, column_name");
    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 information_schema.columns " + "order by table_schema, table_name, column_name");
                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 47 with SQLResponse

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

the class InsertIntoIntegrationTest method testInsertWithPrimaryKeyMultiValuesFailing.

@Test
public void testInsertWithPrimaryKeyMultiValuesFailing() throws Exception {
    execute("create table locations (id integer primary key)");
    ensureYellow();
    SQLResponse response = execute("insert into locations (id) values (1), (2)");
    assertThat(response.rowCount(), is(2L));
    response = execute("insert into locations (id) values (2), (3)");
    assertThat(response.rowCount(), is(1L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 48 with SQLResponse

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

the class JobLogIntegrationTest method testEmptyJobsInLog.

@Test
public void testEmptyJobsInLog() throws Exception {
    // Setup data
    sqlExecutor.exec("create table characters (id int primary key, name string)");
    sqlExecutor.ensureYellowOrGreen();
    sqlExecutor.exec("set global transient stats.enabled = true");
    sqlExecutor.exec("insert into characters (id, name) values (1, 'sysjobstest')");
    sqlExecutor.exec("refresh table characters");
    SQLResponse response = sqlExecutor.exec("delete from characters where id = 1");
    // make sure everything is deleted (nothing changed in whole class lifecycle cluster state)
    assertThat(response.rowCount(), is(1L));
    sqlExecutor.exec("refresh table characters");
    response = sqlExecutor.exec("select * from sys.jobs_log where stmt like 'insert into%' or stmt like 'delete%'");
    assertThat(response.rowCount(), is(2L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 49 with SQLResponse

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

the class FulltextAnalyzerResolverTest method useAnalyzerForIndexSettings.

@Test
public void useAnalyzerForIndexSettings() throws Exception {
    execute("CREATE ANALYZER a11 (" + "  TOKENIZER standard," + "  TOKEN_FILTERS (" + "    lowercase," + "    mystop WITH (" + "      type='stop'," + "      stopword=['the', 'over']" + "    )" + "  )" + ")");
    Settings settings = getPersistentClusterSettings();
    assertThat(settings.getAsMap(), allOf(hasKey("crate.analysis.custom.analyzer.a11"), hasKey("crate.analysis.custom.filter.a11_mystop")));
    Settings analyzerSettings = FulltextAnalyzerResolver.decodeSettings(settings.get("crate.analysis.custom.analyzer.a11"));
    Settings tokenFilterSettings = FulltextAnalyzerResolver.decodeSettings(settings.get("crate" + ".analysis.custom.filter.a11_mystop"));
    Settings.Builder builder = Settings.builder();
    builder.put(analyzerSettings);
    builder.put(tokenFilterSettings);
    execute("create table test (" + " id integer primary key," + " name string," + " content string index using fulltext with (analyzer='a11')" + ")");
    ensureYellow();
    execute("insert into test (id, name, content) values (?, ?, ?)", new Object[] { 1, "phrase", "The quick brown fox jumps over the lazy dog." });
    execute("insert into test (id, name, content) values (?, ?, ?)", new Object[] { 2, "another phrase", "Don't panic!" });
    refresh();
    SQLResponse response = execute("select id from test where match(content, 'brown jump')");
    assertEquals(1L, response.rowCount());
    assertEquals(1, response.rows()[0][0]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 50 with SQLResponse

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

the class GroupByAggregateTest method testGroupByArbitrary.

@Test
public void testGroupByArbitrary() throws Exception {
    this.setup.groupBySetup();
    execute("select arbitrary(name), race from characters group by race order by race asc");
    SQLResponse arbitrary_response = response;
    assertEquals(3, arbitrary_response.rowCount());
    assertEquals("Android", arbitrary_response.rows()[0][1]);
    assertEquals(1, execute("select name from characters where race=? AND name=? ", new Object[] { "Android", arbitrary_response.rows()[0][0] }).rowCount());
    assertEquals("Human", arbitrary_response.rows()[1][1]);
    assertEquals(1, execute("select name from characters where race=? AND name=? ", new Object[] { "Human", arbitrary_response.rows()[1][0] }).rowCount());
    assertEquals("Vogon", arbitrary_response.rows()[2][1]);
    assertEquals(1, execute("select name from characters where race=? AND name=? ", new Object[] { "Vogon", arbitrary_response.rows()[2][0] }).rowCount());
}
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