From c6f250a6bc9fb9a2bc1f2ad4aec799ea7899f3d3 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Wed, 13 Nov 2024 14:11:46 -0800 Subject: [PATCH] Simplify entitlement agent REST tests --- qa/entitlements/build.gradle | 13 ------------ .../test/entitlements/EntitlementsIT.java | 10 ---------- .../local/AbstractLocalClusterFactory.java | 20 ++++++++++++------- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/qa/entitlements/build.gradle b/qa/entitlements/build.gradle index 2621d2731f411..9a5058a3b11ac 100644 --- a/qa/entitlements/build.gradle +++ b/qa/entitlements/build.gradle @@ -18,21 +18,8 @@ esplugin { classname 'org.elasticsearch.test.entitlements.EntitlementsCheckPlugin' } -configurations { - entitlementBridge { - canBeConsumed = false - } -} - dependencies { clusterPlugins project(':qa:entitlements') - entitlementBridge project(':libs:entitlement:bridge') -} - -tasks.named('javaRestTest') { - systemProperty "tests.entitlement-bridge.jar-name", configurations.entitlementBridge.singleFile.getName() - usesDefaultDistribution() - systemProperty "tests.security.manager", "false" } tasks.named("javadoc").configure { diff --git a/qa/entitlements/src/javaRestTest/java/org/elasticsearch/test/entitlements/EntitlementsIT.java b/qa/entitlements/src/javaRestTest/java/org/elasticsearch/test/entitlements/EntitlementsIT.java index a62add89c51e6..8b3629527f918 100644 --- a/qa/entitlements/src/javaRestTest/java/org/elasticsearch/test/entitlements/EntitlementsIT.java +++ b/qa/entitlements/src/javaRestTest/java/org/elasticsearch/test/entitlements/EntitlementsIT.java @@ -10,9 +10,7 @@ package org.elasticsearch.test.entitlements; import org.elasticsearch.client.Request; -import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.cluster.ElasticsearchCluster; -import org.elasticsearch.test.cluster.local.distribution.DistributionType; import org.elasticsearch.test.rest.ESRestTestCase; import org.junit.ClassRule; @@ -20,21 +18,13 @@ import static org.hamcrest.Matchers.containsString; -@ESTestCase.WithoutSecurityManager public class EntitlementsIT extends ESRestTestCase { - private static final String ENTITLEMENT_BRIDGE_JAR_NAME = System.getProperty("tests.entitlement-bridge.jar-name"); - @ClassRule public static ElasticsearchCluster cluster = ElasticsearchCluster.local() - .distribution(DistributionType.INTEG_TEST) .plugin("entitlement-qa") .systemProperty("es.entitlements.enabled", "true") .setting("xpack.security.enabled", "false") - .jvmArg("-Djdk.attach.allowAttachSelf=true") - .jvmArg("-XX:+EnableDynamicAgentLoading") - .jvmArg("--patch-module=java.base=lib/entitlement-bridge/" + ENTITLEMENT_BRIDGE_JAR_NAME) - .jvmArg("--add-exports=java.base/org.elasticsearch.entitlement.bridge=org.elasticsearch.entitlement") .build(); @Override diff --git a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java index ec1bf13bd993b..c616f4de6e036 100644 --- a/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java +++ b/test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalClusterFactory.java @@ -55,10 +55,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; +import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; +import static java.util.function.Predicate.not; import static org.elasticsearch.test.cluster.local.distribution.DistributionType.DEFAULT; import static org.elasticsearch.test.cluster.util.OS.WINDOWS; @@ -755,18 +757,22 @@ private Map getEnvironmentVariables() { } String heapSize = System.getProperty("tests.heap.size", "512m"); - final String esJavaOpts = Stream.of( - "-Xms" + heapSize, - "-Xmx" + heapSize, + List serverOpts = List.of("-Xms" + heapSize, "-Xmx" + heapSize, debugArgs, featureFlagProperties); + List commonOpts = List.of( "-ea", "-esa", System.getProperty("tests.jvm.argline", ""), - featureFlagProperties, systemProperties, - jvmArgs, - debugArgs - ).filter(s -> s.isEmpty() == false).collect(Collectors.joining(" ")); + jvmArgs + ); + + String esJavaOpts = Stream.concat(serverOpts.stream(), commonOpts.stream()) + .filter(not(String::isEmpty)) + .collect(Collectors.joining(" ")); + String cliJavaOpts = commonOpts.stream().filter(not(String::isEmpty)).collect(Collectors.joining(" ")); + environment.put("ES_JAVA_OPTS", esJavaOpts); + environment.put("CLI_JAVA_OPTS", cliJavaOpts); return environment; }