use of org.apache.geode.internal.cache.partitioned.PartitionedRegionObserverAdapter in project geode by apache.
the class PartitionedRegionDataStoreJUnitTest method testChangeCacheLoaderDuringBucketCreation.
@Test
public void testChangeCacheLoaderDuringBucketCreation() throws Exception {
final PartitionedRegion pr = (PartitionedRegion) cache.createRegionFactory(RegionShortcut.PARTITION).create("testChangeCacheLoaderDuringBucketCreation");
// Add an observer which will block bucket creation and wait for a loader to be added
final CountDownLatch loaderAdded = new CountDownLatch(1);
final CountDownLatch bucketCreated = new CountDownLatch(1);
PartitionedRegionObserverHolder.setInstance(new PartitionedRegionObserverAdapter() {
@Override
public void beforeAssignBucket(PartitionedRegion partitionedRegion, int bucketId) {
try {
// Indicate that the bucket has been created
bucketCreated.countDown();
// Wait for the loader to be added. if the synchronization
// is correct, this would wait for ever because setting the
// cache loader will wait for this method. So time out after
// 1 second, which should be good enough to cause a failure
// if the synchronization is broken.
loaderAdded.await(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted");
}
}
});
Thread createBuckets = new Thread() {
public void run() {
PartitionRegionHelper.assignBucketsToPartitions(pr);
}
};
createBuckets.start();
CacheLoader loader = new CacheLoader() {
@Override
public void close() {
}
@Override
public Object load(LoaderHelper helper) throws CacheLoaderException {
return null;
}
};
bucketCreated.await();
pr.getAttributesMutator().setCacheLoader(loader);
loaderAdded.countDown();
createBuckets.join();
// Assert that all buckets have received the cache loader
for (BucketRegion bucket : pr.getDataStore().getAllLocalBucketRegions()) {
assertEquals(loader, bucket.getCacheLoader());
}
}
use of org.apache.geode.internal.cache.partitioned.PartitionedRegionObserverAdapter in project geode by apache.
the class FixedPartitioningTestBase method setPRObserverBeforeCalculateStartingBucketId.
public static void setPRObserverBeforeCalculateStartingBucketId() {
PartitionedRegion.BEFORE_CALCULATE_STARTING_BUCKET_FLAG = true;
origObserver = PartitionedRegionObserverHolder.setInstance(new PartitionedRegionObserverAdapter() {
public void beforeCalculatingStartingBucketId() {
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
Region prRoot = PartitionedRegionHelper.getPRRoot(cache);
PartitionRegionConfig regionConfig = (PartitionRegionConfig) prRoot.get("#Quarter");
if (regionConfig == null) {
return false;
} else {
if (!regionConfig.isFirstDataStoreCreated()) {
return true;
} else {
return false;
}
}
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 20000, 500, false);
LogWriterUtils.getLogWriter().info("end of beforeCalculatingStartingBucketId");
}
});
}
Aggregations