Search in sources :

Example 1 with ClientConnectionResponse

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

the class AutoConnectionSourceImplJUnitTest method testNoServers.

@Test
public void testNoServers() throws Exception {
    startFakeLocator();
    handler.nextConnectionResponse = new ClientConnectionResponse(null);
    assertEquals(null, source.findServer(null));
}
Also used : ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with ClientConnectionResponse

use of org.apache.geode.cache.client.internal.locator.ClientConnectionResponse 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 3 with ClientConnectionResponse

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

the class AutoConnectionSourceImpl method findServer.

public ServerLocation findServer(Set excludedServers) {
    if (PoolImpl.TEST_DURABLE_IS_NET_DOWN) {
        return null;
    }
    ClientConnectionRequest request = new ClientConnectionRequest(excludedServers, serverGroup);
    ClientConnectionResponse response = (ClientConnectionResponse) queryLocators(request);
    if (response == null) {
        // getLogger().warning("Unable to connect to any locators in the list " + locators);
        throw new NoAvailableLocatorsException("Unable to connect to any locators in the list " + locators);
    }
    return response.getServer();
}
Also used : ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) ClientConnectionRequest(org.apache.geode.cache.client.internal.locator.ClientConnectionRequest) NoAvailableLocatorsException(org.apache.geode.cache.client.NoAvailableLocatorsException)

Example 4 with ClientConnectionResponse

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

the class AutoConnectionSourceImplJUnitTest method testDiscoverServers.

@Test
public void testDiscoverServers() throws Exception {
    startFakeLocator();
    ServerLocation loc1 = new ServerLocation("localhost", 4423);
    handler.nextConnectionResponse = new ClientConnectionResponse(loc1);
    assertEquals(loc1, source.findServer(null));
}
Also used : ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with ClientConnectionResponse

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

the class LocatorLoadBalancingDUnitTest method testEstimation.

/**
   * Test that the locator will properly estimate the load for servers when it receives connection
   * requests.
   */
@Test
public void testEstimation() throws IOException, ClassNotFoundException {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    int serverPort = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    ServerLoad expectedLoad = new ServerLoad(2 / 800f, 1 / 800.0f, 0f, 1f);
    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
    Map expected = new HashMap();
    expected.put(expectedLocation, expectedLoad);
    SocketCreatorFactory.setDistributionConfig(new DistributionConfigImpl(new Properties()));
    ClientConnectionResponse response;
    response = (ClientConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000);
    Assert.assertEquals(expectedLocation, response.getServer());
    response = (ClientConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new ClientConnectionRequest(Collections.EMPTY_SET, null), 10000, true);
    Assert.assertEquals(expectedLocation, response.getServer());
    // we expect that the connection load load will be 2 * the loadPerConnection
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    QueueConnectionResponse response2;
    response2 = (QueueConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new QueueConnectionRequest(null, 2, Collections.EMPTY_SET, null, false), 10000, true);
    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
    response2 = (QueueConnectionResponse) new TcpClient().requestToServer(InetAddress.getByName(NetworkUtils.getServerHostName(host)), locatorPort, new QueueConnectionRequest(null, 5, Collections.EMPTY_SET, null, false), 10000, true);
    Assert.assertEquals(Collections.singletonList(expectedLocation), response2.getServers());
    // we expect that the queue load will increase by 2
    expectedLoad.setSubscriptionConnectionLoad(2f);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
}
Also used : QueueConnectionRequest(org.apache.geode.cache.client.internal.locator.QueueConnectionRequest) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) HashMap(java.util.HashMap) ClientConnectionRequest(org.apache.geode.cache.client.internal.locator.ClientConnectionRequest) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) ServerLoad(org.apache.geode.cache.server.ServerLoad) ClientConnectionResponse(org.apache.geode.cache.client.internal.locator.ClientConnectionResponse) DistributionConfigImpl(org.apache.geode.distributed.internal.DistributionConfigImpl) TcpClient(org.apache.geode.distributed.internal.tcpserver.TcpClient) VM(org.apache.geode.test.dunit.VM) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) HashMap(java.util.HashMap) Map(java.util.Map) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ClientConnectionResponse (org.apache.geode.cache.client.internal.locator.ClientConnectionResponse)6 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 Test (org.junit.Test)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 NoAvailableLocatorsException (org.apache.geode.cache.client.NoAvailableLocatorsException)2 ClientConnectionRequest (org.apache.geode.cache.client.internal.locator.ClientConnectionRequest)2 TcpClient (org.apache.geode.distributed.internal.tcpserver.TcpClient)2 ConnectException (java.net.ConnectException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ClientReplacementRequest (org.apache.geode.cache.client.internal.locator.ClientReplacementRequest)1 LocatorListResponse (org.apache.geode.cache.client.internal.locator.LocatorListResponse)1 QueueConnectionRequest (org.apache.geode.cache.client.internal.locator.QueueConnectionRequest)1 QueueConnectionResponse (org.apache.geode.cache.client.internal.locator.QueueConnectionResponse)1 ServerLoad (org.apache.geode.cache.server.ServerLoad)1 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)1 TcpServer (org.apache.geode.distributed.internal.tcpserver.TcpServer)1