Search in sources :

Example 1 with LocatorListResponse

use of org.apache.geode.cache.client.internal.locator.LocatorListResponse 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)

Example 2 with LocatorListResponse

use of org.apache.geode.cache.client.internal.locator.LocatorListResponse in project geode by apache.

the class AutoConnectionSourceImplJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    DistributedSystem ds = DistributedSystem.connect(props);
    cache = CacheFactory.create(ds);
    poolStats = new PoolStats(ds, "pool");
    port = AvailablePortHelper.getRandomAvailableTCPPort();
    handler = new FakeHandler();
    ArrayList responseLocators = new ArrayList();
    responseLocators.add(new ServerLocation(InetAddress.getLocalHost().getHostName(), port));
    handler.nextLocatorListResponse = new LocatorListResponse(responseLocators, false);
    // very irritating, the SystemTimer requires having a distributed system
    Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, "");
    background = Executors.newSingleThreadScheduledExecutor();
    List /* <InetSocketAddress> */
    locators = new ArrayList();
    locators.add(new InetSocketAddress(InetAddress.getLocalHost(), port));
    source = new AutoConnectionSourceImpl(locators, "", 60 * 1000);
    source.start(pool);
}
Also used : LocatorListResponse(org.apache.geode.cache.client.internal.locator.LocatorListResponse) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Properties(java.util.Properties) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) PoolStats(org.apache.geode.internal.cache.PoolStats) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)2 LocatorListResponse (org.apache.geode.cache.client.internal.locator.LocatorListResponse)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 ConnectException (java.net.ConnectException)1 InetSocketAddress (java.net.InetSocketAddress)1 List (java.util.List)1 Properties (java.util.Properties)1 ClientConnectionResponse (org.apache.geode.cache.client.internal.locator.ClientConnectionResponse)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 TcpClient (org.apache.geode.distributed.internal.tcpserver.TcpClient)1 TcpServer (org.apache.geode.distributed.internal.tcpserver.TcpServer)1 PoolStats (org.apache.geode.internal.cache.PoolStats)1 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RestoreSystemProperties (org.junit.contrib.java.lang.system.RestoreSystemProperties)1