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());
}
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());
}
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);
}
}
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());
}
}
}
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);
}
}
Aggregations