Search in sources :

Example 1 with ServerLocation

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

the class Simple2CacheServerDUnitTest method setClientServerObserver.

public static void setClientServerObserver() {
    PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
    ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

        public void afterPrimaryIdentificationFromBackup(ServerLocation primaryEndpoint) {
            LogService.getLogger().info("After primary is set");
            afterPrimaryCount++;
        }
    });
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter)

Example 2 with ServerLocation

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

the class DurableClientSimpleDUnitTest method verifyDurableCqs.

public static void verifyDurableCqs(final List<String> durableCqNames, final String registeredCqName) {
    // Verify the number of durable CQ names is one, and it matches the registered name
    assertEquals(1, durableCqNames.size());
    String returnedCqName = durableCqNames.get(0);
    assertEquals(registeredCqName, returnedCqName);
    // Get client's primary server
    PoolImpl pool = CacheServerTestUtil.getPool();
    ServerLocation primaryServerLocation = pool.getPrimary();
    // Verify the primary server was used and no other server was used
    Map<ServerLocation, ConnectionStats> statistics = pool.getEndpointManager().getAllStats();
    for (Map.Entry<ServerLocation, ConnectionStats> entry : statistics.entrySet()) {
        int expectedGetDurableCqInvocations = entry.getKey().equals(primaryServerLocation) ? 1 : 0;
        assertEquals(expectedGetDurableCqInvocations, entry.getValue().getGetDurableCqs());
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ConnectionStats(org.apache.geode.cache.client.internal.ConnectionStats) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Map(java.util.Map)

Example 3 with ServerLocation

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

the class ClearPropagationDUnitTest method acquireConnectionsAndDestroyRegion.

public static void acquireConnectionsAndDestroyRegion(String host) {
    try {
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
        assertNotNull(r1);
        String poolName = r1.getAttributes().getPoolName();
        assertNotNull(poolName);
        PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
        assertNotNull(pool);
        Connection conn1 = pool.acquireConnection(new ServerLocation(host, PORT2));
        assertNotNull(conn1);
        assertEquals(PORT2, conn1.getServer().getPort());
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.destroyRegionOnForTestsOnly(conn1, new EventID(new byte[] { 1 }, 1, 1), null);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("while setting acquireConnections  " + ex);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheException(org.apache.geode.cache.CacheException)

Example 4 with ServerLocation

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

the class UpdatePropagationDUnitTest method hasEndPointWithPort.

/**
   * Check to see if a client is connected to an endpoint with a specific port
   */
private boolean hasEndPointWithPort(final PoolImpl pool, final int port) {
    EndpointManager endpointManager = pool.getEndpointManager();
    final Set<ServerLocation> servers = endpointManager.getEndpointMap().keySet();
    return servers.stream().anyMatch(location -> location.getPort() == port);
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) EndpointManager(org.apache.geode.cache.client.internal.EndpointManager)

Example 5 with ServerLocation

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

the class ServerBlackListJUnitTest method testBlackListing.

@Test
public void testBlackListing() throws Exception {
    ServerLocation location1 = new ServerLocation("localhost", 1);
    FailureTracker tracker1 = blackList.getFailureTracker(location1);
    tracker1.addFailure();
    tracker1.addFailure();
    assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
    tracker1.addFailure();
    assertEquals(Collections.singleton(location1), blackList.getBadServers());
    boolean done = false;
    for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 10000; done = (blackList.getBadServers().size() == 0)) {
        Thread.sleep(200);
    }
    assertTrue("blackList still has bad servers", done);
    assertEquals(Collections.EMPTY_SET, blackList.getBadServers());
}
Also used : FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) StopWatch(org.apache.geode.internal.util.StopWatch) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

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