Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-14050: clean up tests use of network addresses

Robert Muirdc031ea382d0
diff --git a/lucene/tools/junit4/solr-tests.policy b/lucene/tools/junit4/solr-tests.policy
index 00dae246fed..816c7c382e5 100644
--- a/lucene/tools/junit4/solr-tests.policy
+++ b/lucene/tools/junit4/solr-tests.policy
@@ -51,13 +51,14 @@ grant {
permission java.nio.file.LinkPermission "hard";
- // all possibilities of accepting/binding connections on localhost with ports >=1024:
- permission java.net.SocketPermission "localhost:1024-", "accept,listen";
- permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen";
- permission java.net.SocketPermission "[::1]:1024-", "accept,listen";
-
- // Allow connecting to the internet anywhere
- permission java.net.SocketPermission "*", "connect,resolve";
+ // all possibilities of accepting/binding/connections on localhost with ports >=1024:
+ permission java.net.SocketPermission "localhost:1024-", "accept,listen,connect,resolve";
+ permission java.net.SocketPermission "127.0.0.1:1024-", "accept,listen,connect,resolve";
+ permission java.net.SocketPermission "[::1]:1024-", "accept,listen,connect,resolve";
+ // "dead hosts", we try to keep it fast
+ permission java.net.SocketPermission "[::1]:4", "connect,resolve";
+ permission java.net.SocketPermission "[::1]:6", "connect,resolve";
+ permission java.net.SocketPermission "[::1]:8", "connect,resolve";
// Basic permissions needed for Lucene to work:
permission java.util.PropertyPermission "*", "read,write";
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
index 0bf9cc2b71e..9c4e957711f 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSolrEntityProcessorEndToEnd.java
@@ -54,7 +54,7 @@ public class TestSolrEntityProcessorEndToEnd extends AbstractDataImportHandlerTe
private static final String SOURCE_CONF_DIR = "dih" + File.separator + "solr" + File.separator + "collection1" + File.separator + "conf" + File.separator;
private static final String ROOT_DIR = "dih" + File.separator + "solr" + File.separator;
- private static final String DEAD_SOLR_SERVER = "http://[ff01::114]:33332/solr";
+ private static final String DEAD_SOLR_SERVER = "http://" + DEAD_HOST_1 + "/solr";
private static final List<Map<String,Object>> DB_DOCS = new ArrayList<>();
private static final List<Map<String,Object>> SOLR_DOCS = new ArrayList<>();
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
index a149b33ab4a..c8e4457dcc3 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestSolrCloudWithSecureImpersonation.java
@@ -77,7 +77,7 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "noGroups.hosts", "*");
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "anyHostAnyUser.groups", "*");
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "anyHostAnyUser.hosts", "*");
- filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.hosts", "1.1.1.1.1.1");
+ filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.hosts", DEAD_HOST_1);
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "wrongHost.groups", "*");
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "noHosts.groups", "*");
filterProps.put(KerberosPlugin.IMPERSONATOR_PREFIX + "localHostAnyGroup.groups", "*");
@@ -290,7 +290,7 @@ public class TestSolrCloudWithSecureImpersonation extends SolrTestCaseJ4 {
public void testProxyInvalidRemote() throws Exception {
HttpSolrClient.RemoteSolrException e = expectThrows(HttpSolrClient.RemoteSolrException.class,
() -> {
- String invalidIpAddress = "-127.-128";
+ String invalidIpAddress = DEAD_HOST_2;
solrClient.request(getProxyRequest("localHostAnyGroup","bar", "[ff01::114]", invalidIpAddress));
});
assertTrue(e.getMessage().contains(getExpectedHostExMsg("localHostAnyGroup")));
diff --git a/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
index b0836f1273b..f648535f9ae 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/CustomTermsComponentTest.java
@@ -155,7 +155,7 @@ public class CustomTermsComponentTest extends ShardsWhitelistTest {
// this case should fail
findAndCheckTerms(cluster, collection,
defaultHandlerName,
- shards + ",http://[ff01::114]:33332", // ... with specified shards with one invalid
+ shards + ",http://" + DEAD_HOST_1, // ... with specified shards with one invalid
(random().nextBoolean() ? null : f1), v1,
(random().nextBoolean() ? null : f2), v2,
"No live SolrServers available to handle this request");
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
index 49b7ece0400..e3958250af3 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedDebugComponentTest.java
@@ -388,7 +388,7 @@ public class DistributedDebugComponentTest extends SolrJettyTestBase {
}
public void testTolerantSearch() throws SolrServerException, IOException {
- String badShard = "[ff01::0083]:3334";
+ String badShard = DEAD_HOST_1;
SolrQuery query = new SolrQuery();
query.setQuery("*:*");
query.set("debug", "true");
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
index e85a29530a9..a0fb090230c 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java
@@ -2972,7 +2972,7 @@ public class TestJsonFacets extends SolrTestCaseHS {
public void testTolerant() throws Exception {
initServers();
Client client = servers.getClient(random().nextInt());
- client.queryDefaults().set("shards", servers.getShards() + ",[ff01::114]:33332/ignore_exception");
+ client.queryDefaults().set("shards", servers.getShards() + "," + DEAD_HOST_1 + "/ignore_exception");
indexSimple(client);
try {
diff --git a/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java b/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
index 5ce7527223d..d603fd2736e 100644
--- a/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
+++ b/solr/core/src/test/org/apache/solr/security/hadoop/TestImpersonationWithHadoopAuth.java
@@ -63,7 +63,7 @@ public class TestImpersonationWithHadoopAuth extends SolrCloudTestCase {
proxyUserConfigs.put("proxyuser.noGroups.hosts", "*");
proxyUserConfigs.put("proxyuser.anyHostAnyUser.hosts", "*");
proxyUserConfigs.put("proxyuser.anyHostAnyUser.groups", "*");
- proxyUserConfigs.put("proxyuser.wrongHost.hosts", "1.1.1.1.1.1");
+ proxyUserConfigs.put("proxyuser.wrongHost.hosts", DEAD_HOST_1);
proxyUserConfigs.put("proxyuser.wrongHost.groups", "*");
proxyUserConfigs.put("proxyuser.noHosts.groups", "*");
proxyUserConfigs.put("proxyuser.localHostAnyGroup.hosts",
diff --git a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
index f6d7087d1a9..36c511f4f8a 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrCmdDistributorTest.java
@@ -795,7 +795,7 @@ public class SolrCmdDistributorTest extends BaseDistributedSearchTestCase {
ArrayList<Node> nodes = new ArrayList<>();
- ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, "[ff01::114]:33332" + context, ZkStateReader.CORE_NAME_PROP, "");
+ ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, DEAD_HOST_1 + context, ZkStateReader.CORE_NAME_PROP, "");
ForwardNode retryNode = new ForwardNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1", 5) {
@Override
public boolean checkRetry(Error err) {
diff --git a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
index b9eaa632263..39036ef7d7f 100644
--- a/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
+++ b/solr/core/src/test/org/apache/solr/util/SimplePostToolTest.java
@@ -24,6 +24,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
@@ -37,9 +38,7 @@ import org.junit.Test;
/**
* NOTE: do *not* use real hostnames, not even "example.com", in this test.
*
- * Even though a MockPageFetcher is used to prevent real HTTP requests from being
- * executed, the use of the URL class in SimplePostTool causes attempted resolution of
- * the hostnames.
+ * A MockPageFetcher is used to prevent real HTTP requests from being executed.
*/
public class SimplePostToolTest extends SolrTestCaseJ4 {
@@ -173,7 +172,7 @@ public class SimplePostToolTest extends SolrTestCaseJ4 {
assertEquals(3, num);
// Without respecting robots.txt
- t_web.pageFetcher.robotsCache.clear();
+ t_web.pageFetcher.robotsCache.put("[ff01::114]", Collections.emptyList());
t_web.recursive = 5;
num = t_web.postWebPages(new String[] {"http://[ff01::114]/#removeme"}, 0, null);
assertEquals(6, num);
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
index c894a6a251f..9dbb03c0551 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExceptionTest.java
@@ -20,6 +20,7 @@ import static org.apache.solr.SolrTestCaseJ4.getHttpSolrClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.solr.SolrTestCase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.junit.Test;
@@ -43,7 +44,7 @@ public class SolrExceptionTest extends SolrTestCase {
// switched to a local address to avoid going out on the net, ns lookup issues, etc.
// set a 1ms timeout to let the connection fail faster.
httpClient = HttpClientUtil.createClient(null);
- try (HttpSolrClient client = getHttpSolrClient("http://[ff01::114]:11235/solr/", httpClient, 1)) {
+ try (HttpSolrClient client = getHttpSolrClient("http://" + SolrTestCaseJ4.DEAD_HOST_1 + "/solr/", httpClient, 1)) {
SolrQuery query = new SolrQuery("test123");
client.query(query);
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
index 74b02cb4da7..c398227d527 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudHttp2SolrClientTest.java
@@ -752,7 +752,7 @@ public class CloudHttp2SolrClientTest extends SolrCloudTestCase {
@Test
public void testShutdown() throws IOException {
- try (CloudSolrClient client = getCloudSolrClient("[ff01::114]:33332")) {
+ try (CloudSolrClient client = getCloudSolrClient(DEAD_HOST_1)) {
client.setZkConnectTimeout(100);
client.connect();
fail("Expected exception");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
index 57050ce2e43..943b26ca645 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudSolrClientTest.java
@@ -738,7 +738,7 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
@Test
public void testShutdown() throws IOException {
- try (CloudSolrClient client = getCloudSolrClient("[ff01::114]:33332")) {
+ try (CloudSolrClient client = getCloudSolrClient(DEAD_HOST_1)) {
client.setZkConnectTimeout(100);
SolrException ex = expectThrows(SolrException.class, client::connect);
assertTrue(ex.getCause() instanceof TimeoutException);
diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
index a881084f75d..f0ab629a2be 100644
--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java
@@ -223,9 +223,9 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {
*/
protected BaseDistributedSearchTestCase(final String context) {
this.context = context;
- this.deadServers = new String[] {"[ff01::114]:33332" + context,
- "[ff01::083]:33332" + context,
- "[ff01::213]:33332" + context};
+ this.deadServers = new String[] {DEAD_HOST_1 + context,
+ DEAD_HOST_2 + context,
+ DEAD_HOST_3 + context};
}
private final static int DEFAULT_MAX_SHARD_COUNT = 3;
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index ac8deaaf35f..585f3bc8e39 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -377,6 +377,22 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase {
}
}
+ /**
+ * a "dead" host, if you try to connect to it, it will likely fail fast
+ * please consider using mocks and not real networking to simulate failure
+ */
+ public static final String DEAD_HOST_1 = "[::1]:4";
+ /**
+ * a "dead" host, if you try to connect to it, it will likely fail fast
+ * please consider using mocks and not real networking to simulate failure
+ */
+ public static final String DEAD_HOST_2 = "[::1]:6";
+ /**
+ * a "dead" host, if you try to connect to it, it will likely fail fast
+ * please consider using mocks and not real networking to simulate failure
+ */
+ public static final String DEAD_HOST_3 = "[::1]:8";
+
/** Assumes that Mockito/Bytebuddy is available and can be used to mock classes (e.g., fails if Java version is too new). */
public static void assumeWorkingMockito() {
// we use reflection here, because we do not have ByteBuddy/Mockito in all modules and the test framework!