Skip to content

Commit

Permalink
SOLR-16390: fix flaky test ClusterPropsAPITest.testClusterPropertyOps…
Browse files Browse the repository at this point in the history
…AllGood (apache#2901)

The test fails when SSL in enabled, because of testing framework that
set 'urlScheme' cluster property. This change updates the test to ignore
existing cluster properties.
  • Loading branch information
psalagnac authored Dec 10, 2024
1 parent 2d3a8d9 commit e105547
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.solr.handler.admin.api;

import static org.apache.solr.common.util.Utils.getObjectByPath;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;

import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -86,11 +88,14 @@ public void tearDown() throws Exception {
@Test
public void testClusterPropertyOpsAllGood() throws Exception {
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
// List Properties, confirm there aren't any
// List Properties, confirm the test property does not exist
// This ignores eventually existing other properties
Object o =
Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals(0, ((List<?>) getObjectByPath(o, true, "clusterProperties")).size());
@SuppressWarnings("unchecked")
List<String> initProperties = (List<String>) getObjectByPath(o, true, "clusterProperties");
assertThat(initProperties, not(hasItem(testClusterProperty)));

// Create a single cluster property
String path = baseUrlV2ClusterProps + "/" + testClusterProperty;
Expand All @@ -100,13 +105,12 @@ public void testClusterPropertyOpsAllGood() throws Exception {
o = Utils.executeHttpMethod(client.getHttpClient(), path, Utils.JSONCONSUMER, httpPut);
assertNotNull(o);

// List Properties, this time there should be 1
// List Properties, this time there should be the just added property
o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals(1, ((List<?>) getObjectByPath(o, true, "clusterProperties")).size());
assertEquals(
testClusterProperty,
(String) ((List<?>) getObjectByPath(o, true, "clusterProperties")).get(0));
@SuppressWarnings("unchecked")
List<String> updatedProperties = (List<String>) getObjectByPath(o, true, "clusterProperties");
assertThat(updatedProperties, hasItem(testClusterProperty));

// Fetch Cluster Property
// Same path as used in the Create step above
Expand All @@ -122,10 +126,12 @@ public void testClusterPropertyOpsAllGood() throws Exception {
o = Utils.executeHttpMethod(client.getHttpClient(), path, Utils.JSONCONSUMER, httpDelete);
assertNotNull(o);

// List Properties, should be back to 0
// List Properties, the test property should be gone
o = Utils.executeGET(client.getHttpClient(), baseUrlV2ClusterProps, Utils.JSONCONSUMER);
assertNotNull(o);
assertEquals(0, ((List<?>) getObjectByPath(o, true, "clusterProperties")).size());
@SuppressWarnings("unchecked")
List<String> clearedProperties = (List<String>) getObjectByPath(o, true, "clusterProperties");
assertThat(clearedProperties, not(hasItem(testClusterProperty)));
}
}

Expand Down

0 comments on commit e105547

Please sign in to comment.