use of org.apache.geode.distributed.internal.tcpserver.TcpServer in project geode by apache.
the class AutoConnectionSourceImplJUnitTest method startFakeLocator.
private void startFakeLocator() throws UnknownHostException, IOException, InterruptedException {
server = new TcpServer(port, InetAddress.getLocalHost(), null, null, handler, new FakeHelper(), Thread.currentThread().getThreadGroup(), "Tcp Server");
server.start();
Thread.sleep(500);
}
use of org.apache.geode.distributed.internal.tcpserver.TcpServer in project geode by apache.
the class AutoConnectionSourceImplJUnitTest method testDiscoverLocators.
@Test
public void testDiscoverLocators() throws Exception {
startFakeLocator();
int secondPort = AvailablePortHelper.getRandomAvailableTCPPort();
TcpServer server2 = new TcpServer(secondPort, InetAddress.getLocalHost(), null, null, handler, new FakeHelper(), Thread.currentThread().getThreadGroup(), "tcp server");
server2.start();
try {
ArrayList locators = new ArrayList();
locators.add(new ServerLocation(InetAddress.getLocalHost().getHostName(), secondPort));
handler.nextLocatorListResponse = new LocatorListResponse(locators, false);
Thread.sleep(500);
try {
new TcpClient().stop(InetAddress.getLocalHost(), port);
} catch (ConnectException ignore) {
// must not be running
}
server.join(1000);
ServerLocation server1 = new ServerLocation("localhost", 10);
handler.nextConnectionResponse = new ClientConnectionResponse(server1);
assertEquals(server1, source.findServer(null));
} finally {
try {
new TcpClient().stop(InetAddress.getLocalHost(), secondPort);
} catch (ConnectException ignore) {
// must not be running
}
server.join(60 * 1000);
}
}
Aggregations