SQL: [Tests] Fix and enable internalClusterTests (#37300)
SqlPlugin cannot have more than one public constructor, so for the testing purposes the `getLicenseState()` should be overriden. Fixes: #37191 Co-authored-by: Michael Basnight <mbasnight@gmail.com>
This commit is contained in:
parent
5101e51891
commit
85531f0285
|
@ -21,10 +21,13 @@ archivesBaseName = 'x-pack-sql'
|
|||
integTest.enabled = false
|
||||
|
||||
task internalClusterTest(type: RandomizedTestingTask,
|
||||
group: JavaBasePlugin.VERIFICATION_GROUP
|
||||
) {
|
||||
group: JavaBasePlugin.VERIFICATION_GROUP,
|
||||
dependsOn: unitTest.dependsOn) {
|
||||
include '**/*IT.class'
|
||||
systemProperty 'es.set.netty.runtime.available.processors', 'false'
|
||||
}
|
||||
check.dependsOn internalClusterTest
|
||||
internalClusterTest.mustRunAfter test
|
||||
|
||||
dependencies {
|
||||
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here
|
||||
|
|
|
@ -50,17 +50,9 @@ import static java.util.Collections.emptyList;
|
|||
public class SqlPlugin extends Plugin implements ActionPlugin {
|
||||
|
||||
private final boolean enabled;
|
||||
private final SqlLicenseChecker sqlLicenseChecker;
|
||||
|
||||
SqlPlugin(boolean enabled, SqlLicenseChecker sqlLicenseChecker) {
|
||||
this.enabled = enabled;
|
||||
this.sqlLicenseChecker = sqlLicenseChecker;
|
||||
}
|
||||
|
||||
public SqlPlugin(Settings settings) {
|
||||
this(XPackSettings.SQL_ENABLED.get(settings), new SqlLicenseChecker(
|
||||
private final SqlLicenseChecker sqlLicenseChecker = new SqlLicenseChecker(
|
||||
(mode) -> {
|
||||
XPackLicenseState licenseState = XPackPlugin.getSharedLicenseState();
|
||||
XPackLicenseState licenseState = getLicenseState();
|
||||
switch (mode) {
|
||||
case JDBC:
|
||||
if (licenseState.isJdbcAllowed() == false) {
|
||||
|
@ -81,9 +73,15 @@ public class SqlPlugin extends Plugin implements ActionPlugin {
|
|||
throw new IllegalArgumentException("Unknown SQL mode " + mode);
|
||||
}
|
||||
}
|
||||
));
|
||||
);
|
||||
|
||||
public SqlPlugin(Settings settings) {
|
||||
this.enabled = XPackSettings.SQL_ENABLED.get(settings);
|
||||
}
|
||||
|
||||
// overridable by tests
|
||||
protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }
|
||||
|
||||
@Override
|
||||
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
|
||||
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
|
||||
|
|
|
@ -5,25 +5,20 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.action;
|
||||
|
||||
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.reindex.ReindexPlugin;
|
||||
import org.elasticsearch.license.LicenseService;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.discovery.TestZenDiscovery;
|
||||
import org.elasticsearch.xpack.core.XPackPlugin;
|
||||
import org.elasticsearch.xpack.core.XPackSettings;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
|
||||
|
||||
@ESIntegTestCase.ClusterScope(scope = SUITE, numDataNodes = 0, numClientNodes = 0, maxNumDataNodes = 0, transportClientRatio = 0)
|
||||
public abstract class AbstractSqlIntegTestCase extends ESIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected boolean ignoreExternalCluster() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
Settings.Builder settings = Settings.builder().put(super.nodeSettings(nodeOrdinal));
|
||||
|
@ -32,29 +27,18 @@ public abstract class AbstractSqlIntegTestCase extends ESIntegTestCase {
|
|||
settings.put(XPackSettings.WATCHER_ENABLED.getKey(), false);
|
||||
settings.put(XPackSettings.GRAPH_ENABLED.getKey(), false);
|
||||
settings.put(XPackSettings.MACHINE_LEARNING_ENABLED.getKey(), false);
|
||||
settings.put("xpack.ml.autodetect_process", false);
|
||||
settings.put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), "trial");
|
||||
return settings.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Arrays.asList(XPackPlugin.class, CommonAnalysisPlugin.class, ReindexPlugin.class);
|
||||
return Collections.singletonList(LocalStateSQLXPackPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
|
||||
return nodePlugins();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings transportClientSettings() {
|
||||
// Plugin should be loaded on the transport client as well
|
||||
return nodeSettings(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> getMockPlugins() {
|
||||
return Arrays.asList(TestZenDiscovery.TestPlugin.class, TestSeedPlugin.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.sql.action;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
|
||||
import org.elasticsearch.xpack.sql.plugin.SqlPlugin;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LocalStateSQLXPackPlugin extends LocalStateCompositeXPackPlugin {
|
||||
|
||||
public LocalStateSQLXPackPlugin(final Settings settings, final Path configPath) throws Exception {
|
||||
super(settings, configPath);
|
||||
LocalStateSQLXPackPlugin thisVar = this;
|
||||
plugins.add(new SqlPlugin(settings) {
|
||||
@Override
|
||||
protected XPackLicenseState getLicenseState() {
|
||||
return thisVar.getLicenseState();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -18,12 +18,11 @@ import static org.hamcrest.Matchers.hasSize;
|
|||
|
||||
public class SqlActionIT extends AbstractSqlIntegTestCase {
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37191")
|
||||
public void testSqlAction() throws Exception {
|
||||
public void testSqlAction() {
|
||||
assertAcked(client().admin().indices().prepareCreate("test").get());
|
||||
client().prepareBulk()
|
||||
.add(new IndexRequest("test", "doc", "1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test", "doc", "2").source("data", "baz", "count", 43))
|
||||
.add(new IndexRequest("test").id("1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test").id("2").source("data", "baz", "count", 43))
|
||||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
||||
.get();
|
||||
ensureYellow("test");
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.sql.action;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.support.WriteRequest;
|
||||
|
@ -17,16 +16,15 @@ import static org.hamcrest.Matchers.greaterThan;
|
|||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37191")
|
||||
public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase {
|
||||
|
||||
public void testSqlClearCursorAction() throws Exception {
|
||||
public void testSqlClearCursorAction() {
|
||||
assertAcked(client().admin().indices().prepareCreate("test").get());
|
||||
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
|
||||
int indexSize = randomIntBetween(100, 300);
|
||||
logger.info("Indexing {} records", indexSize);
|
||||
for (int i = 0; i < indexSize; i++) {
|
||||
bulkRequestBuilder.add(new IndexRequest("test", "doc", "id" + i).source("data", "bar", "count", i));
|
||||
bulkRequestBuilder.add(new IndexRequest("test").id("id" + i).source("data", "bar", "count", i));
|
||||
}
|
||||
bulkRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
ensureYellow("test");
|
||||
|
@ -50,13 +48,13 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase {
|
|||
assertEquals(0, getNumberOfSearchContexts());
|
||||
}
|
||||
|
||||
public void testAutoCursorCleanup() throws Exception {
|
||||
public void testAutoCursorCleanup() {
|
||||
assertAcked(client().admin().indices().prepareCreate("test").get());
|
||||
BulkRequestBuilder bulkRequestBuilder = client().prepareBulk();
|
||||
int indexSize = randomIntBetween(100, 300);
|
||||
logger.info("Indexing {} records", indexSize);
|
||||
for (int i = 0; i < indexSize; i++) {
|
||||
bulkRequestBuilder.add(new IndexRequest("test", "doc", "id" + i).source("data", "bar", "count", i));
|
||||
bulkRequestBuilder.add(new IndexRequest("test").id("id" + i).source("data", "bar", "count", i));
|
||||
}
|
||||
bulkRequestBuilder.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
|
||||
ensureYellow("test");
|
||||
|
@ -77,7 +75,7 @@ public class SqlClearCursorActionIT extends AbstractSqlIntegTestCase {
|
|||
do {
|
||||
sqlQueryResponse = new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).cursor(sqlQueryResponse.cursor()).get();
|
||||
fetched += sqlQueryResponse.size();
|
||||
} while (sqlQueryResponse.cursor().equals("") == false);
|
||||
} while (sqlQueryResponse.cursor().isEmpty() == false);
|
||||
assertEquals(indexSize, fetched);
|
||||
|
||||
SqlClearCursorResponse cleanCursorResponse = new SqlClearCursorRequestBuilder(client(), SqlClearCursorAction.INSTANCE)
|
||||
|
|
|
@ -6,13 +6,23 @@
|
|||
package org.elasticsearch.xpack.sql.action;
|
||||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.xpack.core.XPackPlugin;
|
||||
import org.elasticsearch.xpack.core.XPackSettings;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.either;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
|
||||
public class SqlDisabledIT extends AbstractSqlIntegTestCase {
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singletonList(XPackPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Settings nodeSettings(int nodeOrdinal) {
|
||||
return Settings.builder()
|
||||
|
@ -29,8 +39,7 @@ public class SqlDisabledIT extends AbstractSqlIntegTestCase {
|
|||
.build();
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37191")
|
||||
public void testSqlAction() throws Exception {
|
||||
public void testSqlAction() {
|
||||
Throwable throwable = expectThrows(Throwable.class,
|
||||
() -> new SqlQueryRequestBuilder(client(), SqlQueryAction.INSTANCE).query("SHOW tables").get());
|
||||
assertThat(throwable.getMessage(),
|
||||
|
|
|
@ -35,7 +35,7 @@ import static org.elasticsearch.license.XPackLicenseStateTests.randomTrialBasicS
|
|||
import static org.elasticsearch.license.XPackLicenseStateTests.randomTrialOrPlatinumMode;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37191")
|
||||
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37320")
|
||||
public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase {
|
||||
@Override
|
||||
protected boolean ignoreExternalCluster() {
|
||||
|
@ -164,8 +164,8 @@ public class SqlLicenseIT extends AbstractLicensesIntegrationTestCase {
|
|||
private void setupTestIndex() {
|
||||
ElasticsearchAssertions.assertAcked(client().admin().indices().prepareCreate("test").get());
|
||||
client().prepareBulk()
|
||||
.add(new IndexRequest("test", "doc", "1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test", "doc", "2").source("data", "baz", "count", 43))
|
||||
.add(new IndexRequest("test").id("1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test").id("2").source("data", "baz", "count", 43))
|
||||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
||||
.get();
|
||||
}
|
||||
|
|
|
@ -17,12 +17,11 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
|||
|
||||
public class SqlTranslateActionIT extends AbstractSqlIntegTestCase {
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37191")
|
||||
public void testSqlTranslateAction() throws Exception {
|
||||
public void testSqlTranslateAction() {
|
||||
assertAcked(client().admin().indices().prepareCreate("test").get());
|
||||
client().prepareBulk()
|
||||
.add(new IndexRequest("test", "doc", "1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test", "doc", "2").source("data", "baz", "count", 43))
|
||||
.add(new IndexRequest("test").id("1").source("data", "bar", "count", 42))
|
||||
.add(new IndexRequest("test").id("2").source("data", "baz", "count", 43))
|
||||
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
||||
.get();
|
||||
ensureYellow("test");
|
||||
|
@ -33,11 +32,11 @@ public class SqlTranslateActionIT extends AbstractSqlIntegTestCase {
|
|||
.query("SELECT " + columns + " FROM test ORDER BY count").get();
|
||||
SearchSourceBuilder source = response.source();
|
||||
FetchSourceContext fetch = source.fetchSource();
|
||||
assertEquals(true, fetch.fetchSource());
|
||||
assertTrue(fetch.fetchSource());
|
||||
assertArrayEquals(new String[] { "data" }, fetch.includes());
|
||||
assertEquals(
|
||||
singletonList(new DocValueFieldsContext.FieldAndFormat("count", DocValueFieldsContext.USE_DEFAULT_FORMAT)),
|
||||
source.docValueFields());
|
||||
assertEquals(singletonList(SortBuilders.fieldSort("count")), source.sorts());
|
||||
assertEquals(singletonList(SortBuilders.fieldSort("count").missing("_last").unmappedType("long")), source.sorts());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ import static org.mockito.Mockito.mock;
|
|||
public class SqlPluginTests extends ESTestCase {
|
||||
|
||||
public void testSqlDisabled() {
|
||||
SqlPlugin plugin = new SqlPlugin(false, new SqlLicenseChecker((mode) -> {}));
|
||||
Settings settings = Settings.builder().put("xpack.sql.enabled", false).build();
|
||||
SqlPlugin plugin = new SqlPlugin(settings);
|
||||
assertThat(plugin.createComponents(mock(Client.class), "cluster", new NamedWriteableRegistry(Cursors.getNamedWriteables())),
|
||||
empty());
|
||||
assertThat(plugin.getActions(), empty());
|
||||
|
@ -34,5 +35,4 @@ public class SqlPluginTests extends ESTestCase {
|
|||
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, new SettingsFilter(Collections.emptyList()),
|
||||
mock(IndexNameExpressionResolver.class), () -> mock(DiscoveryNodes.class)), empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue