Browse Source

Use ESTestCase in server cli tests (#86783)

This commit removes the LaunchersTestCase in favor of ESTestCase.

relates #85758
Ryan Ernst 3 years ago
parent
commit
132633e998

+ 5 - 9
distribution/tools/server-cli/build.gradle

@@ -20,15 +20,11 @@ tasks.withType(CheckForbiddenApis).configureEach {
   replaceSignatureFiles 'jdk-signatures'
 }
 
-tasks.named("testingConventions").configure {
-  naming.clear()
-  naming {
-    Tests {
-      baseClass 'org.elasticsearch.server.cli.LaunchersTestCase'
-    }
-  }
-}
-
 ["javadoc", "loggerUsageCheck", "jarHell"].each { tsk ->
   tasks.named(tsk).configure { enabled = false }
 }
+
+tasks.named("test").configure {
+  // this is necessary to jvm options can invoke java to find final options
+  systemProperty "tests.system_call_filter", "false"
+}

+ 2 - 1
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/BootstrapJvmOptionsTests.java

@@ -9,6 +9,7 @@
 package org.elasticsearch.server.cli;
 
 import org.elasticsearch.server.cli.BootstrapJvmOptions.PluginInfo;
+import org.elasticsearch.test.ESTestCase;
 
 import java.util.List;
 import java.util.Properties;
@@ -18,7 +19,7 @@ import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
 
-public class BootstrapJvmOptionsTests extends LaunchersTestCase {
+public class BootstrapJvmOptionsTests extends ESTestCase {
 
     public void testGenerateOptionsHandlesNoPlugins() {
         final List<String> options = BootstrapJvmOptions.generateOptions(List.of());

+ 7 - 1
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/JvmErgonomicsTests.java

@@ -8,6 +8,10 @@
 
 package org.elasticsearch.server.cli;
 
+import org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems;
+import org.elasticsearch.test.ESTestCase;
+import org.elasticsearch.test.ESTestCase.WithoutSecurityManager;
+
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
@@ -28,7 +32,9 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-public class JvmErgonomicsTests extends LaunchersTestCase {
+@WithoutSecurityManager
+@SuppressFileSystems("*")
+public class JvmErgonomicsTests extends ESTestCase {
 
     public void testExtractValidHeapSizeUsingXmx() throws Exception {
         assertThat(JvmOption.extractMaxHeapSize(JvmOption.findFinalOptions(Collections.singletonList("-Xmx2g"))), equalTo(2L << 30));

+ 11 - 12
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/JvmOptionsParserTests.java

@@ -8,6 +8,9 @@
 
 package org.elasticsearch.server.cli;
 
+import org.elasticsearch.test.ESTestCase;
+import org.elasticsearch.test.ESTestCase.WithoutSecurityManager;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.StringReader;
@@ -28,13 +31,9 @@ import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasKey;
 import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-public class JvmOptionsParserTests extends LaunchersTestCase {
+@WithoutSecurityManager
+public class JvmOptionsParserTests extends ESTestCase {
 
     public void testSubstitution() {
         final List<String> jvmOptions = JvmOptionsParser.substitutePlaceholders(
@@ -146,7 +145,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
     }
 
     public void testMissingRootJvmOptions() throws IOException, JvmOptionsParser.JvmOptionsFileParserException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         try {
             final JvmOptionsParser parser = new JvmOptionsParser();
             parser.readJvmOptionsFiles(config);
@@ -157,7 +156,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
     }
 
     public void testReadRootJvmOptions() throws IOException, JvmOptionsParser.JvmOptionsFileParserException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         final Path rootJvmOptions = config.resolve("jvm.options");
         Files.write(rootJvmOptions, List.of("# comment", "-Xms256m", "-Xmx256m"), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND);
         if (randomBoolean()) {
@@ -170,7 +169,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
     }
 
     public void testReadJvmOptionsDirectory() throws IOException, JvmOptionsParser.JvmOptionsFileParserException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         Files.createDirectory(config.resolve("jvm.options.d"));
         Files.write(
             config.resolve("jvm.options"),
@@ -190,7 +189,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
     }
 
     public void testReadJvmOptionsDirectoryInOrder() throws IOException, JvmOptionsParser.JvmOptionsFileParserException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         Files.createDirectory(config.resolve("jvm.options.d"));
         Files.write(
             config.resolve("jvm.options"),
@@ -217,7 +216,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
 
     public void testReadJvmOptionsDirectoryIgnoresFilesNotNamedOptions() throws IOException,
         JvmOptionsParser.JvmOptionsFileParserException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         Files.createFile(config.resolve("jvm.options"));
         Files.createDirectory(config.resolve("jvm.options.d"));
         Files.write(
@@ -232,7 +231,7 @@ public class JvmOptionsParserTests extends LaunchersTestCase {
     }
 
     public void testFileContainsInvalidLinesThrowsParserException() throws IOException {
-        final Path config = newTempDir();
+        final Path config = createTempDir();
         final Path rootJvmOptions = config.resolve("jvm.options");
         Files.write(rootJvmOptions, List.of("XX:+UseG1GC"), StandardOpenOption.CREATE_NEW, StandardOpenOption.APPEND);
         try {

+ 0 - 31
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/LaunchersTestCase.java

@@ -1,31 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
- * in compliance with, at your election, the Elastic License 2.0 or the Server
- * Side Public License, v 1.
- */
-
-package org.elasticsearch.server.cli;
-
-import com.carrotsearch.randomizedtesting.JUnit3MethodProvider;
-import com.carrotsearch.randomizedtesting.MixWithSuiteName;
-import com.carrotsearch.randomizedtesting.RandomizedTest;
-import com.carrotsearch.randomizedtesting.annotations.SeedDecorators;
-import com.carrotsearch.randomizedtesting.annotations.TestMethodProviders;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakAction;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakGroup;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakZombies;
-import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
-
-@TestMethodProviders({ JUnit3MethodProvider.class })
-@SeedDecorators({ MixWithSuiteName.class })
-@ThreadLeakScope(ThreadLeakScope.Scope.SUITE)
-@ThreadLeakGroup(ThreadLeakGroup.Group.MAIN)
-@ThreadLeakAction({ ThreadLeakAction.Action.WARN, ThreadLeakAction.Action.INTERRUPT })
-@ThreadLeakZombies(ThreadLeakZombies.Consequence.IGNORE_REMAINING_TESTS)
-@ThreadLeakLingering(linger = 5000)
-@TimeoutSuite(millis = 2 * 60 * 60 * 1000)
-abstract class LaunchersTestCase extends RandomizedTest {}

+ 6 - 1
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/MachineDependentHeapTests.java

@@ -8,6 +8,9 @@
 
 package org.elasticsearch.server.cli;
 
+import org.elasticsearch.test.ESTestCase;
+import org.elasticsearch.test.ESTestCase.WithoutSecurityManager;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -24,7 +27,9 @@ import static org.hamcrest.Matchers.containsInAnyOrder;
 import static org.hamcrest.Matchers.empty;
 import static org.junit.Assert.assertThat;
 
-public class MachineDependentHeapTests extends LaunchersTestCase {
+// TODO: rework these tests to mock jvm option finder so they can run with security manager, no forking needed
+@WithoutSecurityManager
+public class MachineDependentHeapTests extends ESTestCase {
 
     public void testDefaultHeapSize() throws Exception {
         MachineDependentHeap heap = new MachineDependentHeap(systemMemoryInGigabytes(8));

+ 3 - 1
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/NodeRoleParserTests.java

@@ -8,6 +8,8 @@
 
 package org.elasticsearch.server.cli;
 
+import org.elasticsearch.test.ESTestCase;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -22,7 +24,7 @@ import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertThat;
 
-public class NodeRoleParserTests extends LaunchersTestCase {
+public class NodeRoleParserTests extends ESTestCase {
 
     public void testMasterOnlyNode() throws IOException {
         MachineDependentHeap.MachineNodeRole nodeRole = parseConfig(sb -> sb.append("node.roles: [master]"));

+ 3 - 1
distribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/OverridableSystemMemoryInfoTests.java

@@ -8,13 +8,15 @@
 
 package org.elasticsearch.server.cli;
 
+import org.elasticsearch.test.ESTestCase;
+
 import java.util.List;
 
 import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
-public class OverridableSystemMemoryInfoTests extends LaunchersTestCase {
+public class OverridableSystemMemoryInfoTests extends ESTestCase {
 
     private static final long FALLBACK = -1L;