Several internal improvements to internal test cluster infra (#26214)
This chance adds several random test infrastructure improvements that caused issues in on-going developments but are generally useful. For instance is it impossible to restart a node with a secure setting source since we close it after the node is started. This change makes it cloneable such that we can reuse it for a restart.
This commit is contained in:
parent
93edbc0030
commit
a9169e536b
|
@ -235,7 +235,7 @@ public abstract class TransportClient extends AbstractClient {
|
|||
public static final String CLIENT_TYPE = "transport";
|
||||
|
||||
final Injector injector;
|
||||
final NamedWriteableRegistry namedWriteableRegistry;
|
||||
protected final NamedWriteableRegistry namedWriteableRegistry;
|
||||
|
||||
private final List<LifecycleComponent> pluginLifecycleComponents;
|
||||
private final TransportClientNodesService nodesService;
|
||||
|
|
|
@ -38,6 +38,15 @@ public class MockSecureSettings implements SecureSettings {
|
|||
private Set<String> settingNames = new HashSet<>();
|
||||
private final AtomicBoolean closed = new AtomicBoolean(false);
|
||||
|
||||
public MockSecureSettings() {
|
||||
}
|
||||
|
||||
private MockSecureSettings(MockSecureSettings source) {
|
||||
secureStrings.putAll(source.secureStrings);
|
||||
files.putAll(source.files);
|
||||
settingNames.addAll(source.settingNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded() {
|
||||
return true;
|
||||
|
@ -94,4 +103,9 @@ public class MockSecureSettings implements SecureSettings {
|
|||
throw new IllegalStateException("secure settings are already closed");
|
||||
}
|
||||
}
|
||||
|
||||
public SecureSettings clone() {
|
||||
ensureOpen();
|
||||
return new MockSecureSettings(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1084,14 +1084,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
*/
|
||||
protected void ensureClusterStateConsistency() throws IOException {
|
||||
if (cluster() != null && cluster().size() > 0) {
|
||||
final NamedWriteableRegistry namedWriteableRegistry;
|
||||
if (isInternalCluster()) {
|
||||
// If it's internal cluster - using existing registry in case plugin registered custom data
|
||||
namedWriteableRegistry = internalCluster().getInstance(NamedWriteableRegistry.class);
|
||||
} else {
|
||||
// If it's external cluster - fall back to the standard set
|
||||
namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
|
||||
}
|
||||
final NamedWriteableRegistry namedWriteableRegistry = cluster().getNamedWriteableRegistry();
|
||||
ClusterState masterClusterState = client().admin().cluster().prepareState().all().get().getState();
|
||||
byte[] masterClusterStateBytes = ClusterState.Builder.toBytes(masterClusterState);
|
||||
// remove local node reference
|
||||
|
@ -2192,9 +2185,13 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
}
|
||||
|
||||
protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
|
||||
final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
|
||||
final List<NodeInfo> nodes = nodeInfos.getNodes();
|
||||
assertFalse(nodeInfos.hasFailures());
|
||||
NodesInfoResponse nodesInfoResponse = client().admin().cluster().prepareNodesInfo().get();
|
||||
assertFalse(nodesInfoResponse.hasFailures());
|
||||
return createRestClient(nodesInfoResponse.getNodes(), httpClientConfigCallback, protocol);
|
||||
}
|
||||
|
||||
protected static RestClient createRestClient(final List<NodeInfo> nodes,
|
||||
RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
|
||||
List<HttpHost> hosts = new ArrayList<>();
|
||||
for (NodeInfo node : nodes) {
|
||||
if (node.getHttp() != null) {
|
||||
|
|
|
@ -28,6 +28,7 @@ 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.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -62,7 +63,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
private static final AtomicInteger counter = new AtomicInteger();
|
||||
public static final String EXTERNAL_CLUSTER_PREFIX = "external_";
|
||||
|
||||
private final Client client;
|
||||
private final MockTransportClient client;
|
||||
|
||||
private final InetSocketAddress[] httpAddresses;
|
||||
|
||||
|
@ -95,8 +96,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
}
|
||||
}
|
||||
Settings clientSettings = clientSettingsBuilder.build();
|
||||
TransportClient client = new MockTransportClient(clientSettings, pluginClasses);
|
||||
|
||||
MockTransportClient client = new MockTransportClient(clientSettings, pluginClasses);
|
||||
try {
|
||||
client.addTransportAddresses(transportAddresses);
|
||||
NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
|
||||
|
@ -117,6 +117,7 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
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();
|
||||
|
@ -186,6 +187,11 @@ public final class ExternalTestCluster extends TestCluster {
|
|||
return Collections.singleton(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||
return client.getNamedWriteableRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
|
|
|
@ -51,9 +51,11 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.breaker.CircuitBreaker;
|
||||
import org.elasticsearch.common.io.FileSystemUtils;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.lease.Releasables;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.MockSecureSettings;
|
||||
import org.elasticsearch.common.settings.SecureSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings.Builder;
|
||||
|
@ -610,6 +612,10 @@ public final class InternalTestCluster extends TestCluster {
|
|||
throw new IllegalArgumentException(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey() + " must be configured");
|
||||
}
|
||||
SecureSettings secureSettings = finalSettings.getSecureSettings();
|
||||
if (secureSettings instanceof MockSecureSettings) {
|
||||
// we clone this here since in the case of a node restart we might need it again
|
||||
secureSettings = ((MockSecureSettings) secureSettings).clone();
|
||||
}
|
||||
MockNode node = new MockNode(finalSettings.build(), plugins, nodeConfigurationSource.nodeConfigPath(nodeId));
|
||||
try {
|
||||
IOUtils.close(secureSettings);
|
||||
|
@ -1964,6 +1970,11 @@ public final class InternalTestCluster extends TestCluster {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||
return getInstance(NamedWriteableRegistry.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a predicate that only accepts settings of nodes with one of the given names.
|
||||
*/
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp
|
|||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.indices.IndexTemplateMissingException;
|
||||
|
@ -34,6 +35,7 @@ import org.elasticsearch.repositories.RepositoryMissingException;
|
|||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -233,5 +235,9 @@ public abstract class TestCluster implements Closeable {
|
|||
*/
|
||||
public abstract Iterable<Client> getClients();
|
||||
|
||||
|
||||
/**
|
||||
* Returns this clusters {@link NamedWriteableRegistry} this is needed to
|
||||
* deserialize binary content from this cluster that might include custom named writeables
|
||||
*/
|
||||
public abstract NamedWriteableRegistry getNamedWriteableRegistry();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.elasticsearch.transport;
|
||||
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
|
@ -69,4 +70,8 @@ public class MockTransportClient extends TransportClient {
|
|||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
public NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||
return namedWriteableRegistry;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue