use of org.apache.geode.cache.persistence.ConflictingPersistentDataException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testCleanupAfterConflict.
@Test
public void testCleanupAfterConflict() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
createPR(vm0, 0);
// create some buckets
createData(vm0, 0, 2, "a");
closePR(vm0);
createPR(vm1, 0);
// create an overlapping bucket
createData(vm1, 1, 2, "a");
IgnoredException[] expectVm0 = { IgnoredException.addIgnoredException("ConflictingPersistentDataException", vm0), IgnoredException.addIgnoredException("CacheClosedException", vm0) };
try {
// This results in ConflictingPersistentDataException. As part of
// GEODE-2918, the cache is closed, when ConflictingPersistentDataException
// is encountered.
createPR(vm0, 0);
fail("should have seen a conflicting data exception");
} catch (Exception ex) {
boolean expectedException = false;
if (ex.getCause() instanceof CacheClosedException) {
CacheClosedException cce = (CacheClosedException) ex.getCause();
if (cce.getCause() instanceof ConflictingPersistentDataException) {
expectedException = true;
}
}
if (!expectedException) {
throw ex;
}
} finally {
for (IgnoredException ie : expectVm0) {
ie.remove();
}
}
IgnoredException expectVm1 = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
try {
createData(vm1, 0, 1, "a");
} catch (Exception e) {
// restart.
if (!(e.getCause() instanceof PartitionOfflineException)) {
throw e;
}
} finally {
expectVm1.remove();
}
closePR(vm1);
// This should succeed, vm0 should not have persisted any view
// information from vm1
createPR(vm0, 0);
checkData(vm0, 0, 2, "a");
checkData(vm0, 2, 3, null);
}
use of org.apache.geode.cache.persistence.ConflictingPersistentDataException in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testDiskConflictWithRedundancy.
@Test
public void testDiskConflictWithRedundancy() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
createPR(vm0, 1);
// create some buckets
createData(vm0, 0, 2, "a");
closePR(vm0);
createPR(vm1, 1);
// create an overlapping bucket
createData(vm1, 1, 2, "a");
IgnoredException[] expectVm0 = { IgnoredException.addIgnoredException("ConflictingPersistentDataException", vm0), IgnoredException.addIgnoredException("CacheClosedException", vm0) };
try {
createPR(vm0, 1);
fail("should have seen a conflicting data exception");
} catch (Exception ex) {
boolean expectedException = false;
if (ex.getCause() instanceof CacheClosedException) {
CacheClosedException cce = (CacheClosedException) ex.getCause();
if (cce.getCause() instanceof ConflictingPersistentDataException) {
expectedException = true;
}
}
if (!expectedException) {
throw ex;
}
} finally {
for (IgnoredException ie : expectVm0) {
ie.remove();
}
}
closePR(vm1);
}
use of org.apache.geode.cache.persistence.ConflictingPersistentDataException in project geode by apache.
the class PersistentPartitionedRegionTestBase method createCoLocatedPR.
protected void createCoLocatedPR(VM vm, int setRedundantCopies, boolean setPersistenceAdvisorObserver) {
vm.invoke(() -> {
Cache cache = getCache();
// Wait for both nested PRs to be created
final CountDownLatch recoveryDone = new CountDownLatch(2);
ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {
@Override
public void recoveryFinished(Region region) {
recoveryDone.countDown();
}
};
InternalResourceManager.setResourceObserver(observer);
// Wait for parent and child region to be created.
// And throw exception while region is getting initialized.
final CountDownLatch childRegionCreated = new CountDownLatch(1);
if (setPersistenceAdvisorObserver) {
PersistenceAdvisorImpl.setPersistenceAdvisorObserver(new PersistenceAdvisorImpl.PersistenceAdvisorObserver() {
public void observe(String regionPath) {
if (regionPath.contains(PR_CHILD_REGION_NAME)) {
try {
childRegionCreated.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Assert.fail("Exception", e);
}
throw new ConflictingPersistentDataException("Testing Cache Close with ConflictingPersistentDataException for region." + regionPath);
}
}
});
}
// Create region.
try {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
// Parent Region
PartitionAttributesFactory paf = new PartitionAttributesFactory().setRedundantCopies(setRedundantCopies);
AttributesFactory af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_REGION_NAME, af.create());
// Colocated region
paf = (new PartitionAttributesFactory()).setRedundantCopies(setRedundantCopies).setColocatedWith(PR_REGION_NAME);
af = new AttributesFactory();
af.setPartitionAttributes(paf.create());
af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
af.setDiskStoreName("disk");
cache.createRegion(PR_CHILD_REGION_NAME, af.create());
// Count down on region create.
childRegionCreated.countDown();
try {
recoveryDone.await(MAX_WAIT, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
} finally {
PersistenceAdvisorImpl.setPersistenceAdvisorObserver(null);
}
});
}
Aggregations