From 6133214b271d976daf644b336b872a7cbbba6dae Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 13 Apr 2016 20:48:41 -0400 Subject: [PATCH 1/4] Pass test JVM arguments to test nodes This commit passes test JVM arguments (from the system property tests.jvm.argline) through to the test nodes that are spun up for integration tests. --- .../groovy/org/elasticsearch/gradle/test/NodeInfo.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy index 6de282b268d..69718f85705 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy @@ -129,11 +129,11 @@ class NodeInfo { args.add("${esScript}") } - env = [ - 'JAVA_HOME' : project.javaHome - ] + env = [ 'JAVA_HOME' : project.javaHome ] args.addAll("-E", "es.node.portsfile=true") - env.put('ES_JAVA_OPTS', config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ")) + String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ") + String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs + env.put('ES_JAVA_OPTS', esJavaOpts) for (Map.Entry property : System.properties.entrySet()) { if (property.getKey().startsWith('es.')) { args.add("-E") From 2d1ec2ee9df1fde3ba43c26376d1ad13e138cde2 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 13 Apr 2016 20:49:35 -0400 Subject: [PATCH 2/4] Remove unused import from NodeInfo.groovy --- .../main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy index 69718f85705..2ff5e333139 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy @@ -19,7 +19,6 @@ package org.elasticsearch.gradle.test import org.apache.tools.ant.taskdefs.condition.Os -import org.elasticsearch.gradle.VersionProperties import org.gradle.api.InvalidUserDataException import org.gradle.api.Project import org.gradle.api.Task From 4b801f54d180752271ecdc58a7f481be508d4d4f Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 13 Apr 2016 20:50:03 -0400 Subject: [PATCH 3/4] Add test that JvmInfo correctly determines G1 GC This commit adds a simple test that JvmInfo is correctly able to determine whether or not G1 GC is running. As the JvmInfo G1 GC logic is only applies to HotSpot, the test is constructed to do the same. The test determines whether or not G1 GC is running by inspecting the test JVM argument line. --- .../elasticsearch/bootstrap/JavaVersion.java | 2 +- .../routing/allocation/ShardStateIT.java | 2 + .../monitor/jvm/JvmInfoTests.java | 61 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/org/elasticsearch/monitor/jvm/JvmInfoTests.java diff --git a/core/src/main/java/org/elasticsearch/bootstrap/JavaVersion.java b/core/src/main/java/org/elasticsearch/bootstrap/JavaVersion.java index c37f37318fa..afc2b77e211 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/JavaVersion.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/JavaVersion.java @@ -25,7 +25,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -class JavaVersion implements Comparable { +public class JavaVersion implements Comparable { private final List version; public List getVersion() { diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java index 65ec13fb2af..3bc8cfa55a1 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java @@ -48,6 +48,8 @@ public class ShardStateIT extends ESIntegTestCase { indicesService.indexService(resolveIndex("test")).getShard(shard).failShard("simulated test failure", null); logger.info("--> waiting for a yellow index"); + // JDK 9 type inference gets confused, so we have to help the + // type inference assertBusy(() -> assertThat(client().admin().cluster().prepareHealth().get().getStatus(), equalTo(ClusterHealthStatus.YELLOW))); diff --git a/core/src/test/java/org/elasticsearch/monitor/jvm/JvmInfoTests.java b/core/src/test/java/org/elasticsearch/monitor/jvm/JvmInfoTests.java new file mode 100644 index 00000000000..7504ae6a34a --- /dev/null +++ b/core/src/test/java/org/elasticsearch/monitor/jvm/JvmInfoTests.java @@ -0,0 +1,61 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.monitor.jvm; + +import org.apache.lucene.util.Constants; +import org.elasticsearch.bootstrap.JavaVersion; +import org.elasticsearch.test.ESTestCase; + +public class JvmInfoTests extends ESTestCase { + + public void testUseG1GC() { + // if we are running on HotSpot, and the test JVM was started + // with UseG1GC, then JvmInfo should successfully report that + // G1GC is enabled + if (Constants.JVM_NAME.contains("HotSpot")) { + assertEquals(Boolean.toString(isG1GCEnabled()), JvmInfo.jvmInfo().useG1GC()); + } else { + assertEquals("unknown", JvmInfo.jvmInfo().useG1GC()); + } + } + + private boolean isG1GCEnabled() { + final String argline = System.getProperty("tests.jvm.argline"); + final boolean g1GCEnabled = flagIsEnabled(argline, "UseG1GC"); + // for JDK 9 the default collector when no collector is specified is G1 GC + final boolean versionIsAtLeastJava9 = JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0; + final boolean noOtherCollectorSpecified = + argline == null || + (!flagIsEnabled(argline, "UseParNewGC") && + !flagIsEnabled(argline, "UseParallelGC") && + !flagIsEnabled(argline, "UseParallelOldGC") && + !flagIsEnabled(argline, "UseSerialGC") && + !flagIsEnabled(argline, "UseConcMarkSweepGC")); + return g1GCEnabled || (versionIsAtLeastJava9 && noOtherCollectorSpecified); + } + + private boolean flagIsEnabled(String argline, String flag) { + final boolean containsPositiveFlag = argline != null && argline.contains("-XX:+" + flag); + if (!containsPositiveFlag) return false; + final int index = argline.lastIndexOf(flag); + return argline.charAt(index - 1) == '+'; + } + +} From 79d3415210247fad7970b4088bfef0391ff189b6 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 13 Apr 2016 21:38:17 -0400 Subject: [PATCH 4/4] Help JDK 9 type inference in ShardStateIT.java The JDK 9 compiler type inference gets confused, so we need to help it here. --- .../cluster/routing/allocation/ShardStateIT.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java index 3bc8cfa55a1..7e05448bf91 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java @@ -50,8 +50,8 @@ public class ShardStateIT extends ESIntegTestCase { logger.info("--> waiting for a yellow index"); // JDK 9 type inference gets confused, so we have to help the // type inference - assertBusy(() -> assertThat(client().admin().cluster().prepareHealth().get().getStatus(), - equalTo(ClusterHealthStatus.YELLOW))); + assertBusy(((Runnable) () -> assertThat(client().admin().cluster().prepareHealth().get().getStatus(), + equalTo(ClusterHealthStatus.YELLOW)))); final long term0 = shard == 0 ? 2 : 1; final long term1 = shard == 1 ? 2 : 1;