Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
- remove unsed code
- fail early when nodes are somehow added to a testcluster after useCluster
  • Loading branch information
breskeby committed Nov 18, 2024
1 parent dd47867 commit 3e01d40
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +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 sourceSetOutput = yamlCompatTestSourceSet.getOutput();
FileCollection outputFileCollection = yamlCompatTestSourceSet.getOutput();
testTask.setTestClassesDirs(
yamlTestSourceSet.getOutput().getClassesDirs().plus(yamlCompatTestSourceSet.getOutput().getClassesDirs())
);
testTask.onlyIf("Compatibility tests are available", t -> sourceSetOutput.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 @@ -415,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 @@ -670,12 +671,11 @@ public String toString() {
return "cluster{" + path + ":" + clusterName + "}";
}

@Internal
public int getClaims() {
return claims;
int addClaim() {
return ++this.claims;
}

public void setClaims(int claims) {
this.claims = claims;
int removeClaim() {
return --this.claims;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ default void useCluster(ElasticsearchCluster cluster) {
dependsOn(cluster.getPluginAndModuleConfigurations());
}
getClusters().add(cluster);
cluster.freeze();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ public abstract class TestClustersRegistry implements BuildService<BuildServiceP
private static final Logger logger = Logging.getLogger(TestClustersRegistry.class);
private static final String TESTCLUSTERS_INSPECT_FAILURE = "testclusters.inspect.failure";
private final Boolean allowClusterToSurvive = Boolean.valueOf(System.getProperty(TESTCLUSTERS_INSPECT_FAILURE, "false"));
private final Map<ElasticsearchCluster, Integer> claimsInventory = new HashMap<>();
private final Set<ElasticsearchCluster> runningClusters = new HashSet<>();
private final Map<String, Process> nodeProcesses = new HashMap<>();

@Inject
public abstract ProviderFactory getProviderFactory();

public void claimCluster(ElasticsearchCluster cluster) {
int claim = claimsInventory.getOrDefault(cluster, cluster.getClaims()) + 1;
claimsInventory.put(cluster, claim);
cluster.setClaims(claim);
if (claim > 1) {
int claims = cluster.addClaim();
if (claims > 1) {
cluster.setShared(true);
}
}
Expand Down Expand Up @@ -82,9 +79,7 @@ public void stopCluster(ElasticsearchCluster cluster, boolean taskFailed) {
runningClusters.remove(cluster);
}
} else {
int currentClaims = claimsInventory.getOrDefault(cluster, cluster.getClaims()) - 1;
claimsInventory.put(cluster, currentClaims);
cluster.setClaims(currentClaims);
int currentClaims = cluster.removeClaim();
if (currentClaims <= 0 && runningClusters.contains(cluster)) {
cluster.stop(false);
runningClusters.remove(cluster);
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ tasks.named("test").configure {
}
}
File functionsFolder = file("build/testrun/test/temp/esql/functions")
File signatureFolder = file("build/testrun/test/temp/esql/functions/signature")
File typesFolder = file("build/testrun/test/temp/esql/functions/types")
def functionsDocFolder = file("${rootDir}/docs/reference/esql/functions")
def effectiveProjectDir = projectDir

doLast {
List signatures = signatureFolder.list().findAll {it.endsWith("svg")}
List types = typesFolder.list().findAll {it.endsWith("asciidoc")}
int count = types == null ? 0 : types.size()
Closure readExample = line -> {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugin/sql/qa/jdbc/security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ subprojects {
project.gradle.sharedServices,
TestClustersPlugin.REGISTRY_SERVICE_NAME
)
def clusterInfo = project.getProviders().of(TestClusterValueSource.class) {
project.getProviders().of(TestClusterValueSource.class) {
it.parameters.path.set(clusterPath)
it.parameters.clusterName.set("javaRestTest")
it.parameters.service = serviceProvider
Expand Down

0 comments on commit 3e01d40

Please sign in to comment.