Search in sources :

Example 6 with ClientPartitionAdvisor

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

the class FixedPRSinglehopDUnitTest method verifyMetadata.

private void verifyMetadata(final int totalBuckets, int currentRedundancy) {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return (regionMetaData.size() == 1);
        }

        public String description() {
            return "expected no metadata to be refreshed";
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    wc = new WaitCriterion() {

        public boolean done() {
            return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == totalBuckets);
        }

        public String description() {
            return "expected no metadata to be refreshed.  Expected " + totalBuckets + " entries but found " + prMetaData.getBucketServerLocationsMap_TEST_ONLY();
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    System.out.println("metadata is " + prMetaData);
    System.out.println("metadata bucket locations map is " + prMetaData.getBucketServerLocationsMap_TEST_ONLY());
    for (Map.Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals("list has wrong contents: " + entry.getValue(), currentRedundancy, ((List) entry.getValue()).size());
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) Map(java.util.Map)

Example 7 with ClientPartitionAdvisor

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

the class SingleHopStatsDUnitTest method createdColocatedPRData.

private void createdColocatedPRData(GemFireCacheImpl cache) {
    Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
    Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
    Region shipmentRegion = cache.getRegion(SHIPMENT_REGION_NAME);
    for (int i = 0; i <= 20; i++) {
        CustId custid = new CustId(i);
        Customer customer = new Customer("name" + i, "Address" + i);
        customerRegion.put(custid, customer);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            Order order = new Order(ORDER_REGION_NAME + oid);
            orderRegion.put(orderId, order);
            for (int k = 1; k <= 10; k++) {
                int sid = (oid * 10) + k;
                ShipmentId shipmentId = new ShipmentId(sid, orderId);
                Shipment shipment = new Shipment("Shipment" + sid);
                shipmentRegion.put(shipmentId, shipment);
            }
        }
    }
    ClientMetadataService cms = cache.getClientMetadataService();
    Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    assertEquals(3, regionMetaData.size());
    assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
    regionMetaData.get(customerRegion.getFullPath());
    metaDataRefreshCount_Customer = ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount();
    // hops are not predictable
    assertTrue(metaDataRefreshCount_Customer != 0);
    regionMetaData.get(orderRegion.getFullPath());
    metaDataRefreshCount_Order = ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount();
    assertTrue(metaDataRefreshCount_Order == 0);
    regionMetaData.get(shipmentRegion.getFullPath());
    metaDataRefreshCount_Shipment = ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount();
    assertTrue(metaDataRefreshCount_Shipment == 0);
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) CustId(org.apache.geode.internal.cache.execute.data.CustId) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 8 with ClientPartitionAdvisor

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

the class SingleHopGetAllPutAllDUnitTest method verifyMetadata.

private static void verifyMetadata() {
    Region region = cache.getRegion(PartitionedRegionName);
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return (regionMetaData.size() == 1);
        }

        public String description() {
            return "Region metadat size is not 1. Exisitng size of regionMetaData is " + regionMetaData.size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    wc = new WaitCriterion() {

        public boolean done() {
            return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 13);
        }

        public String description() {
            return "Bucket server location map size is not 13. Exisitng size is :" + prMetaData.getBucketServerLocationsMap_TEST_ONLY().size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals(2, ((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) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 9 with ClientPartitionAdvisor

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

the class FixedPRSinglehopDUnitTest method testMetadataInClientWithFixedPartitions.

/**
   * This test will check to see if all the partitionAttributes are sent to the client. In case one
   * partition comes late, we should fetch that when there is a network hop because of that
   * partitioned region. This test will create 3 servers with partition. Do some operations on them.
   * Validate that the metadata are fetched and then later up one more partition and do some
   * operations on them. It should fetch new fpa. Verify that the correct servers are known to the
   * client metadata service at the end.
   */
@Test
public void testMetadataInClientWithFixedPartitions() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM server3 = host.getVM(2);
    VM server4 = host.getVM(3);
    Boolean simpleFPR = false;
    final int portLocator = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    final String hostLocator = NetworkUtils.getServerHostName(server1.getHost());
    final String locator = hostLocator + "[" + portLocator + "]";
    server3.invoke(() -> FixedPRSinglehopDUnitTest.startLocatorInVM(portLocator));
    try {
        List<FixedPartitionAttributes> fpaList = new ArrayList<FixedPartitionAttributes>();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", false, 3));
        Integer port1 = (Integer) server1.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        fpaList.clear();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", true, 3));
        Integer port2 = (Integer) server2.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        fpaList.clear();
        createClientWithLocator(hostLocator, portLocator);
        putIntoPartitionedRegionsThreeQs();
        getFromPartitionedRegionsFor3Qs();
        // Server 1 is actually primary for both Q1 and Q2, since there is no FPA server with
        // primary set to true.
        Awaitility.await().atMost(15, TimeUnit.SECONDS).until(() -> (server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 6) && (server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3));
        // TODO: Verify that all the fpa's are in the map
        server1.invoke(FixedPRSinglehopDUnitTest::printView);
        server2.invoke(FixedPRSinglehopDUnitTest::printView);
        int totalBucketOnServer = 0;
        totalBucketOnServer += (Integer) server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer);
        totalBucketOnServer += (Integer) server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer);
        verifyMetadata(totalBucketOnServer, 1);
        updateIntoSinglePRFor3Qs();
        // now create one more partition
        fpaList.clear();
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q4", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q2", true, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q1", false, 3));
        fpaList.add(FixedPartitionAttributes.createFixedPartition("Q3", false, 3));
        Integer port4 = (Integer) server4.invoke(() -> FixedPRSinglehopDUnitTest.createServerWithLocator(locator, false, fpaList, simpleFPR));
        putIntoPartitionedRegions();
        // Wait to make sure that the buckets have actually moved.
        Awaitility.await().atMost(15, TimeUnit.SECONDS).until(() -> (server1.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3) && (server2.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 3) && (server4.invoke(FixedPRSinglehopDUnitTest::primaryBucketsOnServer) == 6));
        getFromPartitionedRegions();
        server1.invoke(FixedPRSinglehopDUnitTest::printView);
        server2.invoke(FixedPRSinglehopDUnitTest::printView);
        server4.invoke(FixedPRSinglehopDUnitTest::printView);
        updateIntoSinglePR(false);
        ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
        ClientPartitionAdvisor advisor = cms.getClientPartitionAdvisor("/" + PR_NAME);
        int[] expected = new int[] { port1, port1, port1, port4, port4, port4, port2, port2, port2, port4, port4, port4 };
        for (int i = 0; i < expected.length; i++) {
            ServerLocation primary = advisor.advisePrimaryServerLocation(i);
            assertNotNull("bucket " + i + " had no primary server", primary);
            assertEquals("bucket " + i + " was incorrect", expected[i], primary.getPort());
        }
    } finally {
        server3.invoke(FixedPRSinglehopDUnitTest::stopLocator);
    }
}
Also used : FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) VM(org.apache.geode.test.dunit.VM) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 10 with ClientPartitionAdvisor

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

the class SingleHopStatsDUnitTest method updatePR.

private void updatePR(String FromClient, boolean colocated) {
    Cache cache = CacheFactory.getAnyInstance();
    Region region = cache.getRegion(Region_Name);
    if (!colocated) {
        if (FromClient.equals("FirstClient")) {
            for (int i = 0; i < 226; i++) {
                region.put(i, "Update" + i);
            }
            ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
            Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
            assertEquals(1, regionMetaData.size());
            regionMetaData.get(region.getFullPath());
            assertEquals(metaDataRefreshCount, ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount());
        }
    }
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) Cache(org.apache.geode.cache.Cache)

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