use of org.apache.geode.management.ManagerMXBean in project geode by apache.
the class GemfireDataCommandsDUnitTest method setupForGetPutRemoveLocateEntry.
void setupForGetPutRemoveLocateEntry(String testName) {
final VM vm1 = Host.getHost(0).getVM(1);
final VM vm2 = Host.getHost(0).getVM(2);
Properties props = new Properties();
props.setProperty(NAME, testName + "Manager");
HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(props);
assertNotNull(gfsh);
assertEquals(true, gfsh.isConnectedAndReady());
vm1.invoke(new SerializableRunnable() {
public void run() {
InternalCache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region dataRegion = regionFactory.create(DATA_REGION_NAME);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = regionFactory.create(DATA_REGION_NAME_VM1);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
partitionRegionFactory.setPartitionAttributes(partitionAttrs);
Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM1);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
}
});
vm2.invoke(new SerializableRunnable() {
public void run() {
InternalCache cache = getCache();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region dataRegion = regionFactory.create(DATA_REGION_NAME);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = dataRegion.createSubregion(DATA_REGION_NAME_CHILD_1_2, dataRegion.getAttributes());
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
dataRegion = regionFactory.create(DATA_REGION_NAME_VM2);
assertNotNull(dataRegion);
getLogWriter().info("Created Region " + dataRegion);
PartitionAttributes partitionAttrs = new PartitionAttributesFactory().setRedundantCopies(2).create();
RegionFactory<Object, Object> partitionRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
partitionRegionFactory.setPartitionAttributes(partitionAttrs);
Region dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
dataParRegion = partitionRegionFactory.create(DATA_PAR_REGION_NAME_VM2);
assertNotNull(dataParRegion);
getLogWriter().info("Created Region " + dataParRegion);
}
});
final String vm1MemberId = vm1.invoke(() -> getMemberId());
final String vm2MemberId = vm2.invoke(() -> getMemberId());
getLogWriter().info("Vm1 ID : " + vm1MemberId);
getLogWriter().info("Vm2 ID : " + vm2MemberId);
final VM manager = Host.getHost(0).getVM(0);
SerializableRunnable checkRegionMBeans = new SerializableRunnable() {
@Override
public void run() {
InternalCache cache = getCache();
final ManagementService service = ManagementService.getManagementService(cache);
final WaitCriterion waitForMaangerMBean = new WaitCriterion() {
@Override
public boolean done() {
ManagerMXBean bean1 = service.getManagerMXBean();
DistributedRegionMXBean bean2 = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
if (bean1 == null) {
getLogWriter().info("Still probing for ManagerMBean");
return false;
} else {
getLogWriter().info("Still probing for DistributedRegionMXBean=" + bean2);
return (bean2 != null);
}
}
@Override
public String description() {
return "Probing for ManagerMBean";
}
};
waitForCriterion(waitForMaangerMBean, 30000, 2000, true);
assertNotNull(service.getMemberMXBean());
assertNotNull(service.getManagerMXBean());
DistributedRegionMXBean bean = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
assertNotNull(bean);
WaitCriterion waitForRegionMBeans = new WaitCriterion() {
@Override
public boolean done() {
DistributedRegionMXBean[] beans = new DistributedRegionMXBean[6];
beans[0] = service.getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
beans[1] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM1_PATH);
beans[2] = service.getDistributedRegionMXBean(DATA_REGION_NAME_VM2_PATH);
beans[3] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_PATH);
beans[4] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM1_PATH);
beans[5] = service.getDistributedRegionMXBean(DATA_PAR_REGION_NAME_VM2_PATH);
// SubRegion Bug : Proxy creation has some issues.
// beans[6] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_PATH);
// beans[7] = service.getDistributedRegionMXBean(DATA_REGION_NAME_CHILD_1_2_PATH);
boolean flag = true;
for (DistributedRegionMXBean b : beans) {
if (b == null) {
flag = false;
break;
}
}
if (!flag) {
getLogWriter().info("Still probing for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
return false;
} else {
getLogWriter().info("Probing complete for regionMbeans " + DATA_REGION_NAME_PATH + "=" + beans[0] + " " + DATA_REGION_NAME_VM1_PATH + "=" + beans[1] + " " + DATA_REGION_NAME_VM2_PATH + "=" + beans[2] + " " + DATA_PAR_REGION_NAME_PATH + "=" + beans[3] + " " + DATA_PAR_REGION_NAME_VM1_PATH + "=" + beans[4] + " " + DATA_PAR_REGION_NAME_VM2_PATH + "=" + beans[5] + " ");
// bean1.getMemberCount()==1)
return true;
// else{
// getLogWriter().info("Still probing for regionMbeans for aggregation bean1=" +
// bean1.getMemberCount() + " bean2="+ bean2.getMemberCount() + " bean3" +
// bean3.getMemberCount());
// return false;
// }
}
}
@Override
public String description() {
return "Probing for regionMbeans";
}
};
waitForCriterion(waitForRegionMBeans, 30000, 2000, true);
String[] regions = { DATA_REGION_NAME_PATH, DATA_REGION_NAME_VM1_PATH, DATA_REGION_NAME_VM2_PATH, DATA_PAR_REGION_NAME_PATH, DATA_PAR_REGION_NAME_VM1_PATH, DATA_PAR_REGION_NAME_VM2_PATH };
for (String region : regions) {
bean = service.getDistributedRegionMXBean(region);
assertNotNull(bean);
String[] membersName = bean.getMembers();
getLogWriter().info("Members Array for region " + region + " : " + StringUtils.objectToString(membersName, true, 10));
if (bean.getMemberCount() < 1)
fail("Even after waiting mbean reports number of member hosting region " + DATA_REGION_NAME_VM1_PATH + " is less than one");
// assertIndexDetailsEquals(1, membersName.length); //exists in one members vm1
}
}
};
manager.invoke(checkRegionMBeans);
}
Aggregations