Search in sources :

Example 1 with RegionAccessException

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);
            }
        }
    }
}
Also used : Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) HashSet(java.util.HashSet) HashSet(java.util.HashSet) RegionAccessException(org.apache.geode.cache.RegionAccessException)

Example 2 with RegionAccessException

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) RegionAccessException(org.apache.geode.cache.RegionAccessException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Example 3 with RegionAccessException

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...
    }
}
Also used : Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RegionAccessException(org.apache.geode.cache.RegionAccessException)

Aggregations

RegionAccessException (org.apache.geode.cache.RegionAccessException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)1 Query (org.apache.geode.cache.query.Query)1 QueryService (org.apache.geode.cache.query.QueryService)1