Followup for elastic/elasticsearchelastic/elasticsearch#21915 - removal of legacy BWC test infrastructure (elastic/elasticsearch#4247)
Original commit: elastic/x-pack-elasticsearch@07cecdbf00
This commit is contained in:
parent
417ccdd7cc
commit
ace1a7e6af
|
@ -48,11 +48,6 @@ public abstract class AbstractOldXPackIndicesBackwardsCompatibilityTestCase exte
|
|||
private boolean okToStartNode = false;
|
||||
private List<String> 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.
|
||||
|
|
|
@ -21,11 +21,6 @@ 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;
|
||||
|
|
|
@ -82,11 +82,6 @@ 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();
|
||||
|
|
|
@ -129,11 +129,6 @@ 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<String,String> asMap = new HashMap<>(cluster2SettingsSource.nodeSettings(0).getAsMap());
|
||||
|
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* 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<Class<? extends Plugin>> 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<Client> getClients() {
|
||||
return Collections.singleton(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
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;
|
||||
|
@ -26,16 +27,16 @@ import java.util.Collections;
|
|||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class LicensingTribeIT extends ESIntegTestCase {
|
||||
public class LicensingTribeIT extends ESTestCase {
|
||||
//TODO cut this one over to use a REST client
|
||||
private static TestCluster cluster1;
|
||||
private static TestCluster cluster2;
|
||||
private static TestCluster tribeNode;
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return Collections.singletonList(XPackPlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
|
||||
return nodePlugins();
|
||||
}
|
||||
|
@ -43,6 +44,9 @@ public class LicensingTribeIT extends ESIntegTestCase {
|
|||
@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"));
|
||||
}
|
||||
|
@ -54,24 +58,16 @@ public class LicensingTribeIT extends ESIntegTestCase {
|
|||
|
||||
@AfterClass
|
||||
public static void tearDownExternalClusters() throws IOException {
|
||||
if (cluster2 != null) {
|
||||
try {
|
||||
cluster2.close();
|
||||
} finally {
|
||||
cluster2 = null;
|
||||
}
|
||||
}
|
||||
if (tribeNode != null) {
|
||||
try {
|
||||
tribeNode.close();
|
||||
} finally {
|
||||
tribeNode = null;
|
||||
}
|
||||
try {
|
||||
IOUtils.close(cluster1, cluster2, tribeNode);
|
||||
} finally {
|
||||
cluster1 = null;
|
||||
cluster2 = null;
|
||||
tribeNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Settings externalClusterClientSettings() {
|
||||
Settings.Builder builder = Settings.builder();
|
||||
builder.put(XPackSettings.SECURITY_ENABLED.getKey(), false);
|
||||
|
@ -81,7 +77,7 @@ public class LicensingTribeIT extends ESIntegTestCase {
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
private ExternalTestCluster buildExternalCluster(String clusterAddresses) throws IOException {
|
||||
private TestCluster buildExternalCluster(String clusterAddresses) throws IOException {
|
||||
String[] stringAddresses = clusterAddresses.split(",");
|
||||
TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length];
|
||||
int i = 0;
|
||||
|
@ -102,7 +98,7 @@ public class LicensingTribeIT extends ESIntegTestCase {
|
|||
});
|
||||
|
||||
// test that signed license put in one cluster propagates to tribe
|
||||
LicensingClient cluster1Client = new LicensingClient(client());
|
||||
LicensingClient cluster1Client = new LicensingClient(cluster1.client());
|
||||
PutLicenseResponse licenseResponse = cluster1Client.preparePutLicense(License.fromSource(BASIC_LICENSE))
|
||||
.setAcknowledge(true).get();
|
||||
assertThat(licenseResponse.isAcknowledged(), equalTo(true));
|
||||
|
|
Loading…
Reference in New Issue