Skip to content

Commit

Permalink
Merge branch 'main' into ps241120-RTG-keepContext
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Nov 21, 2024
2 parents c8fba48 + 8c20ac5 commit a5940ac
Show file tree
Hide file tree
Showing 229 changed files with 7,906 additions and 2,984 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.plugins.PluginsLoader;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.plugins.ScriptPlugin;
import org.elasticsearch.script.DocReader;
Expand Down Expand Up @@ -76,8 +77,7 @@ public class ScriptScoreBenchmark {
private final PluginsService pluginsService = new PluginsService(
Settings.EMPTY,
null,
null,
Path.of(System.getProperty("plugins.dir"))
new PluginsLoader(null, Path.of(System.getProperty("plugins.dir")))
);
private final ScriptModule scriptModule = new ScriptModule(Settings.EMPTY, pluginsService.filterPlugins(ScriptPlugin.class).toList());

Expand Down
3 changes: 3 additions & 0 deletions branches.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{
"branch": "8.16"
},
{
"branch": "8.17"
},
{
"branch": "8.x"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@ import org.elasticsearch.gradle.internal.test.AntFixture
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.tasks.Internal
import org.gradle.process.ExecOperations

import javax.inject.Inject

abstract class AntFixtureStop extends LoggedExec implements FixtureStop {

@Internal
AntFixture fixture

@Inject
AntFixtureStop(ProjectLayout projectLayout,
ExecOperations execOperations,
Expand All @@ -34,12 +30,12 @@ abstract class AntFixtureStop extends LoggedExec implements FixtureStop {
}

void setFixture(AntFixture fixture) {
assert this.fixture == null
this.fixture = fixture;
final Object pid = "${-> this.fixture.pid}"
onlyIf("pidFile exists") { fixture.pidFile.exists() }
def pidFile = fixture.pidFile
def fixtureName = fixture.name
final Object pid = "${-> Integer.parseInt(pidFile.getText('UTF-8').trim())}"
onlyIf("pidFile exists") { pidFile.exists() }
doFirst {
logger.info("Shutting down ${fixture.name} with pid ${pid}")
logger.info("Shutting down ${fixtureName} with pid ${pid}")
}

if (OS.current() == OS.WINDOWS) {
Expand All @@ -51,9 +47,8 @@ abstract class AntFixtureStop extends LoggedExec implements FixtureStop {
}
doLast {
fileSystemOperations.delete {
it.delete(fixture.pidFile)
it.delete(pidFile)
}
}
this.fixture = fixture
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import java.nio.charset.Charset
*/
public abstract class AntTask extends DefaultTask {

/**
* A buffer that will contain the output of the ant code run,
* if the output was not already written directly to stdout.
*/
public final ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream()

@Inject
protected FileSystemOperations getFileSystemOperations() {
Expand All @@ -57,6 +52,11 @@ public abstract class AntTask extends DefaultTask {

// otherwise groovy replaces System.out, and you have no chance to debug
// ant.saveStreams = false
/**
* A buffer that will contain the output of the ant code run,
* if the output was not already written directly to stdout.
*/
ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream()

final int outputLevel = logger.isDebugEnabled() ? Project.MSG_DEBUG : Project.MSG_INFO
final PrintStream stream = useStdout() ? System.out : new PrintStream(outputBuffer, true, Charset.defaultCharset().name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,37 @@
package org.elasticsearch.gradle.internal.test

import org.elasticsearch.gradle.OS

import org.elasticsearch.gradle.internal.AntFixtureStop
import org.elasticsearch.gradle.internal.AntTask
import org.elasticsearch.gradle.testclusters.TestClusterInfo
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
import org.gradle.api.GradleException
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskProvider

import javax.inject.Inject

/**
* A fixture for integration tests which runs in a separate process launched by Ant.
*/
class AntFixture extends AntTask implements Fixture {
class AntFixture extends AntTask {

/** The path to the executable that starts the fixture. */
@Internal
String executable

private final List<Object> arguments = new ArrayList<>()
private ProjectLayout projectLayout
private final ProviderFactory providerFactory

void args(Object... args) {
arguments.addAll(args)
Expand Down Expand Up @@ -69,19 +84,14 @@ class AntFixture extends AntTask implements Fixture {
return tmpFile.exists()
}

private final TaskProvider<AntFixtureStop> stopTask

AntFixture() {
stopTask = createStopTask()
@Inject
AntFixture(ProjectLayout projectLayout, ProviderFactory providerFactory) {
this.providerFactory = providerFactory
this.projectLayout = projectLayout;
TaskProvider<AntFixtureStop> stopTask = createStopTask()
finalizedBy(stopTask)
}

@Override
@Internal
TaskProvider<AntFixtureStop> getStopTask() {
return stopTask
}

@Override
protected void runAnt(AntBuilder ant) {
// reset everything
Expand Down Expand Up @@ -231,7 +241,7 @@ class AntFixture extends AntTask implements Fixture {
*/
@Internal
protected File getBaseDir() {
return new File(project.buildDir, "fixtures/${name}")
return new File(projectLayout.getBuildDirectory().getAsFile().get(), "fixtures/${name}")
}

/** Returns the working directory for the process. Defaults to "cwd" inside baseDir. */
Expand All @@ -242,7 +252,7 @@ class AntFixture extends AntTask implements Fixture {

/** Returns the file the process writes its pid to. Defaults to "pid" inside baseDir. */
@Internal
protected File getPidFile() {
File getPidFile() {
return new File(baseDir, 'pid')
}

Expand All @@ -264,6 +274,12 @@ class AntFixture extends AntTask implements Fixture {
return portsFile.readLines("UTF-8").get(0)
}

@Internal
Provider<String> getAddressAndPortProvider() {
File thePortFile = portsFile
return providerFactory.provider(() -> thePortFile.readLines("UTF-8").get(0))
}

/** Returns a file that wraps around the actual command when {@code spawn == true}. */
@Internal
protected File getWrapperScript() {
Expand All @@ -281,4 +297,22 @@ class AntFixture extends AntTask implements Fixture {
protected File getRunLog() {
return new File(cwd, 'run.log')
}

@Internal
Provider<AntFixtureValueSource> getAddressAndPortSource() {
return providerFactory.of(AntFixtureValueSource.class, spec -> {
spec.getParameters().getPortFile().set(portsFile);
});
}

static abstract class AntFixtureValueSource implements ValueSource<String, AntFixtureValueSource.Parameters> {
@Override
String obtain() {
return getParameters().getPortFile().map { it.readLines("UTF-8").get(0) }.get()
}

interface Parameters extends ValueSourceParameters {
Property<File> getPortFile();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.Directory;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.ProjectLayout;
import org.gradle.api.file.RelativePath;
import org.gradle.api.internal.file.FileOperations;
Expand Down Expand Up @@ -244,10 +245,11 @@ public void apply(Project project) {
yamlRestCompatTestTask.configure(testTask -> {
testTask.systemProperty("tests.restCompat", true);
// Use test runner and classpath from "normal" yaml source set
FileCollection outputFileCollection = yamlCompatTestSourceSet.getOutput();
testTask.setTestClassesDirs(
yamlTestSourceSet.getOutput().getClassesDirs().plus(yamlCompatTestSourceSet.getOutput().getClassesDirs())
);
testTask.onlyIf("Compatibility tests are available", t -> yamlCompatTestSourceSet.getOutput().isEmpty() == false);
testTask.onlyIf("Compatibility tests are available", t -> outputFileCollection.isEmpty() == false);
testTask.setClasspath(
yamlCompatTestSourceSet.getRuntimeClasspath()
// remove the "normal" api and tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
private final transient Project project;
private final Provider<ReaperService> reaper;
private final Provider<TestClustersRegistry> testClustersRegistryProvider;
private final FileSystemOperations fileSystemOperations;
private final ArchiveOperations archiveOperations;
private final ExecOperations execOperations;
Expand All @@ -87,11 +88,14 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {

private boolean shared = false;

private int claims = 0;

public ElasticsearchCluster(
String path,
String clusterName,
Project project,
Provider<ReaperService> reaper,
Provider<TestClustersRegistry> testClustersRegistryProvider,
FileSystemOperations fileSystemOperations,
ArchiveOperations archiveOperations,
ExecOperations execOperations,
Expand All @@ -104,6 +108,7 @@ public ElasticsearchCluster(
this.clusterName = clusterName;
this.project = project;
this.reaper = reaper;
this.testClustersRegistryProvider = testClustersRegistryProvider;
this.fileSystemOperations = fileSystemOperations;
this.archiveOperations = archiveOperations;
this.execOperations = execOperations;
Expand All @@ -120,6 +125,7 @@ public ElasticsearchCluster(
clusterName + "-0",
project,
reaper,
testClustersRegistryProvider,
fileSystemOperations,
archiveOperations,
execOperations,
Expand Down Expand Up @@ -177,6 +183,7 @@ public void setNumberOfNodes(int numberOfNodes) {
clusterName + "-" + i,
project,
reaper,
testClustersRegistryProvider,
fileSystemOperations,
archiveOperations,
execOperations,
Expand Down Expand Up @@ -408,6 +415,7 @@ public void setPreserveDataDir(boolean preserveDataDir) {
public void freeze() {
nodes.forEach(ElasticsearchNode::freeze);
configurationFrozen.set(true);
nodes.whenObjectAdded(node -> { throw new IllegalStateException("Cannot add nodes to test cluster after is has been frozen"); });
}

private void checkFrozen() {
Expand Down Expand Up @@ -663,4 +671,11 @@ public String toString() {
return "cluster{" + path + ":" + clusterName + "}";
}

int addClaim() {
return ++this.claims;
}

int removeClaim() {
return --this.claims;
}
}
Loading

0 comments on commit a5940ac

Please sign in to comment.