Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

fix test cases using RemoteSearchable to pick a random port instead of hardwiring to 1099, so such tests running at the same time don't conflict

Michael McCandless57adcb5bd8bb
diff --git a/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java b/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
index 687c0b7facb..3ad8b78e6ab 100644
--- a/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
+++ b/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
@@ -21,6 +21,7 @@ import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
@@ -48,9 +49,11 @@ public class TestRemoteCachingWrapperFilter extends LuceneTestCase {
}
private static Searchable lookupRemote() throws Exception {
- return (Searchable)Naming.lookup("//localhost/Searchable");
+ return (Searchable)Naming.lookup("//localhost:" + port + "/Searchable");
}
+ private static int port;
+
private static void startServer() throws Exception {
// construct an index
RAMDirectory indexStore = new RAMDirectory();
@@ -71,10 +74,11 @@ public class TestRemoteCachingWrapperFilter extends LuceneTestCase {
writer.close();
// publish it
- LocateRegistry.createRegistry(1099);
+ port = _TestUtil.getRandomSocketPort();
+ LocateRegistry.createRegistry(port);
Searchable local = new IndexSearcher(indexStore);
RemoteSearchable impl = new RemoteSearchable(local);
- Naming.rebind("//localhost/Searchable", impl);
+ Naming.rebind("//localhost:" + port + "/Searchable", impl);
}
private static void search(Query query, Filter filter, int hitNumber, String typeValue) throws Exception {
diff --git a/src/test/org/apache/lucene/search/TestRemoteSearchable.java b/src/test/org/apache/lucene/search/TestRemoteSearchable.java
index d048c71598e..cf930e6e360 100644
--- a/src/test/org/apache/lucene/search/TestRemoteSearchable.java
+++ b/src/test/org/apache/lucene/search/TestRemoteSearchable.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search;
*/
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter;
@@ -38,7 +39,13 @@ public class TestRemoteSearchable extends LuceneTestCase {
super(name);
}
+ private static int port = -1;
+
private static Searchable getRemote() throws Exception {
+ if (port == -1) {
+ startServer();
+ }
+
try {
return lookupRemote();
} catch (Throwable e) {
@@ -48,7 +55,7 @@ public class TestRemoteSearchable extends LuceneTestCase {
}
private static Searchable lookupRemote() throws Exception {
- return (Searchable)Naming.lookup("//localhost/Searchable");
+ return (Searchable)Naming.lookup("//localhost:" + port + "/Searchable");
}
private static void startServer() throws Exception {
@@ -63,10 +70,11 @@ public class TestRemoteSearchable extends LuceneTestCase {
writer.close();
// publish it
- LocateRegistry.createRegistry(1099);
+ port = _TestUtil.getRandomSocketPort();
+ LocateRegistry.createRegistry(port);
Searchable local = new IndexSearcher(indexStore);
RemoteSearchable impl = new RemoteSearchable(local);
- Naming.rebind("//localhost/Searchable", impl);
+ Naming.rebind("//localhost:" + port + "/Searchable", impl);
}
private static void search(Query query) throws Exception {
diff --git a/src/test/org/apache/lucene/search/TestSort.java b/src/test/org/apache/lucene/search/TestSort.java
index 0be68a31904..4bdbe299eda 100644
--- a/src/test/org/apache/lucene/search/TestSort.java
+++ b/src/test/org/apache/lucene/search/TestSort.java
@@ -44,6 +44,7 @@ import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.DocIdBitSet;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util._TestUtil;
/**
* Unit tests for sorting code.
@@ -1086,18 +1087,21 @@ public class TestSort extends LuceneTestCase implements Serializable {
}
private Searchable lookupRemote () throws Exception {
- return (Searchable) Naming.lookup ("//localhost/SortedSearchable");
+ return (Searchable) Naming.lookup ("//localhost:" + port + "/SortedSearchable");
}
+ private int port = -1;
+
private void startServer () throws Exception {
// construct an index
+ port = _TestUtil.getRandomSocketPort();
Searcher local = getFullIndex();
// local.search (queryA, new Sort());
// publish it
- LocateRegistry.createRegistry (1099);
+ LocateRegistry.createRegistry (port);
RemoteSearchable impl = new RemoteSearchable (local);
- Naming.rebind ("//localhost/SortedSearchable", impl);
+ Naming.rebind ("//localhost:" + port + "/SortedSearchable", impl);
}
}
diff --git a/src/test/org/apache/lucene/util/_TestUtil.java b/src/test/org/apache/lucene/util/_TestUtil.java
index 617e8c8f787..3a7f735f3f4 100644
--- a/src/test/org/apache/lucene/util/_TestUtil.java
+++ b/src/test/org/apache/lucene/util/_TestUtil.java
@@ -26,6 +26,7 @@ import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.store.Directory;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.util.Random;
public class _TestUtil {
@@ -103,4 +104,8 @@ public class _TestUtil {
return buf.toString();
}
+ public static int getRandomSocketPort() {
+ return 1024 + new Random().nextInt(64512);
+ }
+
}