Search in sources :

Example 1 with GeodeCacheFacade

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());
}
Also used : Expectations(org.jmock.Expectations) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with GeodeCacheFacade

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);
}
Also used : InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) Expectations(org.jmock.Expectations) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PRHARedundancyProvider(org.apache.geode.internal.cache.PRHARedundancyProvider) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LoadProbe(org.apache.geode.internal.cache.partitioned.LoadProbe) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with GeodeCacheFacade

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));
}
Also used : InternalPRInfo(org.apache.geode.internal.cache.partitioned.InternalPRInfo) Expectations(org.jmock.Expectations) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) HashMap(java.util.HashMap) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) HashSet(java.util.HashSet) Ignore(org.junit.Ignore) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with GeodeCacheFacade

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) CacheOperationFacade(org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade) DistributedLockService(org.apache.geode.distributed.DistributedLockService) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with GeodeCacheFacade

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));
}
Also used : GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) DistributedLockService(org.apache.geode.distributed.DistributedLockService) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

GeodeCacheFacade (org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 Test (org.junit.Test)7 Expectations (org.jmock.Expectations)4 DistributedLockService (org.apache.geode.distributed.DistributedLockService)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 Ignore (org.junit.Ignore)3 HashSet (java.util.HashSet)2 CacheOperationFacade (org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade)2 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)2 InternalPRInfo (org.apache.geode.internal.cache.partitioned.InternalPRInfo)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RebalanceFactory (org.apache.geode.cache.control.RebalanceFactory)1 RebalanceOperation (org.apache.geode.cache.control.RebalanceOperation)1 RebalanceResults (org.apache.geode.cache.control.RebalanceResults)1 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)1 PRHARedundancyProvider (org.apache.geode.internal.cache.PRHARedundancyProvider)1