use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.
the class RebalanceOperationDUnitTest method setLoadProbe.
private LoadProbe setLoadProbe(VM vm, final LoadProbe probe) {
LoadProbe oldProbe = (LoadProbe) vm.invoke(new SerializableCallable("set load probe") {
public Object call() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
InternalResourceManager mgr = cache.getInternalResourceManager();
return mgr.setLoadProbe(probe);
}
});
return oldProbe;
}
use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.
the class RebalanceOperationDUnitTest method balanceBucketsByCount.
/**
* Check to make sure that we balance buckets between two hosts with no redundancy.
*
* @param simulate
*/
public void balanceBucketsByCount(final boolean simulate) {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
LoadProbe oldProbe = setLoadProbe(vm0, new BucketCountLoadProbe());
try {
SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setCacheLoader(new Bug40228Loader());
cache.createRegion("region1", attr.create());
}
};
// Create the region in only 1 VM
vm0.invoke(createPrRegion);
// Create some buckets with very uneven sizes
vm0.invoke(new SerializableRunnable("createSomeBuckets") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.put(Integer.valueOf(1), new byte[1024 * 1024]);
region.put(Integer.valueOf(2), "A");
region.put(Integer.valueOf(3), "A");
region.put(Integer.valueOf(4), "A");
region.put(Integer.valueOf(5), "A");
region.put(Integer.valueOf(6), "A");
}
});
// Create the region in the other VM (should have no effect)
vm1.invoke(createPrRegion);
// Now simulate a rebalance
vm0.invoke(new SerializableRunnable("simulateRebalance") {
public void run() {
Cache cache = getCache();
ResourceManager manager = cache.getResourceManager();
RebalanceResults results = doRebalance(simulate, manager);
assertEquals(0, results.getTotalBucketCreatesCompleted());
assertEquals(0, results.getTotalPrimaryTransfersCompleted());
assertEquals(3, results.getTotalBucketTransfersCompleted());
assertTrue(0 < results.getTotalBucketTransferBytes());
Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
assertEquals(1, detailSet.size());
PartitionRebalanceInfo details = detailSet.iterator().next();
assertEquals(0, details.getBucketCreatesCompleted());
assertEquals(0, details.getPrimaryTransfersCompleted());
assertTrue(0 < details.getBucketTransferBytes());
assertEquals(3, details.getBucketTransfersCompleted());
Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
assertEquals(2, afterDetails.size());
for (PartitionMemberInfo memberDetails : afterDetails) {
assertEquals(3, memberDetails.getBucketCount());
assertEquals(3, memberDetails.getPrimaryCount());
}
if (!simulate) {
verifyStats(manager, results);
}
}
});
if (!simulate) {
SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkRedundancyFixed") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
assertEquals(6, details.getCreatedBucketCount());
assertEquals(0, details.getActualRedundantCopies());
assertEquals(0, details.getLowRedundancyBucketCount());
assertEquals(2, details.getPartitionMemberInfo().size());
for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
assertEquals(3, memberDetails.getBucketCount());
assertEquals(3, memberDetails.getPrimaryCount());
}
// check to make sure that moving buckets didn't close the cache loader
Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
assertFalse(loader.isClosed());
}
};
vm0.invoke(checkRedundancyFixed);
vm1.invoke(checkRedundancyFixed);
}
} finally {
setLoadProbe(vm0, oldProbe);
}
}
use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.
the class AutoBalancerJUnitTest method testFacadeCollectMemberDetails2Regions.
@Test
@Ignore("GEODE-2789: need to rewrite this test")
public void testFacadeCollectMemberDetails2Regions() {
final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
final InternalResourceManager mockRM = mockContext.mock(InternalResourceManager.class);
final LoadProbe mockProbe = mockContext.mock(LoadProbe.class);
final PartitionedRegion mockR1 = mockContext.mock(PartitionedRegion.class, "r1");
final PartitionedRegion mockR2 = mockContext.mock(PartitionedRegion.class, "r2");
final HashSet<PartitionedRegion> regions = new HashSet<>();
regions.add(mockR1);
regions.add(mockR2);
final PRHARedundancyProvider mockRedundancyProviderR1 = mockContext.mock(PRHARedundancyProvider.class, "prhaR1");
final InternalPRInfo mockR1PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR1");
final PRHARedundancyProvider mockRedundancyProviderR2 = mockContext.mock(PRHARedundancyProvider.class, "prhaR2");
final InternalPRInfo mockR2PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR2");
mockContext.checking(new Expectations() {
{
oneOf(mockCache).isClosed();
will(returnValue(false));
oneOf(mockCache).getPartitionedRegions();
will(returnValue(regions));
exactly(2).of(mockCache).getResourceManager();
will(returnValue(mockRM));
exactly(2).of(mockRM).getLoadProbe();
will(returnValue(mockProbe));
allowing(mockR1).getFullPath();
oneOf(mockR1).getRedundancyProvider();
will(returnValue(mockRedundancyProviderR1));
allowing(mockR2).getFullPath();
oneOf(mockR2).getRedundancyProvider();
will(returnValue(mockRedundancyProviderR2));
oneOf(mockRedundancyProviderR1).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
will(returnValue(mockR1PRInfo));
oneOf(mockRedundancyProviderR2).buildPartitionedRegionInfo(with(true), with(any(LoadProbe.class)));
will(returnValue(mockR2PRInfo));
}
});
GeodeCacheFacade facade = new GeodeCacheFacade(mockCache);
Map<PartitionedRegion, InternalPRInfo> map = facade.getRegionMemberDetails();
assertNotNull(map);
assertEquals(2, map.size());
assertEquals(map.get(mockR1), mockR1PRInfo);
assertEquals(map.get(mockR2), mockR2PRInfo);
}
use of org.apache.geode.internal.cache.partitioned.LoadProbe in project geode by apache.
the class InternalResourceManager method setLoadProbe.
/**
* This method is test purposes only.
*/
public LoadProbe setLoadProbe(LoadProbe probe) {
LoadProbe old = this.loadProbe;
this.loadProbe = probe;
return old;
}
Aggregations