Skip to content

Commit

Permalink
Fix jvm ergonomics tests (elastic#106969)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst authored Apr 2, 2024
1 parent 1e253a0 commit e39fd58
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

package org.elasticsearch.server.cli;

import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -18,11 +17,13 @@
import org.elasticsearch.test.ESTestCase.WithoutSecurityManager;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsString;
Expand All @@ -41,7 +42,6 @@

@WithoutSecurityManager
@SuppressFileSystems("*")
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/106554")
public class JvmErgonomicsTests extends ESTestCase {

public void testExtractValidHeapSizeUsingXmx() throws Exception {
Expand Down Expand Up @@ -193,18 +193,21 @@ public void testConcGCThreadsNotSetBasedOnProcessors() throws Exception {
Settings.Builder nodeSettingsBuilder = Settings.builder()
.put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), DiscoveryNodeRole.SEARCH_ROLE.roleName());
if (randomBoolean()) {
nodeSettingsBuilder.put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), randomBoolean() ? between(1, 3) : between(6, 100));
int maxProcessors = Runtime.getRuntime().availableProcessors();
List<Integer> possibleProcessors = new ArrayList<>();
IntStream.range(1, maxProcessors + 1).filter(i -> i < 4 || i > 5).forEach(possibleProcessors::add);
nodeSettingsBuilder.put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), randomFrom(possibleProcessors));
}
assertThat(JvmErgonomics.choose(List.of(), nodeSettingsBuilder.build()), everyItem(not(startsWith("-XX:ConcGCThreads="))));
}

public void testConcGCThreadsNotSetBasedOnRoles() throws Exception {
Settings.Builder nodeSettingsBuilder = Settings.builder().put(EsExecutors.NODE_PROCESSORS_SETTING.getKey(), between(4, 5));
if (randomBoolean()) {
nodeSettingsBuilder.put(
NodeRoleSettings.NODE_ROLES_SETTING.getKey(),
randomValueOtherThan(DiscoveryNodeRole.SEARCH_ROLE, () -> randomFrom(DiscoveryNodeRole.roles())).roleName()
);
List<DiscoveryNodeRole> possibleRoles = new ArrayList<>(DiscoveryNodeRole.roles());
possibleRoles.remove(DiscoveryNodeRole.SEARCH_ROLE);
possibleRoles.remove(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE);
nodeSettingsBuilder.put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), randomFrom(possibleRoles).roleName());
}
assertThat(JvmErgonomics.choose(List.of(), nodeSettingsBuilder.build()), everyItem(not(startsWith("-XX:ConcGCThreads="))));

Expand All @@ -228,14 +231,17 @@ public void testMinimumNewSizeNotSetBasedOnHeap() throws Exception {
}

public void testMinimumNewSizeNotSetBasedOnRoles() throws Exception {
Settings nodeSettings = randomBoolean()
? Settings.EMPTY
: Settings.builder()
.put(
NodeRoleSettings.NODE_ROLES_SETTING.getKey(),
randomValueOtherThan(DiscoveryNodeRole.SEARCH_ROLE, () -> randomFrom(DiscoveryNodeRole.roles())).roleName()
)
Settings nodeSettings;
if (randomBoolean()) {
nodeSettings = Settings.EMPTY;
} else {
List<DiscoveryNodeRole> possibleRoles = new ArrayList<>(DiscoveryNodeRole.roles());
possibleRoles.remove(DiscoveryNodeRole.SEARCH_ROLE);
possibleRoles.remove(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE);
nodeSettings = Settings.builder()
.put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), randomFrom(possibleRoles).roleName())
.build();
}
List<String> chosen = JvmErgonomics.choose(List.of("-Xmx" + between(1, 4) + "g"), nodeSettings);
assertThat(chosen, everyItem(not(is("-XX:+UnlockExperimentalVMOptions"))));
assertThat(chosen, everyItem(not(startsWith("-XX:G1NewSizePercent="))));
Expand Down

0 comments on commit e39fd58

Please sign in to comment.