Search in sources :

Example 1 with QueueConnectionResponse

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

the class SerialGatewaySenderOperationsDUnitTest method testGatewaySenderNotRegisteredAsCacheServer.

@Test
public void testGatewaySenderNotRegisteredAsCacheServer() {
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    createCacheInVMs(nyPort, vm2, vm3);
    createReceiverInVMs(vm2, vm3);
    createCacheInVMs(lnPort, vm4, vm5);
    vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 10, false, true, null, true));
    vm5.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 10, false, true, null, true));
    startSenderInVMs("ln", vm4, vm5);
    SerializableRunnable check = new SerializableRunnable("assert no cache servers") {

        public void run() {
            InternalLocator inl = (InternalLocator) Locator.getLocator();
            ServerLocator server = inl.getServerLocatorAdvisee();
            LogWriterUtils.getLogWriter().info("Server load map is " + server.getLoadMap());
            assertTrue("expected an empty map but found " + server.getLoadMap(), server.getLoadMap().isEmpty());
            QueueConnectionRequest request = new QueueConnectionRequest(ClientProxyMembershipID.getNewProxyMembership(InternalDistributedSystem.getConnectedInstance()), 1, new HashSet<>(), "", false);
            QueueConnectionResponse response = (QueueConnectionResponse) server.processRequest(request);
            assertTrue("expected no servers but found " + response.getServers(), response.getServers().isEmpty());
        }
    };
    vm0.invoke(check);
    vm1.invoke(check);
}
Also used : QueueConnectionRequest(org.apache.geode.cache.client.internal.locator.QueueConnectionRequest) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) ServerLocator(org.apache.geode.distributed.internal.ServerLocator) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with QueueConnectionResponse

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

Example 3 with QueueConnectionResponse

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

the class ServerLocator method pickQueueServers.

private Object pickQueueServers(QueueConnectionRequest clientRequest) {
    Set excludedServers = new HashSet(clientRequest.getExcludedServers());
    /* If this is a request to find durable queues, lets go find them */
    ArrayList servers = new ArrayList();
    boolean durableQueueFound = false;
    if (clientRequest.isFindDurable() && clientRequest.getProxyId().isDurable()) {
        servers = FindDurableQueueProcessor.sendAndFind(this, clientRequest.getProxyId(), getDistributionManager());
        /* add the found durables to exclude list so they aren't candidates for more queues */
        excludedServers.addAll(servers);
        durableQueueFound = servers.size() > 0;
    }
    List candidates;
    if (clientRequest.getRedundantCopies() == -1) {
        /* We need all the servers we can get */
        candidates = loadSnapshot.getServersForQueue(clientRequest.getProxyId(), clientRequest.getServerGroup(), excludedServers, -1);
    } else if (clientRequest.getRedundantCopies() > servers.size()) {
        /* We need more servers. */
        int count = clientRequest.getRedundantCopies() - servers.size();
        candidates = loadSnapshot.getServersForQueue(clientRequest.getProxyId(), clientRequest.getServerGroup(), excludedServers, count);
    } else {
        /* Otherwise, we don't need any more servers */
        candidates = Collections.EMPTY_LIST;
    }
    if (candidates.size() > 1) {
        Collections.shuffle(candidates);
    }
    servers.addAll(candidates);
    return new QueueConnectionResponse(durableQueueFound, servers);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) HashSet(java.util.HashSet)

Example 4 with QueueConnectionResponse

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

the class AutoConnectionSourceImpl method findServersForQueue.

public List findServersForQueue(Set excludedServers, int numServers, ClientProxyMembershipID proxyId, boolean findDurableQueue) {
    if (PoolImpl.TEST_DURABLE_IS_NET_DOWN) {
        return new ArrayList();
    }
    QueueConnectionRequest request = new QueueConnectionRequest(proxyId, numServers, excludedServers, serverGroup, findDurableQueue);
    QueueConnectionResponse response = (QueueConnectionResponse) queryLocators(request);
    if (response == null) {
        throw new NoAvailableLocatorsException("Unable to connect to any locators in the list " + locators);
    }
    List result = response.getServers();
    return result;
}
Also used : QueueConnectionRequest(org.apache.geode.cache.client.internal.locator.QueueConnectionRequest) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) QueueConnectionResponse(org.apache.geode.cache.client.internal.locator.QueueConnectionResponse) NoAvailableLocatorsException(org.apache.geode.cache.client.NoAvailableLocatorsException)

Aggregations

QueueConnectionResponse (org.apache.geode.cache.client.internal.locator.QueueConnectionResponse)4 QueueConnectionRequest (org.apache.geode.cache.client.internal.locator.QueueConnectionRequest)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Set (java.util.Set)1 NoAvailableLocatorsException (org.apache.geode.cache.client.NoAvailableLocatorsException)1 ClientConnectionRequest (org.apache.geode.cache.client.internal.locator.ClientConnectionRequest)1 ClientConnectionResponse (org.apache.geode.cache.client.internal.locator.ClientConnectionResponse)1 ServerLoad (org.apache.geode.cache.server.ServerLoad)1 DistributionConfigImpl (org.apache.geode.distributed.internal.DistributionConfigImpl)1 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)1 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)1 ServerLocator (org.apache.geode.distributed.internal.ServerLocator)1 TcpClient (org.apache.geode.distributed.internal.tcpserver.TcpClient)1