Search in sources :

Example 11 with ResourceObserver

use of org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver in project geode by apache.

the class PersistentPartitionedRegionTestBase method getCreatePRRunnable.

private SerializableRunnable getCreatePRRunnable(final int redundancy, final int recoveryDelay, final int numBuckets, final boolean synchronous) {
    SerializableRunnable createPR = new SerializableRunnable("create pr") {

        public void run() {
            final CountDownLatch recoveryDone;
            if (redundancy > 0) {
                recoveryDone = new CountDownLatch(1);
                ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {

                    @Override
                    public void recoveryFinished(Region region) {
                        recoveryDone.countDown();
                    }
                };
                InternalResourceManager.setResourceObserver(observer);
            } else {
                recoveryDone = null;
            }
            Cache cache = getCache();
            RegionAttributes attr = getPersistentPRAttributes(redundancy, recoveryDelay, cache, numBuckets, synchronous);
            cache.createRegion(PR_REGION_NAME, attr);
            if (recoveryDone != null) {
                try {
                    recoveryDone.await();
                } catch (InterruptedException e) {
                    Assert.fail("Interrupted", e);
                }
            }
        }
    };
    return createPR;
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) Cache(org.apache.geode.cache.Cache)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)11 Region (org.apache.geode.cache.Region)11 ResourceObserver (org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver)11 Cache (org.apache.geode.cache.Cache)10 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)9 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 DiskStore (org.apache.geode.cache.DiskStore)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Test (org.junit.Test)5 DiskRegion (org.apache.geode.internal.cache.DiskRegion)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 AdminException (org.apache.geode.admin.AdminException)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 ConflictingPersistentDataException (org.apache.geode.cache.persistence.ConflictingPersistentDataException)1