Search in sources :

Example 1 with CacheOperationFacade

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

the class AutoBalancerJUnitTest method testFacadeTotalBytesNoRegion.

@Test
public void testFacadeTotalBytesNoRegion() {
    CacheOperationFacade facade = new AutoBalancer().getCacheOperationFacade();
    assertEquals(0, facade.getTotalDataSize(new HashMap<PartitionedRegion, InternalPRInfo>()));
}
Also used : HashMap(java.util.HashMap) CacheOperationFacade(org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with CacheOperationFacade

use of org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade 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 3 with CacheOperationFacade

use of org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade 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)

Aggregations

CacheOperationFacade (org.apache.geode.cache.util.AutoBalancer.CacheOperationFacade)3 GeodeCacheFacade (org.apache.geode.cache.util.AutoBalancer.GeodeCacheFacade)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DistributedLockService (org.apache.geode.distributed.DistributedLockService)1