use of org.apache.geode.cache.client.internal.ClientPartitionAdvisor 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);
}
}
use of org.apache.geode.cache.client.internal.ClientPartitionAdvisor in project geode by apache.
the class SingleHopStatsDUnitTest method getPR.
private void getPR(String FromClient, boolean colocated) {
Cache cache = CacheFactory.getAnyInstance();
Region region = cache.getRegion(Region_Name);
Region customerRegion = cache.getRegion(CUSTOMER_REGION_NAME);
Region orderRegion = cache.getRegion(ORDER_REGION_NAME);
Region shipmentRegion = cache.getRegion("SHIPMENT");
if (!colocated) {
for (int i = 0; i < 226; i++) {
region.get(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());
} else {
for (int i = 0; i <= 20; i++) {
CustId custid = new CustId(i);
customerRegion.get(custid);
for (int j = 1; j <= 10; j++) {
int oid = (i * 10) + j;
OrderId orderId = new OrderId(oid, custid);
orderRegion.get(orderId);
for (int k = 1; k <= 10; k++) {
int sid = (oid * 10) + k;
ShipmentId shipmentId = new ShipmentId(sid, orderId);
shipmentRegion.get(shipmentId);
}
}
}
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(3, regionMetaData.size());
assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
regionMetaData.get(customerRegion.getFullPath());
assertEquals(metaDataRefreshCount_Customer, ((LocalRegion) customerRegion).getCachePerfStats().getMetaDataRefreshCount());
regionMetaData.get(orderRegion.getFullPath());
assertEquals(metaDataRefreshCount_Order, ((LocalRegion) orderRegion).getCachePerfStats().getMetaDataRefreshCount());
regionMetaData.get(shipmentRegion.getFullPath());
assertEquals(metaDataRefreshCount_Shipment, ((LocalRegion) shipmentRegion).getCachePerfStats().getMetaDataRefreshCount());
}
}
use of org.apache.geode.cache.client.internal.ClientPartitionAdvisor in project geode by apache.
the class PartitionedRegionSingleHopWithServerGroupDUnitTest method verifyMetadataFor2ClientsInOneVM.
public static void verifyMetadataFor2ClientsInOneVM(final int numRegions, final int numBucketLocations, final int numBucketLocations2) {
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() + " they are " + regionMetaData.keySet();
}
};
Wait.waitForCriterion(wc, 120000, 1000, true);
if (numRegions != 0) {
assertTrue(regionMetaData.containsKey(region.getFullPath()));
ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
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());
}
assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
prMetaData = regionMetaData.get(customerRegion.getFullPath());
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());
}
assertTrue(regionMetaData.containsKey(customerRegion2.getFullPath()));
prMetaData = regionMetaData.get(customerRegion2.getFullPath());
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(numBucketLocations2, ((List) entry.getValue()).size());
}
}
}
use of org.apache.geode.cache.client.internal.ClientPartitionAdvisor in project geode by apache.
the class Shipment method testMetadataIsSameOnAllServersAndClients.
// GEODE-1763
@Category(FlakyTest.class)
@Test
public void testMetadataIsSameOnAllServersAndClients() {
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);
put();
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
cms.getClientPRMetadata((LocalRegion) region);
Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(1, regionMetaData.size());
assertTrue(regionMetaData.containsKey(region.getFullPath()));
ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
final Map<Integer, List<BucketServerLocation66>> clientMap = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return (clientMap.size() == 4);
}
public String description() {
return "expected no metadata to be refreshed";
}
};
Wait.waitForCriterion(wc, 60000, 1000, true);
for (Entry entry : clientMap.entrySet()) {
assertEquals(4, ((List) entry.getValue()).size());
}
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.stopServer());
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.startServerOnPort(port0));
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.startServerOnPort(port1));
put();
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
cms = ((GemFireCacheImpl) cache).getClientMetadataService();
wc = new WaitCriterion() {
public boolean done() {
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(1, regionMetaData.size());
assertTrue(regionMetaData.containsKey(region.getFullPath()));
ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
Map<Integer, List<BucketServerLocation66>> clientMap = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
assertEquals(4, /* numBuckets */
clientMap.size());
boolean finished = true;
for (Entry entry : clientMap.entrySet()) {
List list = (List) entry.getValue();
if (list.size() < 4) {
LogWriterUtils.getLogWriter().info("still waiting for 4 bucket owners in " + entry.getKey() + ": " + list);
finished = false;
break;
}
}
return finished;
}
public String description() {
return "bucket copies are not created";
}
};
Wait.waitForCriterion(wc, 60000, 400, true);
cms = ((GemFireCacheImpl) cache).getClientMetadataService();
cms.getClientPRMetadata((LocalRegion) region);
regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(1, regionMetaData.size());
assertTrue(regionMetaData.containsKey(region.getFullPath()));
prMetaData = regionMetaData.get(region.getFullPath());
final Map<Integer, List<BucketServerLocation66>> clientMap2 = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
wc = new WaitCriterion() {
public boolean done() {
return (clientMap2.size() == 4);
}
public String description() {
return "expected no metadata to be refreshed";
}
};
Wait.waitForCriterion(wc, 60000, 1000, true);
for (Entry entry : clientMap.entrySet()) {
assertEquals(4, ((List) entry.getValue()).size());
}
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(clientMap));
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.closeCacheAndDisconnect());
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.closeCacheAndDisconnect());
// member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServerOnPort(3,4,port0 ));
// member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServerOnPort(3,4,port1 ));
put();
member2.invoke(new CacheSerializableRunnable("aba") {
@Override
public void run2() throws CacheException {
final PartitionedRegion pr = (PartitionedRegion) region;
ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
}
});
member3.invoke(new CacheSerializableRunnable("aba") {
@Override
public void run2() throws CacheException {
final PartitionedRegion pr = (PartitionedRegion) region;
ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
}
});
// member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
// member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.waitForLocalBucketsCreation(4));
cms = ((GemFireCacheImpl) cache).getClientMetadataService();
cms.getClientPRMetadata((LocalRegion) region);
regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
assertEquals(1, regionMetaData.size());
assertTrue(regionMetaData.containsKey(region.getFullPath()));
prMetaData = regionMetaData.get(region.getFullPath());
final Map<Integer, List<BucketServerLocation66>> clientMap3 = prMetaData.getBucketServerLocationsMap_TEST_ONLY();
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (clientMap3.size() == 4));
for (Entry entry : clientMap.entrySet()) {
assertEquals(2, ((List) entry.getValue()).size());
}
final Map<Integer, List<BucketServerLocation66>> fclientMap = clientMap;
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
try {
// member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(fclientMap));
// member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(fclientMap));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(fclientMap));
member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.verifyMetadata(fclientMap));
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("verification failed", e);
return false;
}
return true;
}
public String description() {
return "verification of metadata on all members";
}
}, 20000, 2000, true);
}
use of org.apache.geode.cache.client.internal.ClientPartitionAdvisor in project geode by apache.
the class PartitionedRegionSingleHopWithServerGroupDUnitTest method verifyMetadataForColocatedRegionWithDiffPool.
public static void verifyMetadataForColocatedRegionWithDiffPool(final int numRegions, final int numBucketLocations, final int numBucketLocations2, final int numBucketLocations3) {
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() + " they are " + regionMetaData.keySet();
}
};
Wait.waitForCriterion(wc, 120000, 1000, true);
assertTrue(regionMetaData.containsKey(region.getFullPath()));
ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
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());
}
assertTrue(regionMetaData.containsKey(customerRegion.getFullPath()));
prMetaData = regionMetaData.get(customerRegion.getFullPath());
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());
}
assertTrue(regionMetaData.containsKey(orderRegion.getFullPath()));
prMetaData = regionMetaData.get(orderRegion.getFullPath());
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(numBucketLocations2, ((List) entry.getValue()).size());
}
assertTrue(regionMetaData.containsKey(shipmentRegion.getFullPath()));
prMetaData = regionMetaData.get(shipmentRegion.getFullPath());
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(numBucketLocations3, ((List) entry.getValue()).size());
}
}
Aggregations