Search in sources :

Example 16 with ClientPartitionAdvisor

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

the class Shipment method testMetadataFetchOnlyThroughFunctions.

@Test
public void testMetadataFetchOnlyThroughFunctions() throws Exception {
    // Workaround for 52004
    IgnoredException.addIgnoredException("InternalFunctionInvocationTargetException");
    Integer port0 = (Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port1 = (Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port2 = (Integer) member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    Integer port3 = (Integer) member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
    createClient(port0, port1, port2, port3);
    executeFunctions();
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> regionMetaData.size() == 1);
    assertEquals(1, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    // Fixes a race condition in GEODE-414 by retrying as
    // region.clientMetaDataLock.tryLock() may prevent fetching the
    // metadata through functional calls as only limited functions are executed in the test.
    long start = System.currentTimeMillis();
    do {
        if ((prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() != 4)) {
            // waiting if there is another thread holding the lock
            Thread.sleep(1000);
            cms.getClientPRMetadata((LocalRegion) region);
        } else {
            break;
        }
    } while (System.currentTimeMillis() - start < 60000);
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 4));
// assertIndexDetailsEquals(4/*numBuckets*/,
// prMetaData.getBucketServerLocationsMap_TEST_ONLY().size());
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Aggregations

ClientPartitionAdvisor (org.apache.geode.cache.client.internal.ClientPartitionAdvisor)16 ClientMetadataService (org.apache.geode.cache.client.internal.ClientMetadataService)15 Entry (java.util.Map.Entry)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 Test (org.junit.Test)6 Region (org.apache.geode.cache.Region)5 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Cache (org.apache.geode.cache.Cache)2 CacheException (org.apache.geode.cache.CacheException)2 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 ServerBucketProfile (org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile)2 CustId (org.apache.geode.internal.cache.execute.data.CustId)2 OrderId (org.apache.geode.internal.cache.execute.data.OrderId)2