Skip to content

Commit 20d8107

Browse files
authored
SOLR-17945: fix flaky test CloudHttp2SolrClientTest#testHttpCspPerf (#3742)
1 parent f412bc1 commit 20d8107

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

solr/solrj/src/java/org/apache/solr/client/solrj/impl/BaseHttpClusterStateProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
public abstract class BaseHttpClusterStateProvider implements ClusterStateProvider {
5757
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5858

59+
protected static final String SYS_PROP_CACHE_TIMEOUT_SECONDS = "solr.solrj.cache.timeout.sec";
60+
5961
private String urlScheme;
6062
private List<URL> configuredNodes;
6163
volatile Set<String> liveNodes; // initially null then never null
@@ -65,7 +67,7 @@ public abstract class BaseHttpClusterStateProvider implements ClusterStateProvid
6567
long aliasesTimestamp = 0;
6668

6769
// the liveNodes and aliases cache will be invalidated after 5 secs
68-
private int cacheTimeout = EnvUtils.getPropertyAsInteger("solr.solrj.cache.timeout.sec", 5);
70+
private int cacheTimeout = EnvUtils.getPropertyAsInteger(SYS_PROP_CACHE_TIMEOUT_SECONDS, 5);
6971

7072
volatile boolean liveNodeReloadingScheduled = false;
7173
private final ScheduledExecutorService liveNodeReloadingService =

solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.solr.client.solrj.impl;
1818

19+
import static org.apache.solr.client.solrj.impl.BaseHttpClusterStateProvider.SYS_PROP_CACHE_TIMEOUT_SECONDS;
1920
import static org.apache.solr.client.solrj.impl.CloudSolrClient.RouteResponse;
2021

2122
import java.io.IOException;
@@ -256,6 +257,14 @@ public void testAliasHandling() throws Exception {
256257
@Test
257258
@LogLevel("org.apache.solr.servlet.HttpSolrCall=DEBUG")
258259
public void testHttpCspPerf() throws Exception {
260+
// This ensures CH2SC is caching cluster status by counting the number of logged calls to the
261+
// admin endpoint. Too many calls to CLUSTERSTATUS might mean insufficient caching and
262+
// performance regressions!
263+
264+
// BaseHttpClusterStateProvider has a background job that pre-fetches data from CLUSTERSTATUS
265+
// on timed intervals. This can pollute this test, so we set the interval very high to
266+
// prevent it from running.
267+
System.setProperty(SYS_PROP_CACHE_TIMEOUT_SECONDS, "" + Integer.MAX_VALUE);
259268

260269
String collectionName = "HTTPCSPTEST";
261270
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1)

solr/solrj/src/test/org/apache/solr/client/solrj/impl/ClusterStateProviderTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.solr.client.solrj.impl;
1919

20+
import static org.apache.solr.client.solrj.impl.BaseHttpClusterStateProvider.SYS_PROP_CACHE_TIMEOUT_SECONDS;
2021
import static org.apache.solr.common.util.URLUtil.getNodeNameForBaseUrl;
2122
import static org.hamcrest.Matchers.containsInAnyOrder;
2223
import static org.hamcrest.Matchers.equalTo;
@@ -84,7 +85,7 @@ public static void setupCluster() throws Exception {
8485
.resolve("conf"))
8586
.configure();
8687
cluster.waitForAllNodes(30);
87-
System.setProperty("solr.solrj.cache.timeout.sec", "1");
88+
System.setProperty(SYS_PROP_CACHE_TIMEOUT_SECONDS, "1");
8889
}
8990

9091
@After

0 commit comments

Comments
 (0)