use of org.apache.geode.cache.RegionAccessException in project geode by apache.
the class DistributedRegion method checkForLimitedOrNoAccess.
/**
* Throws RegionAccessException is required roles are missing and the LossAction is either
* NO_ACCESS or LIMITED_ACCESS.
*
* @throws RegionAccessException if required roles are missing and the LossAction is either
* NO_ACCESS or LIMITED_ACCESS
*/
@Override
protected void checkForLimitedOrNoAccess() {
if (this.requiresReliabilityCheck && this.isMissingRequiredRoles) {
if (getMembershipAttributes().getLossAction().isNoAccess() || getMembershipAttributes().getLossAction().isLimitedAccess()) {
synchronized (this.missingRequiredRoles) {
if (!this.isMissingRequiredRoles)
return;
Set roles = Collections.unmodifiableSet(new HashSet(this.missingRequiredRoles));
Assert.assertTrue(!roles.isEmpty());
throw new RegionAccessException(LocalizedStrings.DistributedRegion_OPERATION_IS_DISALLOWED_BY_LOSSACTION_0_BECAUSE_THESE_REQUIRED_ROLES_ARE_MISSING_1.toLocalizedString(getMembershipAttributes().getLossAction(), roles), getFullPath(), roles);
}
}
}
}
use of org.apache.geode.cache.RegionAccessException in project geode by apache.
the class RegionReliabilityTestCase method assertLimitedAccessThrows.
protected void assertLimitedAccessThrows(Region region) throws Exception {
try {
region.clear();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.create("KEY", "VAL");
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.destroy(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.destroyRegion();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
if (region.getAttributes().getScope().isGlobal()) {
try {
region.becomeLockGrantor();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.getDistributedLock(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.getRegionDistributedLock();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
}
try {
region.invalidate(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.invalidateRegion();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.loadSnapshot(new ByteArrayInputStream(new byte[] {}));
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
// netload TODO: configure CacheLoader in region
region.get("netload");
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
// netsearch TODO: add 2nd VM that has the object
region.get("netsearch");
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.put(new Object(), new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
Map map = new HashMap();
map.put(new Object(), new Object());
region.putAll(map);
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
Map map = new HashMap();
map.put(new Object(), new Object());
region.putAll(map, "callbackArg");
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.remove(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
if (!region.getAttributes().getScope().isGlobal()) {
CacheTransactionManager tx = region.getCache().getCacheTransactionManager();
tx.begin();
try {
region.put("KEY-tx", "VAL-tx");
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
tx.rollback();
}
}
use of org.apache.geode.cache.RegionAccessException in project geode by apache.
the class RegionReliabilityTestCase method assertNoAccessThrows.
protected void assertNoAccessThrows(Region region) throws Exception {
assertLimitedAccessThrows(region);
try {
region.containsKey(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.containsValue(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.containsValueForKey(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.entrySet(false);
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.entrySet();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.get(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.getEntry(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.isEmpty();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.keySet();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.localDestroy(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.localInvalidate(new Object());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.localInvalidateRegion();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.saveSnapshot(new ByteArrayOutputStream());
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.size();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
region.values();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
try {
QueryService qs = region.getCache().getQueryService();
Query query = qs.newQuery("(select distinct * from " + region.getFullPath() + ").size");
query.execute();
fail("Should have thrown an RegionAccessException");
} catch (RegionAccessException ex) {
// pass...
}
}
Aggregations