mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-19 04:45:07 -04:00
[TEST] Migrated REST tests extending JsonLogsIntegTestCase (#115188)
REST tests extending JsonLogsIntegTestCase migrated to the new REST testing framework, using 'elasticsearch.internal-java-rest-test' Gradle plugin Explicit handling of test single-cluster config by checking if cluster is explicitly configured as single-node to avoid an incorrect configuration which may cause split brain. Replaced `ElasticsearchJavaPlugin` with `ElasticsearchJavaBasePlugin` in `RestTestBasePlugin` for better granularity. Additionally, updated the `DistributionDownloadPlugin` to set configurations as non-consumable and the `InternalDistributionArchiveSetupPlugin` to mark certain configurations as consumable. This ensures that configurations are correctly utilized during build setup and execution phases.
This commit is contained in:
parent
4ee98e80b2
commit
130cc74d8a
27 changed files with 236 additions and 219 deletions
|
@ -76,12 +76,14 @@ public class InternalDistributionArchiveSetupPlugin implements Plugin<Project> {
|
|||
sub.getArtifacts().add(DEFAULT_CONFIGURATION_NAME, distributionArchive.getArchiveTask());
|
||||
var extractedConfiguration = sub.getConfigurations().create(EXTRACTED_CONFIGURATION_NAME);
|
||||
extractedConfiguration.setCanBeResolved(false);
|
||||
extractedConfiguration.setCanBeConsumed(true);
|
||||
extractedConfiguration.getAttributes()
|
||||
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
|
||||
sub.getArtifacts().add(EXTRACTED_CONFIGURATION_NAME, distributionArchive.getExpandedDistTask());
|
||||
// The "composite" configuration is specifically used for resolving transformed artifacts in an included build
|
||||
var compositeConfiguration = sub.getConfigurations().create(COMPOSITE_CONFIGURATION_NAME);
|
||||
compositeConfiguration.setCanBeResolved(false);
|
||||
compositeConfiguration.setCanBeConsumed(true);
|
||||
compositeConfiguration.getAttributes()
|
||||
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
|
||||
compositeConfiguration.getAttributes().attribute(Attribute.of("composite", Boolean.class), true);
|
||||
|
|
|
@ -53,8 +53,6 @@ public abstract class RestrictedBuildApiService implements BuildService<Restrict
|
|||
map.put(LegacyRestTestBasePlugin.class, ":plugins:repository-hdfs");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":plugins:store-smb");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:ccs-rolling-upgrade-remote-cluster");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:ccs-unavailable-clusters");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:logging-config");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:mixed-cluster");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:multi-cluster-search");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:remote-clusters");
|
||||
|
@ -65,7 +63,6 @@ public abstract class RestrictedBuildApiService implements BuildService<Restrict
|
|||
map.put(LegacyRestTestBasePlugin.class, ":qa:smoke-test-ingest-with-all-dependencies");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:smoke-test-plugins");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:system-indices");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:unconfigured-node-name");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":qa:verify-version-constants");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":test:external-modules:test-apm-integration");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":test:external-modules:test-delayed-aggs");
|
||||
|
@ -73,7 +70,6 @@ public abstract class RestrictedBuildApiService implements BuildService<Restrict
|
|||
map.put(LegacyRestTestBasePlugin.class, ":test:external-modules:test-error-query");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":test:external-modules:test-latency-simulating-directory");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":test:yaml-rest-runner");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":distribution:archives:integ-test-zip");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:core");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ent-search");
|
||||
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:fleet");
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.elasticsearch.gradle.ElasticsearchDistributionType;
|
|||
import org.elasticsearch.gradle.Version;
|
||||
import org.elasticsearch.gradle.VersionProperties;
|
||||
import org.elasticsearch.gradle.distribution.ElasticsearchDistributionTypes;
|
||||
import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin;
|
||||
import org.elasticsearch.gradle.internal.ElasticsearchJavaBasePlugin;
|
||||
import org.elasticsearch.gradle.internal.InternalDistributionDownloadPlugin;
|
||||
import org.elasticsearch.gradle.internal.info.BuildParams;
|
||||
import org.elasticsearch.gradle.internal.test.ErrorReportingTestListener;
|
||||
|
@ -90,7 +90,7 @@ public class RestTestBasePlugin implements Plugin<Project> {
|
|||
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
project.getPluginManager().apply(ElasticsearchJavaPlugin.class);
|
||||
project.getPluginManager().apply(ElasticsearchJavaBasePlugin.class);
|
||||
project.getPluginManager().apply(InternalDistributionDownloadPlugin.class);
|
||||
|
||||
// Register integ-test and default distributions
|
||||
|
|
|
@ -89,7 +89,9 @@ public class DistributionDownloadPlugin implements Plugin<Project> {
|
|||
private void setupDistributionContainer(Project project) {
|
||||
distributionsContainer = project.container(ElasticsearchDistribution.class, name -> {
|
||||
var fileConfiguration = project.getConfigurations().create(DISTRO_CONFIG_PREFIX + name);
|
||||
fileConfiguration.setCanBeConsumed(false);
|
||||
var extractedConfiguration = project.getConfigurations().create(DISTRO_EXTRACTED_CONFIG_PREFIX + name);
|
||||
extractedConfiguration.setCanBeConsumed(false);
|
||||
extractedConfiguration.getAttributes()
|
||||
.attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.DIRECTORY_TYPE);
|
||||
var distribution = new ElasticsearchDistribution(
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
apply plugin: 'elasticsearch.legacy-java-rest-test'
|
||||
apply plugin: 'elasticsearch.internal-java-rest-test'
|
||||
|
||||
// The integ-test-distribution is published to maven
|
||||
apply plugin: 'elasticsearch.publish'
|
||||
|
@ -35,19 +35,3 @@ publishing {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("javaRestTest").configure {
|
||||
dependsOn "assemble"
|
||||
/*
|
||||
* There are two unique things going on here:
|
||||
* 1. These tests can be run against an external cluster with
|
||||
* -Dtests.rest.cluster=whatever and -Dtest.cluster=whatever
|
||||
* 2. *One* of these tests is incompatible with that and should be skipped
|
||||
* when running against an external cluster.
|
||||
*/
|
||||
if (project.providers.systemProperty("tests.rest.cluster").isPresent()) {
|
||||
nonInputProperties.systemProperty 'tests.logfile', testClusters.named('javaRestTest').map(c -> c.singleNode().serverLog)
|
||||
} else {
|
||||
systemProperty 'tests.logfile', '--external--'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,8 @@ package org.elasticsearch.test.rest;
|
|||
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -23,6 +25,14 @@ import static org.hamcrest.Matchers.startsWith;
|
|||
*/
|
||||
public class CreatedLocationHeaderIT extends ESRestTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
public void testCreate() throws IOException {
|
||||
locationTestCase("PUT", "test/_doc/1");
|
||||
}
|
||||
|
|
|
@ -10,36 +10,36 @@
|
|||
package org.elasticsearch.test.rest;
|
||||
|
||||
import org.elasticsearch.common.logging.JsonLogsIntegTestCase;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.elasticsearch.test.cluster.LogType;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class JsonLogsFormatAndParseIT extends JsonLogsIntegTestCase {
|
||||
|
||||
private static final String NODE_NAME = "test-node-0";
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
|
||||
.withNode(localNodeSpecBuilder -> localNodeSpecBuilder.name(NODE_NAME))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected Matcher<String> nodeNameMatcher() {
|
||||
return is("integTest-0");
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BufferedReader openReader(Path logFile) {
|
||||
assumeFalse(
|
||||
"Skipping test because it is being run against an external cluster.",
|
||||
logFile.getFileName().toString().equals("--external--")
|
||||
);
|
||||
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> {
|
||||
try {
|
||||
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
protected Matcher<String> nodeNameMatcher() {
|
||||
return is(NODE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream openLogsStream() {
|
||||
return cluster.getNodeLog(0, LogType.SERVER_JSON);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.elasticsearch.client.ResponseException;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
@ -28,6 +30,14 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
|
||||
public class NodeRestUsageIT extends ESRestTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testWithRestUsage() throws IOException {
|
||||
// First get the current usage figures
|
||||
|
|
|
@ -11,6 +11,8 @@ package org.elasticsearch.test.rest;
|
|||
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -18,6 +20,14 @@ import static org.hamcrest.CoreMatchers.containsString;
|
|||
|
||||
public class RequestsWithoutContentIT extends ESRestTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
public void testIndexMissingBody() throws IOException {
|
||||
ResponseException responseException = expectThrows(
|
||||
ResponseException.class,
|
||||
|
|
|
@ -17,8 +17,10 @@ import org.elasticsearch.client.Request;
|
|||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.client.ResponseListener;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
@ -32,6 +34,15 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
* Tests that wait for refresh is fired if the index is closed.
|
||||
*/
|
||||
public class WaitForRefreshAndCloseIT extends ESRestTestCase {
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupIndex() throws IOException {
|
||||
Request request = new Request("PUT", "/test");
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
apply plugin: 'elasticsearch.build'
|
||||
apply plugin: 'elasticsearch.legacy-java-rest-test'
|
||||
apply plugin: 'elasticsearch.internal-java-rest-test'
|
||||
|
||||
dependencies {
|
||||
testImplementation project(":libs:x-content")
|
||||
|
@ -15,26 +15,6 @@ dependencies {
|
|||
|
||||
}
|
||||
|
||||
testClusters.all {
|
||||
setting 'xpack.security.enabled', 'false'
|
||||
}
|
||||
|
||||
testClusters.matching { it.name == "javaRestTest" }.configureEach {
|
||||
/**
|
||||
* Provide a custom log4j configuration where layout is an old style pattern and confirm that Elasticsearch
|
||||
* can successfully startup.
|
||||
*/
|
||||
extraConfigFile 'log4j2.properties', file('es-v7-log4j2.properties')
|
||||
}
|
||||
|
||||
tasks.named("javaRestTest").configure {
|
||||
nonInputProperties.systemProperty 'tests.logfile',
|
||||
"${-> testClusters.javaRestTest.singleNode().getServerLog().absolutePath.replaceAll("_server.json", ".log")}"
|
||||
|
||||
nonInputProperties.systemProperty 'tests.jsonLogfile',
|
||||
"${-> testClusters.javaRestTest.singleNode().getServerLog()}"
|
||||
}
|
||||
|
||||
tasks.named("test").configure {
|
||||
systemProperty 'tests.security.manager', 'false'
|
||||
}
|
||||
|
|
|
@ -8,18 +8,19 @@
|
|||
*/
|
||||
package org.elasticsearch.common.logging;
|
||||
|
||||
import org.elasticsearch.core.SuppressForbidden;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.elasticsearch.test.cluster.LogType;
|
||||
import org.elasticsearch.test.cluster.util.resource.Resource;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.matchesRegex;
|
||||
|
@ -34,53 +35,44 @@ public class CustomLoggingConfigIT extends ESRestTestCase {
|
|||
// [2020-03-20T14:51:59,989][INFO ][o.e.g.GatewayService ] [integTest-0] recovered [0] indices into cluster_state
|
||||
private static final String NODE_STARTED = ".*recovered.*cluster_state.*";
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
|
||||
.setting("xpack.security.enabled", "false")
|
||||
.configFile("log4j2.properties", Resource.fromClasspath("es-v7-log4j2.properties"))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
public void testSuccessfulStartupWithCustomConfig() throws Exception {
|
||||
assertBusy(() -> {
|
||||
List<String> lines = readAllLines(getPlaintextLogFile());
|
||||
List<String> lines = getPlaintextLog();
|
||||
assertThat(lines, Matchers.hasItem(matchesRegex(NODE_STARTED)));
|
||||
});
|
||||
}
|
||||
|
||||
public void testParseAllV7JsonLines() throws Exception {
|
||||
assertBusy(() -> {
|
||||
List<String> lines = readAllLines(getJSONLogFile());
|
||||
List<String> lines = getJSONLog();
|
||||
assertThat(lines, Matchers.hasItem(matchesRegex(NODE_STARTED)));
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> readAllLines(Path logFile) {
|
||||
return AccessController.doPrivileged((PrivilegedAction<List<String>>) () -> {
|
||||
try {
|
||||
return Files.readAllLines(logFile, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
});
|
||||
private List<String> getJSONLog() {
|
||||
try (InputStream nodeLog = cluster.getNodeLog(0, LogType.SERVER_JSON)) {
|
||||
return new BufferedReader(new InputStreamReader(nodeLog, StandardCharsets.UTF_8)).lines().toList();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "PathUtils doesn't have permission to read this file")
|
||||
private Path getJSONLogFile() {
|
||||
String logFileString = System.getProperty("tests.logfile");
|
||||
if (logFileString == null) {
|
||||
fail(
|
||||
"tests.logfile must be set to run this test. It is automatically "
|
||||
+ "set by gradle. If you must set it yourself then it should be the absolute path to the "
|
||||
+ "log file."
|
||||
);
|
||||
private List<String> getPlaintextLog() {
|
||||
try (InputStream nodeLog = cluster.getNodeLog(0, LogType.SERVER)) {
|
||||
return new BufferedReader(new InputStreamReader(nodeLog, StandardCharsets.UTF_8)).lines().toList();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
return Paths.get(logFileString);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "PathUtils doesn't have permission to read this file")
|
||||
private Path getPlaintextLogFile() {
|
||||
String logFileString = System.getProperty("tests.logfile");
|
||||
if (logFileString == null) {
|
||||
fail(
|
||||
"tests.logfile must be set to run this test. It is automatically "
|
||||
+ "set by gradle. If you must set it yourself then it should be the absolute path to the "
|
||||
+ "log file."
|
||||
);
|
||||
}
|
||||
return Paths.get(logFileString);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,49 +8,45 @@
|
|||
*/
|
||||
package org.elasticsearch.common.logging;
|
||||
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.elasticsearch.test.cluster.LogType;
|
||||
import org.elasticsearch.test.cluster.util.resource.Resource;
|
||||
import org.elasticsearch.xcontent.ObjectParser;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
* Test to verify ES JSON log format. Used in ES v7. Some users might decide to keep that format.
|
||||
* Provide a custom log4j configuration where layout is an old style pattern and confirm that Elasticsearch can successfully startup.
|
||||
*/
|
||||
public class ESJsonLogsConfigIT extends JsonLogsIntegTestCase {
|
||||
|
||||
private static final String NODE_NAME = "test-node-0";
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
|
||||
.setting("xpack.security.enabled", "false")
|
||||
.withNode(localNodeSpecBuilder -> localNodeSpecBuilder.name(NODE_NAME))
|
||||
.configFile("log4j2.properties", Resource.fromClasspath("es-v7-log4j2.properties"))
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InputStream openLogsStream() {
|
||||
return cluster.getNodeLog(0, LogType.SERVER_JSON);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Matcher<String> nodeNameMatcher() {
|
||||
return is("javaRestTest-0");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BufferedReader openReader(Path logFile) {
|
||||
assumeFalse(
|
||||
"Skipping test because it is being run against an external cluster.",
|
||||
logFile.getFileName().toString().equals("--external--")
|
||||
);
|
||||
|
||||
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> {
|
||||
try {
|
||||
String temp = Files.readString(logFile);
|
||||
|
||||
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogFileName() {
|
||||
return System.getProperty("tests.jsonLogfile");
|
||||
return is(NODE_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,17 +7,4 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
apply plugin: 'elasticsearch.legacy-java-rest-test'
|
||||
|
||||
testClusters.configureEach {
|
||||
setting 'xpack.security.enabled', 'false'
|
||||
}
|
||||
|
||||
testClusters.matching { it.name == "javaRestTest" }.configureEach {
|
||||
nameCustomization = { null }
|
||||
}
|
||||
|
||||
tasks.named("javaRestTest").configure {
|
||||
nonInputProperties.systemProperty 'tests.logfile',
|
||||
"${-> testClusters.javaRestTest.singleNode().getServerLog()}"
|
||||
}
|
||||
apply plugin: 'elasticsearch.internal-java-rest-test'
|
||||
|
|
|
@ -10,15 +10,12 @@
|
|||
package org.elasticsearch.unconfigured_node_name;
|
||||
|
||||
import org.elasticsearch.common.logging.JsonLogsIntegTestCase;
|
||||
import org.elasticsearch.test.cluster.ElasticsearchCluster;
|
||||
import org.elasticsearch.test.cluster.LogType;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.ClassRule;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
|
@ -26,9 +23,24 @@ public class JsonLogsFormatAndParseIT extends JsonLogsIntegTestCase {
|
|||
private static final String OS_NAME = System.getProperty("os.name");
|
||||
private static final boolean WINDOWS = OS_NAME.startsWith("Windows");
|
||||
|
||||
// These match the values defined in org.elasticsearch.gradle.testclusters.ElasticsearchNode
|
||||
private static final String COMPUTERNAME = "WindowsComputername";
|
||||
private static final String HOSTNAME = "LinuxDarwinHostname";
|
||||
private static final String COMPUTERNAME = "WindowsTestComputername";
|
||||
private static final String HOSTNAME = "LinuxDarwinTestHostname";
|
||||
|
||||
@ClassRule
|
||||
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
|
||||
.setting("xpack.security.enabled", "false")
|
||||
.setting("discovery.type", "single-node")
|
||||
.withNode(
|
||||
localNodeSpecBuilder -> localNodeSpecBuilder.withoutName()
|
||||
.environment("HOSTNAME", HOSTNAME)
|
||||
.environment("COMPUTERNAME", COMPUTERNAME)
|
||||
)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected String getTestRestCluster() {
|
||||
return cluster.getHttpAddresses();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Matcher<String> nodeNameMatcher() {
|
||||
|
@ -39,13 +51,7 @@ public class JsonLogsFormatAndParseIT extends JsonLogsIntegTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected BufferedReader openReader(Path logFile) {
|
||||
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> {
|
||||
try {
|
||||
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
protected InputStream openLogsStream() {
|
||||
return cluster.getNodeLog(0, LogType.SERVER_JSON);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
|
||||
package org.elasticsearch.common.logging;
|
||||
|
||||
import org.elasticsearch.core.SuppressForbidden;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.elasticsearch.xcontent.ObjectParser;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -50,18 +50,21 @@ public abstract class JsonLogsIntegTestCase extends ESRestTestCase {
|
|||
*/
|
||||
protected abstract org.hamcrest.Matcher<String> nodeNameMatcher();
|
||||
|
||||
private BufferedReader openReader() {
|
||||
return new BufferedReader(new InputStreamReader(openLogsStream(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the log file. This is delegated to subclasses because the test
|
||||
* framework doesn't have permission to read from the log file but
|
||||
* subclasses can grant themselves that permission.
|
||||
* Reads the logs.
|
||||
* This is delegated to subclasses because they configure the cluster and have access to the nodes logs InputStream.
|
||||
*/
|
||||
protected abstract BufferedReader openReader(Path logFile);
|
||||
protected abstract InputStream openLogsStream();
|
||||
|
||||
public void testElementsPresentOnAllLinesOfLog() throws IOException {
|
||||
JsonLogLine firstLine = findFirstLine();
|
||||
assertNotNull(firstLine);
|
||||
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(getLogFile()), getParser())) {
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(), getParser())) {
|
||||
stream.limit(LINES_TO_CHECK).forEach(jsonLogLine -> {
|
||||
assertThat(jsonLogLine.getDataset(), is(not(emptyOrNullString())));
|
||||
assertThat(jsonLogLine.getTimestamp(), is(not(emptyOrNullString())));
|
||||
|
@ -77,13 +80,13 @@ public abstract class JsonLogsIntegTestCase extends ESRestTestCase {
|
|||
}
|
||||
|
||||
private JsonLogLine findFirstLine() throws IOException {
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(getLogFile()), getParser())) {
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(), getParser())) {
|
||||
return stream.findFirst().orElseThrow(() -> new AssertionError("no logs at all?!"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testNodeIdAndClusterIdConsistentOnceAvailable() throws IOException {
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(getLogFile()), getParser())) {
|
||||
try (Stream<JsonLogLine> stream = JsonLogsStream.from(openReader(), getParser())) {
|
||||
Iterator<JsonLogLine> iterator = stream.iterator();
|
||||
|
||||
JsonLogLine firstLine = null;
|
||||
|
@ -91,6 +94,7 @@ public abstract class JsonLogsIntegTestCase extends ESRestTestCase {
|
|||
JsonLogLine jsonLogLine = iterator.next();
|
||||
if (jsonLogLine.getNodeId() != null) {
|
||||
firstLine = jsonLogLine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(firstLine);
|
||||
|
@ -106,23 +110,6 @@ public abstract class JsonLogsIntegTestCase extends ESRestTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "PathUtils doesn't have permission to read this file")
|
||||
private Path getLogFile() {
|
||||
String logFileString = getLogFileName();
|
||||
if (logFileString == null) {
|
||||
fail(
|
||||
"tests.logfile must be set to run this test. It is automatically "
|
||||
+ "set by gradle. If you must set it yourself then it should be the absolute path to the "
|
||||
+ "log file."
|
||||
);
|
||||
}
|
||||
return Paths.get(logFileString);
|
||||
}
|
||||
|
||||
protected String getLogFileName() {
|
||||
return System.getProperty("tests.logfile");
|
||||
}
|
||||
|
||||
protected ObjectParser<JsonLogLine, Void> getParser() {
|
||||
return JsonLogLine.ECS_LOG_LINE;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -130,7 +131,7 @@ public abstract class AbstractLocalClusterFactory<S extends LocalClusterSpec, H
|
|||
this.distributionResolver = distributionResolver;
|
||||
this.spec = spec;
|
||||
this.name = suffix == null ? spec.getName() : spec.getName() + "-" + suffix;
|
||||
this.workingDir = baseWorkingDir.resolve(name);
|
||||
this.workingDir = baseWorkingDir.resolve(name != null ? name : UUID.randomUUID().toString());
|
||||
this.repoDir = baseWorkingDir.resolve("repo");
|
||||
this.dataDir = workingDir.resolve("data");
|
||||
this.logsDir = workingDir.resolve("logs");
|
||||
|
@ -386,7 +387,9 @@ public abstract class AbstractLocalClusterFactory<S extends LocalClusterSpec, H
|
|||
// Write settings to elasticsearch.yml
|
||||
Map<String, String> finalSettings = new HashMap<>();
|
||||
finalSettings.put("cluster.name", spec.getCluster().getName());
|
||||
finalSettings.put("node.name", name);
|
||||
if (name != null) {
|
||||
finalSettings.put("node.name", name);
|
||||
}
|
||||
finalSettings.put("path.repo", repoDir.toString());
|
||||
finalSettings.put("path.data", dataDir.toString());
|
||||
finalSettings.put("path.logs", logsDir.toString());
|
||||
|
|
|
@ -18,7 +18,9 @@ import org.elasticsearch.test.cluster.util.resource.Resource;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -141,9 +143,10 @@ public abstract class AbstractLocalClusterSpecBuilder<T extends ElasticsearchClu
|
|||
|
||||
if (nodeBuilders.isEmpty()) {
|
||||
// No node-specific configuration so assume a single-node cluster
|
||||
nodeSpecs = List.of(new DefaultLocalNodeSpecBuilder(this).build(clusterSpec));
|
||||
nodeSpecs = List.of(new DefaultLocalNodeSpecBuilder(this).build(clusterSpec, 0));
|
||||
} else {
|
||||
nodeSpecs = nodeBuilders.stream().map(node -> node.build(clusterSpec)).toList();
|
||||
AtomicInteger nodeIndex = new AtomicInteger(0);
|
||||
nodeSpecs = nodeBuilders.stream().map(node -> node.build(clusterSpec, nodeIndex.getAndIncrement())).toList();
|
||||
}
|
||||
|
||||
clusterSpec.setNodes(nodeSpecs);
|
||||
|
@ -154,6 +157,7 @@ public abstract class AbstractLocalClusterSpecBuilder<T extends ElasticsearchClu
|
|||
|
||||
public static class DefaultLocalNodeSpecBuilder extends AbstractLocalSpecBuilder<LocalNodeSpecBuilder> implements LocalNodeSpecBuilder {
|
||||
private String name;
|
||||
private boolean unsetName = false;
|
||||
|
||||
protected DefaultLocalNodeSpecBuilder(AbstractLocalSpecBuilder<?> parent) {
|
||||
super(parent);
|
||||
|
@ -161,15 +165,37 @@ public abstract class AbstractLocalClusterSpecBuilder<T extends ElasticsearchClu
|
|||
|
||||
@Override
|
||||
public DefaultLocalNodeSpecBuilder name(String name) {
|
||||
this.name = name;
|
||||
if (unsetName) {
|
||||
throw new IllegalStateException("Cannot set name when 'withoutName()` has been used");
|
||||
}
|
||||
this.name = Objects.requireNonNull(
|
||||
name,
|
||||
"Name cannot be set to null. Consider using '.withoutName()' method if you need node without explicitly set name"
|
||||
);
|
||||
return this;
|
||||
}
|
||||
|
||||
private LocalNodeSpec build(LocalClusterSpec cluster) {
|
||||
@Override
|
||||
public DefaultLocalNodeSpecBuilder withoutName() {
|
||||
if (name != null) {
|
||||
throw new IllegalStateException("Cannot use 'withoutName()', because name has been set for the node");
|
||||
}
|
||||
this.unsetName = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
private String resolveName(LocalClusterSpec cluster, int nodeIndex) {
|
||||
if (unsetName) {
|
||||
return null;
|
||||
}
|
||||
return name == null ? cluster.getName() + "-" + nodeIndex : name;
|
||||
}
|
||||
|
||||
private LocalNodeSpec build(LocalClusterSpec cluster, int nodeIndex) {
|
||||
|
||||
return new LocalNodeSpec(
|
||||
cluster,
|
||||
name,
|
||||
resolveName(cluster, nodeIndex),
|
||||
Optional.ofNullable(getVersion()).orElse(Version.CURRENT),
|
||||
getSettingsProviders(),
|
||||
getSettings(),
|
||||
|
|
|
@ -15,9 +15,14 @@ import org.elasticsearch.test.cluster.local.distribution.DistributionType;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DefaultSettingsProvider implements SettingsProvider {
|
||||
|
||||
private static final String MULTI_NODE_DISCOVERY_TYPE = "multi-node";
|
||||
private static final String DISCOVERY_TYPE_SETTING = "discovery.type";
|
||||
|
||||
@Override
|
||||
public Map<String, String> get(LocalNodeSpec nodeSpec) {
|
||||
Map<String, String> settings = new HashMap<>();
|
||||
|
@ -70,18 +75,29 @@ public class DefaultSettingsProvider implements SettingsProvider {
|
|||
.stream()
|
||||
.filter(LocalNodeSpec::isMasterEligible)
|
||||
.map(LocalNodeSpec::getName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
if (masterEligibleNodes.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot start cluster '" + nodeSpec.getCluster().getName() + "' as it configured with no master-eligible nodes."
|
||||
);
|
||||
}
|
||||
if (isMultiNodeCluster(nodeSpec.getCluster())) {
|
||||
if (masterEligibleNodes.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot start multi-node cluster '" + nodeSpec.getCluster().getName() + "' as configured with no master-eligible nodes."
|
||||
);
|
||||
}
|
||||
|
||||
settings.put("cluster.initial_master_nodes", "[" + masterEligibleNodes + "]");
|
||||
settings.put("discovery.seed_providers", "file");
|
||||
settings.put("discovery.seed_hosts", "[]");
|
||||
settings.put("cluster.initial_master_nodes", "[" + masterEligibleNodes + "]");
|
||||
settings.put("discovery.seed_providers", "file");
|
||||
settings.put("discovery.seed_hosts", "[]");
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
private boolean isMultiNodeCluster(LocalClusterSpec cluster) {
|
||||
return cluster.getNodes().size() > 1
|
||||
|| cluster.getNodes()
|
||||
.getFirst()
|
||||
.getSetting(DISCOVERY_TYPE_SETTING, MULTI_NODE_DISCOVERY_TYPE)
|
||||
.equals(MULTI_NODE_DISCOVERY_TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.elasticsearch.test.cluster.util.resource.Resource;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -155,7 +156,7 @@ public class LocalClusterSpec implements ClusterSpec {
|
|||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? cluster.getName() + "-" + cluster.getNodes().indexOf(this) : name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
|
@ -345,7 +346,7 @@ public class LocalClusterSpec implements ClusterSpec {
|
|||
|
||||
newCluster.setNodes(nodeSpecs);
|
||||
|
||||
return nodeSpecs.stream().filter(n -> n.getName().equals(this.getName())).findFirst().get();
|
||||
return nodeSpecs.stream().filter(n -> Objects.equals(n.getName(), this.getName())).findFirst().get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,4 +15,9 @@ public interface LocalNodeSpecBuilder extends LocalSpecBuilder<LocalNodeSpecBuil
|
|||
* Sets the node name. By default, nodes are named after the cluster with an incrementing suffix (ex: my-cluster-0).
|
||||
*/
|
||||
LocalNodeSpecBuilder name(String name);
|
||||
|
||||
/**
|
||||
* Explicitly sets that this node should not have a name in configuration.
|
||||
*/
|
||||
LocalNodeSpecBuilder withoutName();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ apply plugin: 'elasticsearch.bwc-test'
|
|||
|
||||
|
||||
dependencies {
|
||||
testImplementation project(path: xpackModule('ent-search'))
|
||||
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
|
||||
javaRestTestImplementation(testArtifact(project(":qa:full-cluster-restart"), "javaRestTest"))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
apply plugin: 'elasticsearch.internal-java-rest-test'
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':x-pack:plugin:core')
|
||||
javaRestTestImplementation project(path: xpackModule('inference'))
|
||||
clusterPlugins project(':x-pack:plugin:inference:qa:test-service-plugin')
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import org.elasticsearch.gradle.Version
|
||||
import org.elasticsearch.gradle.VersionProperties
|
||||
import org.elasticsearch.gradle.util.GradleUtils
|
||||
import org.elasticsearch.gradle.internal.info.BuildParams
|
||||
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
|
||||
|
||||
|
@ -9,8 +8,6 @@ apply plugin: 'elasticsearch.internal-test-artifact-base'
|
|||
apply plugin: 'elasticsearch.bwc-test'
|
||||
|
||||
dependencies {
|
||||
testImplementation project(path: ':x-pack:plugin:inference:qa:inference-service-tests')
|
||||
compileOnly project(':x-pack:plugin:core')
|
||||
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
|
||||
javaRestTestImplementation project(path: xpackModule('inference'))
|
||||
clusterPlugins project(
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import org.elasticsearch.gradle.Version
|
||||
import org.elasticsearch.gradle.VersionProperties
|
||||
import org.elasticsearch.gradle.internal.info.BuildParams
|
||||
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
|
||||
|
||||
|
@ -16,7 +14,6 @@ apply plugin: 'elasticsearch.bwc-test'
|
|||
|
||||
|
||||
dependencies {
|
||||
compileOnly project(':x-pack:plugin:core')
|
||||
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
|
||||
javaRestTestImplementation project(path: xpackModule('inference'))
|
||||
javaRestTestImplementation(testArtifact(project(":qa:rolling-upgrade"), "javaRestTest"))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
apply plugin: 'elasticsearch.internal-java-rest-test'
|
||||
apply plugin: 'elasticsearch.java'
|
||||
|
||||
dependencies {
|
||||
api project(':libs:x-content')
|
||||
|
|
Loading…
Add table
Reference in a new issue