mirror of https://github.com/apache/lucene.git
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
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@782403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9eccbc50c3
commit
57adcb5bd8
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue