Search in sources :

Example 1 with ClientPartitionAdvisor

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

the class PartitionedRegionSingleHopWithServerGroupDUnitTest method verifyMetadata.

public static void verifyMetadata(final int numRegions, final int numBucketLocations) {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            if (regionMetaData.size() == numRegions) {
                return true;
            }
            return false;
        }

        public String description() {
            return "expected metadata for each region to be" + numRegions + " but it is " + regionMetaData.size() + "Metadata is " + regionMetaData.keySet();
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    if (numRegions != 0) {
        assertTrue(regionMetaData.containsKey(region.getFullPath()));
        ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
        if (cache.getLogger().fineEnabled()) {
            for (Entry e : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
                cache.getLogger().fine("For bucket id " + e.getKey() + " the locations are " + e.getValue());
            }
        }
        for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
            assertEquals(numBucketLocations, ((List) entry.getValue()).size());
        }
    }
}
Also used : Entry(java.util.Map.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 2 with ClientPartitionAdvisor

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

the class Shipment method verifyDeadServer.

private void verifyDeadServer(Map<String, ClientPartitionAdvisor> regionMetaData, Region region, int port0, int port1) {
    ServerLocation sl0 = new ServerLocation("localhost", port0);
    ServerLocation sl1 = new ServerLocation("localhost", port1);
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        List servers = (List) entry.getValue();
        assertFalse(servers.contains(sl0));
        assertFalse(servers.contains(sl1));
    }
}
Also used : Entry(java.util.Map.Entry) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with ClientPartitionAdvisor

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

the class Shipment method testServerLocationRemovalThroughPing.

// GEODE-853: random ports, pause sleeps, time sensitive, 5 second
@Category(FlakyTest.class)
// thread sleeps
@Test
public void testServerLocationRemovalThroughPing() {
    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);
    putIntoPartitionedRegions();
    getFromPartitionedRegions();
    Wait.pause(5000);
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    assertEquals(4, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
    assertTrue(regionMetaData.containsKey(orderRegion.getFullPath()));
    assertTrue(regionMetaData.containsKey(shipmentRegion.getFullPath()));
    ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    assertEquals(4, /* numBuckets */
    prMetaData.getBucketServerLocationsMap_TEST_ONLY().size());
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals(4, ((List) entry.getValue()).size());
    }
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    // make sure that ping detects the dead servers
    Wait.pause(5000);
    getFromPartitionedRegions();
    verifyDeadServer(regionMetaData, customerRegion, port0, port1);
    verifyDeadServer(regionMetaData, region, port0, port1);
}
Also used : Entry(java.util.Map.Entry) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) Category(org.junit.experimental.categories.Category) 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)

Example 4 with ClientPartitionAdvisor

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

the class Shipment method testMetadataIsSameOnAllServersAndClientsHA.

@Test
public void testMetadataIsSameOnAllServersAndClientsHA() {
    Integer port0 = (Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(2, 4));
    Integer port1 = (Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(2, 4));
    createClient(port0, port1, port0, port1);
    put();
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    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()));
    member0.invoke(new CacheSerializableRunnable("aba") {

        @Override
        public void run2() throws CacheException {
            final PartitionedRegion pr = (PartitionedRegion) region;
            ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
        }
    });
    member1.invoke(new CacheSerializableRunnable("aba") {

        @Override
        public void run2() throws CacheException {
            final PartitionedRegion pr = (PartitionedRegion) region;
            ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
        }
    });
    ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    final Map<Integer, List<BucketServerLocation66>> clientMap = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (clientMap.size() == 4));
    for (Entry entry : clientMap.entrySet()) {
        assertEquals(2, ((List) entry.getValue()).size());
    }
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
    put();
    cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    // member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
    assertEquals(4, /* numBuckets */
    clientMap.size());
    for (Entry entry : clientMap.entrySet()) {
        assertEquals(1, ((List) entry.getValue()).size());
    }
    assertEquals(1, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    assertEquals(4, /* numBuckets */
    clientMap.size());
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> {
        int bucketId = -1;
        int size = -1;
        List globalList = new ArrayList();
        boolean finished = true;
        for (Entry entry : clientMap.entrySet()) {
            List list = (List) entry.getValue();
            if (list.size() != 1) {
                size = list.size();
                globalList = list;
                bucketId = (Integer) entry.getKey();
                finished = false;
                System.out.println("bucket copies are not created, the locations size for bucket id : " + bucketId + " size : " + size + " the list is " + globalList);
            }
        }
        return finished;
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ArrayList(java.util.ArrayList) ServerBucketProfile(org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile) Entry(java.util.Map.Entry) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) List(java.util.List) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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)

Example 5 with ClientPartitionAdvisor

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

the class Shipment method testMetadataFetchOnlyThroughputAll.

@Test
public void testMetadataFetchOnlyThroughputAll() {
    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);
    putAll();
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (regionMetaData.size() == 1));
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 4));
}
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