use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.
the class AutoBalancerJUnitTest method testFacadeCollectMemberDetailsNoRegion.
@Test
@Ignore("GEODE-2789: need to rewrite this test")
public void testFacadeCollectMemberDetailsNoRegion() {
final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
mockContext.checking(new Expectations() {
{
oneOf(mockCache).isClosed();
will(returnValue(false));
oneOf(mockCache).getPartitionedRegions();
will(returnValue(new HashSet<PartitionedRegion>()));
}
});
GeodeCacheFacade facade = new GeodeCacheFacade(mockCache);
assertEquals(0, facade.getRegionMemberDetails().size());
}
use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade 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.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.
the class AutoBalancerJUnitTest method testFacadeTotalBytes2Regions.
@Test
@Ignore("GEODE-2789: need to rewrite this test")
public void testFacadeTotalBytes2Regions() {
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 InternalPRInfo mockR1PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR1");
final PartitionMemberInfo mockR1M1Info = mockContext.mock(PartitionMemberInfo.class, "r1M1");
final PartitionMemberInfo mockR1M2Info = mockContext.mock(PartitionMemberInfo.class, "r1M2");
final HashSet<PartitionMemberInfo> r1Members = new HashSet<>();
r1Members.add(mockR1M1Info);
r1Members.add(mockR1M2Info);
final InternalPRInfo mockR2PRInfo = mockContext.mock(InternalPRInfo.class, "prInforR2");
final PartitionMemberInfo mockR2M1Info = mockContext.mock(PartitionMemberInfo.class, "r2M1");
final HashSet<PartitionMemberInfo> r2Members = new HashSet<>();
r2Members.add(mockR2M1Info);
final Map<PartitionedRegion, InternalPRInfo> details = new HashMap<>();
details.put(mockR1, mockR1PRInfo);
details.put(mockR2, mockR2PRInfo);
mockContext.checking(new Expectations() {
{
allowing(mockR1).getFullPath();
allowing(mockR2).getFullPath();
oneOf(mockR1PRInfo).getPartitionMemberInfo();
will(returnValue(r1Members));
atLeast(1).of(mockR1M1Info).getSize();
will(returnValue(123L));
atLeast(1).of(mockR1M2Info).getSize();
will(returnValue(74L));
oneOf(mockR2PRInfo).getPartitionMemberInfo();
will(returnValue(r2Members));
atLeast(1).of(mockR2M1Info).getSize();
will(returnValue(3475L));
}
});
GeodeCacheFacade facade = new GeodeCacheFacade() {
@Override
public Map<PartitionedRegion, InternalPRInfo> getRegionMemberDetails() {
return details;
}
};
assertEquals(123 + 74 + 3475, facade.getTotalDataSize(details));
}
use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.
the class AutoBalancerIntegrationJUnitTest method testLockAlreadyTakenElsewhere.
@Test
public void testLockAlreadyTakenElsewhere() throws InterruptedException {
DistributedLockService dls = new GeodeCacheFacade().getDLS();
assertTrue(dls.lock(AutoBalancer.AUTO_BALANCER_LOCK, 0, -1));
final AtomicBoolean success = new AtomicBoolean(true);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
CacheOperationFacade cacheFacade = new GeodeCacheFacade();
success.set(cacheFacade.acquireAutoBalanceLock());
}
});
thread.start();
thread.join();
assertFalse(success.get());
}
use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.
the class AutoBalancerIntegrationJUnitTest method canReacquireLock.
@Test
public void canReacquireLock() throws InterruptedException {
acquireLockInDifferentThread(2);
DistributedLockService dls = new GeodeCacheFacade().getDLS();
assertFalse(dls.lock(AutoBalancer.AUTO_BALANCER_LOCK, 0, -1));
}
Aggregations