Use the host returned by the Server when connecting to it

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1491140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-06-09 05:01:08 +00:00
parent b0aef6e46d
commit a987468500
2 changed files with 11 additions and 8 deletions

View File

@ -17,7 +17,6 @@ package org.apache.lucene.replicator;
* limitations under the License.
*/
import java.net.SocketException;
import java.util.Random;
import org.apache.http.conn.ClientConnectionManager;
@ -125,12 +124,14 @@ public abstract class ReplicatorTestCase extends LuceneTestCase {
return server;
}
/**
* Returns a {@link Server}'s port. This method assumes that no
* {@link Connector}s were added to the Server besides the default one.
*/
public static int serverPort(Server httpServer) {
return httpServer.getConnectors()[0].getLocalPort();
/** Returns a {@link Server}'s port. */
public static int serverPort(Server server) {
return server.getConnectors()[0].getLocalPort();
}
/** Returns a {@link Server}'s host. */
public static String serverHost(Server server) {
return server.getConnectors()[0].getHost();
}
/**

View File

@ -50,6 +50,7 @@ public class HttpReplicatorTest extends ReplicatorTestCase {
private DirectoryReader reader;
private Server server;
private int port;
private String host;
private Directory serverIndexDir, handlerIndexDir;
private void startServer() throws Exception {
@ -59,6 +60,7 @@ public class HttpReplicatorTest extends ReplicatorTestCase {
replicationHandler.addServletWithMapping(servlet, ReplicationService.REPLICATION_CONTEXT + "/*");
server = newHttpServer(replicationHandler);
port = serverPort(server);
host = serverHost(server);
}
@Before
@ -103,7 +105,7 @@ public class HttpReplicatorTest extends ReplicatorTestCase {
@Test
public void testBasic() throws Exception {
Replicator replicator = new HttpReplicator("127.0.0.1", port, ReplicationService.REPLICATION_CONTEXT + "/s1",
Replicator replicator = new HttpReplicator(host, port, ReplicationService.REPLICATION_CONTEXT + "/s1",
getClientConnectionManager());
ReplicationClient client = new ReplicationClient(replicator, new IndexReplicationHandler(handlerIndexDir, null),
new PerSessionDirectoryFactory(clientWorkDir));