Search in sources :

Example 31 with ClientMetadataService

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

the class FixedPRSinglehopDUnitTest method verifyEmptyMetadata.

public static void verifyEmptyMetadata() {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    assertTrue(cms.getClientPRMetadata_TEST_ONLY().isEmpty());
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService)

Example 32 with ClientMetadataService

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

the class FixedPRSinglehopDUnitTest method verifyEmptyStaticData.

public static void verifyEmptyStaticData() {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    assertTrue(cms.getClientPartitionAttributesMap().isEmpty());
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService)

Example 33 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService 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 34 with ClientMetadataService

use of org.apache.geode.cache.client.internal.ClientMetadataService 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)

Example 35 with ClientMetadataService

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

the class SingleHopStatsDUnitTest method createPR.

private void createPR(String fromClient, boolean colocated) {
    GemFireCacheImpl cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
    Region region = cache.getRegion(Region_Name);
    if (!colocated) {
        if (fromClient.equals("FirstClient")) {
            System.out.println("first pass...");
            for (int i = 0; i < 113; i++) {
                region.create(i, "create" + i);
            }
            ClientMetadataService cms = cache.getClientMetadataService();
            final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
            assertEquals(0, regionMetaData.size());
            System.out.println("second pass...");
            for (int i = 113; i < 226; i++) {
                region.create(i, "create" + i);
            }
            cms = ((GemFireCacheImpl) cache).getClientMetadataService();
            // since PR metadata is fetched in a background executor thread
            // we need to wait for it to arrive for a bit
            Awaitility.await().timeout(120, TimeUnit.SECONDS).pollDelay(100, TimeUnit.MILLISECONDS).pollInterval(500, TimeUnit.MILLISECONDS).until(() -> regionMetaData.size() == 1);
            assertTrue(regionMetaData.containsKey(region.getFullPath()));
            regionMetaData.get(region.getFullPath());
            metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
            // hops are not predictable
            assertTrue(metaDataRefreshCount != 0);
            System.out.println("metadata refresh count after second pass is " + metaDataRefreshCount);
        } else {
            System.out.println("creating keys in second client");
            for (int i = 0; i < 226; i++) {
                region.create(i, "create" + i);
            }
            ClientMetadataService cms = cache.getClientMetadataService();
            Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
            assertEquals(1, regionMetaData.size());
            assertTrue(regionMetaData.containsKey(region.getFullPath()));
            regionMetaData.get(region.getFullPath());
            metaDataRefreshCount = ((LocalRegion) region).getCachePerfStats().getMetaDataRefreshCount();
            // hops are not predictable
            assertTrue(metaDataRefreshCount != 0);
            System.out.println("metadata refresh count in second client is " + metaDataRefreshCount);
        }
    } else {
        createdColocatedPRData(cache);
    }
}
Also used : ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) Region(org.apache.geode.cache.Region) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Aggregations

ClientMetadataService (org.apache.geode.cache.client.internal.ClientMetadataService)37 ClientPartitionAdvisor (org.apache.geode.cache.client.internal.ClientPartitionAdvisor)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)12 Entry (java.util.Map.Entry)8 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 Region (org.apache.geode.cache.Region)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)2 List (java.util.List)2 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 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2