Search in sources :

Example 1 with TcpServer

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);
}
Also used : TcpServer(org.apache.geode.distributed.internal.tcpserver.TcpServer)

Example 2 with TcpServer

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);
    }
}
Also used : LocatorListResponse(org.apache.geode.cache.client.internal.locator.LocatorListResponse) ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) ArrayList(java.util.ArrayList) TcpServer(org.apache.geode.distributed.internal.tcpserver.TcpServer) ConnectException(java.net.ConnectException) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

TcpServer (org.apache.geode.distributed.internal.tcpserver.TcpServer)2 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 ClientConnectionResponse (org.apache.geode.cache.client.internal.locator.ClientConnectionResponse)1 LocatorListResponse (org.apache.geode.cache.client.internal.locator.LocatorListResponse)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 TcpClient (org.apache.geode.distributed.internal.tcpserver.TcpClient)1 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Test (org.junit.Test)1