Search in sources :

Example 56 with ServerLocation

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

the class DurableClientTestCase method setBridgeObeserverForAfterPrimaryRecovered.

public static void setBridgeObeserverForAfterPrimaryRecovered() {
    DurableClientTestCase.isPrimaryRecovered = false;
    PoolImpl.AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG = true;
    ClientServerObserver bo = ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {

        public void afterPrimaryRecovered(ServerLocation location) {
            DurableClientTestCase.isPrimaryRecovered = true;
            PoolImpl.AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG = false;
        }
    });
}
Also used : ClientServerObserver(org.apache.geode.internal.cache.ClientServerObserver) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientServerObserverAdapter(org.apache.geode.internal.cache.ClientServerObserverAdapter)

Example 57 with ServerLocation

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

the class HAStartupAndFailoverDUnitTest method createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection.

public static void createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection(String testName, String host) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HAStartupAndFailoverDUnitTest().createCache(props);
    CacheServerTestUtil.disableShufflingOfEndpoints();
    PoolImpl p;
    try {
        p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).addServer(host, PORT2.intValue()).addServer(host, PORT3.intValue()).setPingInterval(500).create("HAStartupAndFailoverDUnitTestPool");
    } finally {
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(p.getName());
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    pool = p;
    // since the default minConnections is 1 we currently have a connection to
    // server1 (vm_0). Now we create a connection to server2 (vm_1)
    conn = pool.acquireConnection(new ServerLocation(Host.getHost(0).getHostName(), PORT2));
    // assert that the conn is to server2 since the tests assume that this is so
    assertNotNull(conn);
    assertTrue(conn.getEndpoint().getLocation().getPort() == PORT2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 58 with ServerLocation

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

the class UniversalMembershipListenerAdapterDUnitTest method testNoDuplicates.

/**
   * Tests use of history to prevent duplicate events.
   */
@Test
public void testNoDuplicates() throws Exception {
    getSystem();
    final boolean[] fired = new boolean[3];
    final DistributedMember[] member = new DistributedMember[3];
    final String[] memberId = new String[3];
    UniversalMembershipListenerAdapter listener = new UniversalMembershipListenerAdapter() {

        @Override
        public synchronized void memberJoined(MembershipEvent event) {
            assertFalse(fired[JOINED]);
            assertNull(member[JOINED]);
            assertNull(memberId[JOINED]);
            fired[JOINED] = true;
            member[JOINED] = event.getDistributedMember();
            memberId[JOINED] = event.getMemberId();
            notify();
        }

        @Override
        public synchronized void memberLeft(MembershipEvent event) {
            assertFalse(fired[LEFT]);
            assertNull(member[LEFT]);
            assertNull(memberId[LEFT]);
            fired[LEFT] = true;
            member[LEFT] = event.getDistributedMember();
            memberId[LEFT] = event.getMemberId();
            notify();
        }

        @Override
        public synchronized void memberCrashed(MembershipEvent event) {
            // assures no dupes
            assertFalse(fired[CRASHED]);
            assertNull(member[CRASHED]);
            assertNull(memberId[CRASHED]);
            fired[CRASHED] = true;
            member[CRASHED] = event.getDistributedMember();
            memberId[CRASHED] = event.getMemberId();
            notify();
        }
    };
    DistributedMember memberA = new TestDistributedMember("memberA");
    ServerLocation serverA = new ServerLocation("serverA", 0);
    // first join
    InternalClientMembership.notifyClientJoined(memberA);
    synchronized (listener) {
        if (!fired[JOINED]) {
            listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    assertTrue(fired[JOINED]);
    assertEquals(memberA, member[JOINED]);
    assertEquals(memberA.getId(), memberId[JOINED]);
    fired[JOINED] = false;
    member[JOINED] = null;
    memberId[JOINED] = null;
    // duplicate join
    InternalClientMembership.notifyClientJoined(memberA);
    Wait.pause(BRIEF_PAUSE_MILLIS);
    assertFalse(fired[JOINED]);
    assertNull(member[JOINED]);
    assertNull(memberId[JOINED]);
    // first left
    InternalClientMembership.notifyClientLeft(memberA);
    synchronized (listener) {
        if (!fired[LEFT]) {
            listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    assertTrue(fired[LEFT]);
    assertEquals(memberA, member[LEFT]);
    assertEquals(memberA.getId(), memberId[LEFT]);
    fired[LEFT] = false;
    member[LEFT] = null;
    memberId[LEFT] = null;
    // duplicate left
    InternalClientMembership.notifyClientLeft(memberA);
    Wait.pause(BRIEF_PAUSE_MILLIS);
    assertFalse(fired[LEFT]);
    assertNull(member[LEFT]);
    assertNull(memberId[LEFT]);
    // rejoin
    InternalClientMembership.notifyClientJoined(memberA);
    synchronized (listener) {
        if (!fired[JOINED]) {
            listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
        }
    }
    assertTrue(fired[JOINED]);
    assertEquals(memberA, member[JOINED]);
    assertEquals(memberA.getId(), memberId[JOINED]);
}
Also used : UniversalMembershipListenerAdapter(org.apache.geode.management.membership.UniversalMembershipListenerAdapter) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientMembershipEvent(org.apache.geode.management.membership.ClientMembershipEvent) MembershipEvent(org.apache.geode.management.membership.MembershipEvent) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 59 with ServerLocation

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

the class LocatorJUnitTest method testServerLocationOnDifferentHostsShouldNotTestEqual.

/**
   * Make sure two ServerLocation objects on different hosts but with the same port are not equal
   * <p/>
   * TRAC #42040: LoadBalancing directs all traffic to a single cache server if all servers are
   * started on the same port
   */
@Test
public void testServerLocationOnDifferentHostsShouldNotTestEqual() {
    ServerLocation sl1 = new ServerLocation("host1", 777);
    ServerLocation sl2 = new ServerLocation("host2", 777);
    if (sl1.equals(sl2)) {
        fail("ServerLocation instances on different hosts should not test equal");
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 60 with ServerLocation

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

the class SingleHopClientExecutor method submitGetAll.

static Map<ServerLocation, Object> submitGetAll(Map<ServerLocation, HashSet> serverToFilterMap, List callableTasks, ClientMetadataService cms, LocalRegion region) {
    if (callableTasks != null && !callableTasks.isEmpty()) {
        Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                List keys = ((GetAllOpImpl) task.getOperation()).getKeyList();
                ServerLocation server = task.getServer();
                try {
                    VersionedObjectList valuesFromServer = (VersionedObjectList) fut.get();
                    valuesFromServer.setKeys(keys);
                    for (VersionedObjectList.Iterator it = valuesFromServer.iterator(); it.hasNext(); ) {
                        VersionedObjectList.Entry entry = it.next();
                        Object key = entry.getKey();
                        Object value = entry.getValue();
                        if (!entry.isKeyNotOnServer()) {
                            if (value instanceof Throwable) {
                                logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { value, key }), (Throwable) value);
                            }
                        }
                    }
                    if (logger.isDebugEnabled()) {
                        logger.debug("GetAllOp#got result from {}: {}", server, valuesFromServer);
                    }
                    resultMap.put(server, valuesFromServer);
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof ServerOperationException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        throw (ServerOperationException) ee.getCause();
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("GetAllOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return null;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData((LocalRegion) region, false);
                        resultMap.put(server, ee.getCause());
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            return resultMap;
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) GetAllOpImpl(org.apache.geode.cache.client.internal.GetAllOp.GetAllOpImpl) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

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