Search in sources :

Example 66 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class FindDurableQueueProcessor method findLocalDurableQueues.

private static void findLocalDurableQueues(ClientProxyMembershipID proxyId, ArrayList<ServerLocation> matches) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null) {
        List l = cache.getCacheServers();
        if (l != null) {
            Iterator i = l.iterator();
            while (i.hasNext()) {
                CacheServerImpl bs = (CacheServerImpl) i.next();
                if (bs.getAcceptor().getCacheClientNotifier().getClientProxy(proxyId) != null) {
                    ServerLocation loc = new ServerLocation(bs.getExternalAddress(), bs.getPort());
                    matches.add(loc);
                }
            }
        }
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.

the class AutoConnectionSourceImplJUnitTest method testServerLocationUsedInListenerNotification.

@Test
public void testServerLocationUsedInListenerNotification() throws Exception {
    final ClientMembershipEvent[] listenerEvents = new ClientMembershipEvent[1];
    ClientMembershipListener listener = new ClientMembershipListener() {

        @Override
        public void memberJoined(final ClientMembershipEvent event) {
            synchronized (listenerEvents) {
                listenerEvents[0] = event;
            }
        }

        @Override
        public void memberLeft(final ClientMembershipEvent event) {
        }

        @Override
        public void memberCrashed(final ClientMembershipEvent event) {
        }
    };
    InternalClientMembership.registerClientMembershipListener(listener);
    ServerLocation location = new ServerLocation("1.1.1.1", 0);
    InternalClientMembership.notifyServerJoined(location);
    Awaitility.await("wait for listener notification").atMost(10, TimeUnit.SECONDS).until(() -> {
        synchronized (listenerEvents) {
            return listenerEvents[0] != null;
        }
    });
    assertEquals("1.1.1.1", listenerEvents[0].getMember().getHost());
    InetAddress addr = InetAddress.getLocalHost();
    location = new ServerLocation(addr.getHostAddress(), 0);
    listenerEvents[0] = null;
    InternalClientMembership.notifyServerJoined(location);
    Awaitility.await("wait for listener notification").atMost(10, TimeUnit.SECONDS).until(() -> {
        synchronized (listenerEvents) {
            return listenerEvents[0] != null;
        }
    });
    assertEquals(addr.getCanonicalHostName(), listenerEvents[0].getMember().getHost());
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientMembershipListener(org.apache.geode.management.membership.ClientMembershipListener) InetAddress(java.net.InetAddress) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 68 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation 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 69 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation 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)

Example 70 with ServerLocation

use of org.apache.geode.distributed.internal.ServerLocation 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

ServerLocation (org.apache.geode.distributed.internal.ServerLocation)95 ArrayList (java.util.ArrayList)26 Test (org.junit.Test)21 HashSet (java.util.HashSet)19 List (java.util.List)18 HashMap (java.util.HashMap)17 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)17 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)13 Map (java.util.Map)12 Iterator (java.util.Iterator)10 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)9 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Set (java.util.Set)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 LinkedHashSet (java.util.LinkedHashSet)7 Host (org.apache.geode.test.dunit.Host)7 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5