From b1cd6b691f94c5405ed013132e02628777fecdcd Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Wed, 27 Jan 2021 13:38:22 +0100 Subject: [PATCH] SOLR-15055: Fix this test to avoid OS dependency. --- .../impl/PlacementPluginIntegrationTest.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java b/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java index 199d7798283..e699af688d0 100644 --- a/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/cluster/placement/impl/PlacementPluginIntegrationTest.java @@ -325,7 +325,18 @@ public class PlacementPluginIntegrationTest extends SolrCloudTestCase { AttributeFetcher attributeFetcher = new AttributeFetcherImpl(cloudManager); NodeMetric someMetricKey = new NodeMetricImpl<>("solr.jvm:system.properties:user.name"); String sysprop = "user.name"; - String sysenv = "PWD"; + Set potentialEnvVars = Set.of("PWD", "TMPDIR", "TMP", "TEMP", "USER", "USERNAME", "HOME"); + + String envVar = null; + for (String env : potentialEnvVars) { + if (System.getenv(env) != null) { + envVar = env; + break; + } + } + if (envVar == null) { + fail("None of the potential env vars exist? " + potentialEnvVars); + } attributeFetcher .fetchFrom(cluster.getLiveNodes()) .requestNodeMetric(NodeMetricImpl.HEAP_USAGE) @@ -336,11 +347,11 @@ public class PlacementPluginIntegrationTest extends SolrCloudTestCase { .requestNodeMetric(NodeMetricImpl.AVAILABLE_PROCESSORS) .requestNodeMetric(someMetricKey) .requestNodeSystemProperty(sysprop) - .requestNodeEnvironmentVariable(sysenv) + .requestNodeEnvironmentVariable(envVar) .requestCollectionMetrics(collection, Set.of(ReplicaMetricImpl.INDEX_SIZE_GB, ReplicaMetricImpl.QUERY_RATE_1MIN, ReplicaMetricImpl.UPDATE_RATE_1MIN)); AttributeValues attributeValues = attributeFetcher.fetchAttributes(); String userName = System.getProperty("user.name"); - String pwd = System.getenv("PWD"); + String envVarValue = System.getenv(envVar); // node metrics for (Node node : cluster.getLiveNodes()) { Optional doubleOpt = attributeValues.getNodeMetric(node, NodeMetricImpl.HEAP_USAGE); @@ -363,9 +374,9 @@ public class PlacementPluginIntegrationTest extends SolrCloudTestCase { Optional syspropOpt = attributeValues.getSystemProperty(node, sysprop); assertTrue("sysprop", syspropOpt.isPresent()); assertEquals("user.name sysprop", userName, syspropOpt.get()); - Optional sysenvOpt = attributeValues.getEnvironmentVariable(node, sysenv); - assertTrue("sysenv", sysenvOpt.isPresent()); - assertEquals("PWD sysenv", pwd, sysenvOpt.get()); + Optional envVarOpt = attributeValues.getEnvironmentVariable(node, envVar); + assertTrue("envVar", envVarOpt.isPresent()); + assertEquals("envVar " + envVar, envVarValue, envVarOpt.get()); } assertTrue(attributeValues.getCollectionMetrics(COLLECTION).isPresent()); CollectionMetrics collectionMetrics = attributeValues.getCollectionMetrics(COLLECTION).get();