Search in sources :

Example 6 with GeodeCacheFacade

use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.

the class AutoBalancerIntegrationJUnitTest method testAutoBalanceStatUpdate.

@Test
public void testAutoBalanceStatUpdate() {
    assertEquals(0, cache.getInternalResourceManager().getStats().getAutoRebalanceAttempts());
    new GeodeCacheFacade().incrementAttemptCounter();
    assertEquals(1, cache.getInternalResourceManager().getStats().getAutoRebalanceAttempts());
}
Also used : GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with GeodeCacheFacade

use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.

the class AutoBalancerIntegrationJUnitTest method acquireLockInDifferentThread.

private void acquireLockInDifferentThread(final int num) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(num);
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            CacheOperationFacade cacheFacade = new GeodeCacheFacade();
            for (int i = 0; i < num; i++) {
                boolean result = cacheFacade.acquireAutoBalanceLock();
                if (result) {
                    latch.countDown();
                }
            }
        }
    });
    thread.start();
    assertTrue(latch.await(TIMEOUT_SECONDS, TimeUnit.SECONDS));
}
Also used : GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) CacheOperationFacade(org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with GeodeCacheFacade

use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.

the class AutoBalancerIntegrationJUnitTest method testLockSuccess.

@Test
public void testLockSuccess() throws InterruptedException {
    acquireLockInDifferentThread(1);
    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)

Example 9 with GeodeCacheFacade

use of org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade in project geode by apache.

the class AutoBalancerJUnitTest method getFacadeForResourceManagerOps.

private GeodeCacheFacade getFacadeForResourceManagerOps(final boolean simulate) throws Exception {
    final GemFireCacheImpl mockCache = mockContext.mock(GemFireCacheImpl.class);
    final InternalResourceManager mockRM = mockContext.mock(InternalResourceManager.class);
    final RebalanceFactory mockRebalanceFactory = mockContext.mock(RebalanceFactory.class);
    final RebalanceOperation mockRebalanceOperation = mockContext.mock(RebalanceOperation.class);
    final RebalanceResults mockRebalanceResults = mockContext.mock(RebalanceResults.class);
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).isClosed();
            will(returnValue(false));
            oneOf(mockCache).getResourceManager();
            will(returnValue(mockRM));
            oneOf(mockRM).createRebalanceFactory();
            will(returnValue(mockRebalanceFactory));
            if (simulate) {
                oneOf(mockRebalanceFactory).simulate();
            } else {
                oneOf(mockRebalanceFactory).start();
            }
            will(returnValue(mockRebalanceOperation));
            oneOf(mockRebalanceOperation).getResults();
            will(returnValue(mockRebalanceResults));
            if (simulate) {
                atLeast(1).of(mockRebalanceResults).getTotalBucketTransferBytes();
                will(returnValue(12345L));
            }
            allowing(mockRebalanceResults);
        }
    });
    GeodeCacheFacade facade = new GeodeCacheFacade(mockCache);
    return facade;
}
Also used : Expectations(org.jmock.Expectations) RebalanceFactory(org.apache.geode.cache.control.RebalanceFactory) RebalanceOperation(org.apache.geode.cache.control.RebalanceOperation) GeodeCacheFacade(org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager)

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