diff --git a/elasticsearch/src/test/java/org/elasticsearch/AbstractOldXPackIndicesBackwardsCompatibilityTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/AbstractOldXPackIndicesBackwardsCompatibilityTestCase.java index c482e5997ba..33405a4c1ea 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/AbstractOldXPackIndicesBackwardsCompatibilityTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/AbstractOldXPackIndicesBackwardsCompatibilityTestCase.java @@ -48,6 +48,11 @@ public abstract class AbstractOldXPackIndicesBackwardsCompatibilityTestCase exte private boolean okToStartNode = false; private List dataFiles; + @Override + protected final boolean ignoreExternalCluster() { + return true; + } + @Override protected boolean shouldAssertXPackIsInstalled() { return false; // Skip asserting that the xpack is installed because it tries to start the cluter. diff --git a/elasticsearch/src/test/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java b/elasticsearch/src/test/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java index 8dda6570efc..e8db61c2975 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/integration/ShrinkIndexWithSecurityTests.java @@ -21,6 +21,11 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC @ClusterScope(minNumDataNodes = 2) public class ShrinkIndexWithSecurityTests extends SecurityIntegTestCase { + @Override + protected final boolean ignoreExternalCluster() { + return true; + } + @Override protected int minimumNumberOfShards() { return 2; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java index f41e48e5ca7..f6d30ac3342 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterIT.java @@ -82,6 +82,11 @@ public class HttpExporterIT extends MonitoringIntegTestCase { webServer.shutdown(); } + @Override + protected boolean ignoreExternalCluster() { + return true; + } + public void testExport() throws Exception { final boolean templatesExistsAlready = randomBoolean(); final boolean pipelineExistsAlready = randomBoolean(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java index ad5791f8326..071ea9039fb 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/security/SecurityTribeIT.java @@ -129,6 +129,11 @@ public class SecurityTribeIT extends NativeRealmIntegTestCase { return useSSL; } + @Override + protected boolean ignoreExternalCluster() { + return true; + } + private void setupTribeNode(Settings settings) throws NodeValidationException, InterruptedException { SecuritySettingsSource cluster2SettingsSource = new SecuritySettingsSource(1, useSSL, systemKey(), createTempDir(), Scope.TEST); Map asMap = new HashMap<>(cluster2SettingsSource.nodeSettings(0).getAsMap()); diff --git a/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/ExternalTestCluster.java b/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/ExternalTestCluster.java deleted file mode 100644 index ee45a856ba1..00000000000 --- a/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/ExternalTestCluster.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.test; - -import org.apache.logging.log4j.Logger; -import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; -import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; -import org.elasticsearch.client.Client; -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.common.breaker.CircuitBreaker; -import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkModule; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.env.Environment; -import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.transport.MockTcpTransportPlugin; -import org.elasticsearch.transport.MockTransportClient; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - -/** - * External cluster to run the tests against. - * It is a pure immutable test cluster that allows to send requests to a pre-existing cluster - * and supports by nature all the needed test operations like wipeIndices etc. - */ -final class ExternalTestCluster extends TestCluster { - - private static final Logger logger = Loggers.getLogger(ExternalTestCluster.class); - - private static final AtomicInteger counter = new AtomicInteger(); - public static final String EXTERNAL_CLUSTER_PREFIX = "external_"; - - private final Client client; - - private final InetSocketAddress[] httpAddresses; - - private final String clusterName; - - private final int numDataNodes; - private final int numMasterAndDataNodes; - - public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection> pluginClasses, - TransportAddress... transportAddresses) { - super(0); - Settings.Builder clientSettingsBuilder = Settings.builder() - .put(additionalSettings) - .put("node.name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement()) - .put("client.transport.ignore_cluster_name", true) - .put(Environment.PATH_HOME_SETTING.getKey(), tempDir); - boolean addMockTcpTransport = additionalSettings.get(NetworkModule.TRANSPORT_TYPE_KEY) == null; - - if (addMockTcpTransport) { - clientSettingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME); - if (pluginClasses.contains(MockTcpTransportPlugin.class) == false) { - pluginClasses = new ArrayList<>(pluginClasses); - pluginClasses.add(MockTcpTransportPlugin.class); - } - } - Settings clientSettings = clientSettingsBuilder.build(); - TransportClient client = new MockTransportClient(clientSettings, pluginClasses); - - try { - client.addTransportAddresses(transportAddresses); - NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get(); - httpAddresses = new InetSocketAddress[nodeInfos.getNodes().size()]; - this.clusterName = nodeInfos.getClusterName().value(); - int dataNodes = 0; - int masterAndDataNodes = 0; - for (int i = 0; i < nodeInfos.getNodes().size(); i++) { - NodeInfo nodeInfo = nodeInfos.getNodes().get(i); - httpAddresses[i] = nodeInfo.getHttp().address().publishAddress().address(); - if (DiscoveryNode.isDataNode(nodeInfo.getSettings())) { - dataNodes++; - masterAndDataNodes++; - } else if (DiscoveryNode.isMasterNode(nodeInfo.getSettings())) { - masterAndDataNodes++; - } - } - this.numDataNodes = dataNodes; - this.numMasterAndDataNodes = masterAndDataNodes; - this.client = client; - logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size()); - } catch (Exception e) { - client.close(); - throw e; - } - } - - @Override - public void afterTest() { - - } - - @Override - public Client client() { - return client; - } - - @Override - public int size() { - return httpAddresses.length; - } - - @Override - public int numDataNodes() { - return numDataNodes; - } - - @Override - public int numDataAndMasterNodes() { - return numMasterAndDataNodes; - } - - @Override - public InetSocketAddress[] httpAddresses() { - return httpAddresses; - } - - @Override - public void close() throws IOException { - client.close(); - } - - @Override - public void ensureEstimatedStats() { - if (size() > 0) { - NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats() - .clear().setBreaker(true).setIndices(true).execute().actionGet(); - for (NodeStats stats : nodeStats.getNodes()) { - assertThat("Fielddata breaker not reset to 0 on node: " + stats.getNode(), - stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated(), equalTo(0L)); - // ExternalTestCluster does not check the request breaker, - // because checking it requires a network request, which in - // turn increments the breaker, making it non-0 - - assertThat("Fielddata size must be 0 on node: " + stats.getNode(), - stats.getIndices().getFieldData().getMemorySizeInBytes(), equalTo(0L)); - assertThat("Query cache size must be 0 on node: " + stats.getNode(), - stats.getIndices().getQueryCache().getMemorySizeInBytes(), equalTo(0L)); - assertThat("FixedBitSet cache size must be 0 on node: " + stats.getNode(), - stats.getIndices().getSegments().getBitsetMemoryInBytes(), equalTo(0L)); - } - } - } - - @Override - public Iterable getClients() { - return Collections.singleton(client); - } - - @Override - public String getClusterName() { - return clusterName; - } -} \ No newline at end of file diff --git a/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/LicensingTribeIT.java b/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/LicensingTribeIT.java index 7f83556b5ed..76baa8b8f18 100644 --- a/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/LicensingTribeIT.java +++ b/qa/tribe-tests-with-license/src/test/java/org/elasticsearch/test/LicensingTribeIT.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.test; -import org.apache.lucene.util.IOUtils; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.license.GetLicenseResponse; @@ -27,16 +26,16 @@ import java.util.Collections; import static org.hamcrest.CoreMatchers.equalTo; -public class LicensingTribeIT extends ESTestCase { - //TODO cut this one over to use a REST client - private static TestCluster cluster1; +public class LicensingTribeIT extends ESIntegTestCase { private static TestCluster cluster2; private static TestCluster tribeNode; + @Override protected Collection> nodePlugins() { return Collections.singletonList(XPackPlugin.class); } + @Override protected Collection> transportClientPlugins() { return nodePlugins(); } @@ -44,9 +43,6 @@ public class LicensingTribeIT extends ESTestCase { @Override public void setUp() throws Exception { super.setUp(); - if (cluster1 == null) { - cluster1 = buildExternalCluster(System.getProperty("tests.cluster")); - } if (cluster2 == null) { cluster2 = buildExternalCluster(System.getProperty("tests.cluster2")); } @@ -58,16 +54,24 @@ public class LicensingTribeIT extends ESTestCase { @AfterClass public static void tearDownExternalClusters() throws IOException { - try { - IOUtils.close(cluster1, cluster2, tribeNode); - } finally { - cluster1 = null; - cluster2 = null; - tribeNode = null; + if (cluster2 != null) { + try { + cluster2.close(); + } finally { + cluster2 = null; + } + } + if (tribeNode != null) { + try { + tribeNode.close(); + } finally { + tribeNode = null; + } } } + @Override protected Settings externalClusterClientSettings() { Settings.Builder builder = Settings.builder(); builder.put(XPackSettings.SECURITY_ENABLED.getKey(), false); @@ -77,7 +81,7 @@ public class LicensingTribeIT extends ESTestCase { return builder.build(); } - private TestCluster buildExternalCluster(String clusterAddresses) throws IOException { + private ExternalTestCluster buildExternalCluster(String clusterAddresses) throws IOException { String[] stringAddresses = clusterAddresses.split(","); TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length]; int i = 0; @@ -98,7 +102,7 @@ public class LicensingTribeIT extends ESTestCase { }); // test that signed license put in one cluster propagates to tribe - LicensingClient cluster1Client = new LicensingClient(cluster1.client()); + LicensingClient cluster1Client = new LicensingClient(client()); PutLicenseResponse licenseResponse = cluster1Client.preparePutLicense(License.fromSource(BASIC_LICENSE)) .setAcknowledge(true).get(); assertThat(licenseResponse.isAcknowledged(), equalTo(true));