use of org.apache.geode.cache.control.ResourceManager in project geode by apache.
the class MemoryMonitorJUnitTest method testCriticalHeapThreshold.
@Test
public void testCriticalHeapThreshold() throws Exception {
final int toohigh = 101;
final int toolow = -1;
final float disabled = 0.0f;
final float justright = 92.5f;
final ResourceManager rm = this.cache.getResourceManager();
long usageThreshold = -1;
int once = 0;
for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
if (p.isUsageThresholdSupported() && HeapMemoryMonitor.isTenured(p)) {
usageThreshold = p.getUsageThreshold();
once++;
}
}
assertEquals("Expected only one pool to be assigned", 1, once);
// Default test, current default is disabled
assertEquals(rm.getCriticalHeapPercentage(), MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE, 0.01);
NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
assertTrue("Expected that the resource manager was not registered", false);
} catch (ListenerNotFoundException expected) {
}
try {
rm.setCriticalHeapPercentage(toohigh);
assertTrue("Expected illegal argument exception for value " + toohigh, false);
} catch (IllegalArgumentException toohi) {
}
try {
rm.setCriticalHeapPercentage(toolow);
assertTrue("Expected illegal argument exception for value " + toolow, false);
} catch (IllegalArgumentException toohi) {
}
rm.setCriticalHeapPercentage(justright);
emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
{
InternalResourceManager irm = InternalResourceManager.getInternalResourceManager(cache);
HeapMemoryMonitor hmm = irm.getHeapMonitor();
// Expect no exception for removal (it was installed during set)
hmm.stopMonitoring();
}
assertEquals(rm.getCriticalHeapPercentage(), justright, 0.01);
rm.setCriticalHeapPercentage(disabled);
assertEquals(rm.getCriticalHeapPercentage(), disabled, 0.01);
emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
try {
emitter.removeNotificationListener(InternalResourceManager.getInternalResourceManager(cache).getHeapMonitor());
assertTrue("Expected that the resource manager was not registered", false);
} catch (ListenerNotFoundException expected) {
}
// Assert the threshold was reset
for (MemoryPoolMXBean p : ManagementFactory.getMemoryPoolMXBeans()) {
if (HeapMemoryMonitor.isTenured(p)) {
assertEquals(usageThreshold, p.getUsageThreshold());
}
}
}
use of org.apache.geode.cache.control.ResourceManager in project geode by apache.
the class RebalanceOperationDUnitTest method recoverRedundancyBalancing.
public void recoverRedundancyBalancing(final boolean simulate) {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final DistributedMember member1 = createPrRegion(vm0, "region1", 200, null);
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
for (int i = 0; i < 12; i++) {
region.put(Integer.valueOf(i), "A");
}
}
});
SerializableRunnable checkRedundancy = new SerializableRunnable("checkRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(12, details.getCreatedBucketCount());
assertEquals(0, details.getActualRedundantCopies());
assertEquals(12, details.getLowRedundancyBucketCount());
}
};
vm0.invoke(checkRedundancy);
// Now create the region in 2 more VMs with half the localMaxMemory
createPrRegion(vm1, "region1", 100, null);
createPrRegion(vm2, "region1", 100, null);
vm0.invoke(checkRedundancy);
// Now simulate a rebalance
vm0.invoke(new SerializableRunnable("rebalance") {
public void run() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(simulate, manager);
assertEquals(12, results.getTotalBucketCreatesCompleted());
assertEquals(6, results.getTotalPrimaryTransfersCompleted());
assertEquals(0, results.getTotalBucketTransferBytes());
assertEquals(0, results.getTotalBucketTransfersCompleted());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(12, details.getBucketCreatesCompleted());
assertEquals(6, details.getPrimaryTransfersCompleted());
assertEquals(0, details.getBucketTransferBytes());
assertEquals(0, details.getBucketTransfersCompleted());
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(3, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
// We have 1 member with a size of 200 and two members with size 100
if (memberDetails.getDistributedMember().equals(member1)) {
assertEquals(12, memberDetails.getBucketCount());
assertEquals(6, memberDetails.getPrimaryCount());
} else {
assertEquals(6, memberDetails.getBucketCount());
assertEquals(3, memberDetails.getPrimaryCount());
}
}
if (!simulate) {
verifyStats(manager, results);
}
}
});
if (!simulate) {
SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkLowRedundancy") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(12, details.getCreatedBucketCount());
assertEquals(1, details.getActualRedundantCopies());
assertEquals(0, details.getLowRedundancyBucketCount());
}
};
vm0.invoke(checkRedundancyFixed);
vm1.invoke(checkRedundancyFixed);
vm2.invoke(checkRedundancyFixed);
}
}
use of org.apache.geode.cache.control.ResourceManager in project geode by apache.
the class FixedPartitioningTestBase method doRebalance.
public static void doRebalance() {
ResourceManager manager = cache.getResourceManager();
RebalanceOperation operation = manager.createRebalanceFactory().start();
try {
RebalanceResults result = operation.getResults();
} catch (InterruptedException e) {
org.apache.geode.test.dunit.Assert.fail("Not expecting exception", e);
}
}
use of org.apache.geode.cache.control.ResourceManager in project geode by apache.
the class MyGatewayEventSubstitutionFilter method doRebalance.
/**
* Do a rebalance and verify balance was improved. If evictionPercentage > 0 (the default) then we
* have heapLRU and this can cause simulate and rebalance results to differ if eviction kicks in
* between. (See BUG 44899).
*/
public static void doRebalance() {
ResourceManager resMan = cache.getResourceManager();
boolean heapEviction = (resMan.getEvictionHeapPercentage() > 0);
RebalanceFactory factory = resMan.createRebalanceFactory();
try {
RebalanceResults simulateResults = null;
if (!heapEviction) {
LogWriterUtils.getLogWriter().info("Calling rebalance simulate");
RebalanceOperation simulateOp = factory.simulate();
simulateResults = simulateOp.getResults();
}
LogWriterUtils.getLogWriter().info("Starting rebalancing");
RebalanceOperation rebalanceOp = factory.start();
RebalanceResults rebalanceResults = rebalanceOp.getResults();
} catch (InterruptedException e) {
Assert.fail("Interrupted", e);
}
}
use of org.apache.geode.cache.control.ResourceManager in project geode by apache.
the class ResourceManagerValidator method validateJavaStartupParameters.
public static void validateJavaStartupParameters(GemFireCache cache) {
// Get the input arguments
ResourceManager rm = cache.getResourceManager();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
List<String> inputArguments = runtimeBean.getInputArguments();
if (cache.getLogger().fineEnabled()) {
cache.getLogger().fine("Full input java arguments: " + inputArguments);
}
// Validate the arguments based on VM vendor
String vmVendor = runtimeBean.getVmVendor();
if (vmVendor.startsWith("Sun") || vmVendor.startsWith("Apple")) {
// java.vm.vendor = Sun Microsystems Inc. || java.vm.vendor = Apple Inc.
validateSunArguments(cache, rm, inputArguments);
} else if (vmVendor.startsWith("IBM")) {
// java.vm.vendor = IBM Corporation
// TODO validate IBM input arguments
} else if (vmVendor.startsWith("BEA")) {
// java.vm.vendor = BEA Systems, Inc.
// TODO validate JRockit input arguments
}
}
Aggregations