You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by mi...@apache.org on 2009/06/07 17:47:21 UTC
svn commit: r782403 - in /lucene/java/trunk/src/test/org/apache/lucene:
search/TestRemoteCachingWrapperFilter.java search/TestRemoteSearchable.java
search/TestSort.java util/_TestUtil.java
Author: mikemccand
Date: Sun Jun 7 15:47:21 2009
New Revision: 782403
URL: http://svn.apache.org/viewvc?rev=782403&view=rev
Log:
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
Modified:
lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteSearchable.java
lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java?rev=782403&r1=782402&r2=782403&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java Sun Jun 7 15:47:21 2009
@@ -21,6 +21,7 @@
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 @@
}
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 @@
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 {
Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteSearchable.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteSearchable.java?rev=782403&r1=782402&r2=782403&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteSearchable.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestRemoteSearchable.java Sun Jun 7 15:47:21 2009
@@ -18,6 +18,7 @@
*/
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 @@
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 @@
}
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 @@
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 {
Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java?rev=782403&r1=782402&r2=782403&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestSort.java Sun Jun 7 15:47:21 2009
@@ -44,6 +44,7 @@
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 @@
}
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);
}
}
Modified: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java?rev=782403&r1=782402&r2=782403&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java Sun Jun 7 15:47:21 2009
@@ -26,6 +26,7 @@
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 @@
return buf.toString();
}
+ public static int getRandomSocketPort() {
+ return 1024 + new Random().nextInt(64512);
+ }
+
}