Search in sources :

Example 6 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class JUnit4CacheTestCase method createRegion.

public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException {
    Region root = getRootRegion(rootName);
    if (root == null) {
        // don't put listeners on root region
        RegionAttributes rootAttrs = attributes;
        AttributesFactory fac = new AttributesFactory(attributes);
        ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
        // fac.setCacheListener(null);
        fac.setCacheLoader(null);
        fac.setCacheWriter(null);
        fac.setPoolName(null);
        fac.setPartitionAttributes(null);
        fac.setRegionTimeToLive(expiration);
        fac.setEntryTimeToLive(expiration);
        fac.setRegionIdleTimeout(expiration);
        fac.setEntryIdleTimeout(expiration);
        rootAttrs = fac.create();
        root = createRootRegion(rootName, rootAttrs);
    }
    InternalRegionArguments internalArgs = getInternalRegionArguments();
    if (internalArgs == null) {
        return root.createSubregion(name, attributes);
    } else {
        try {
            LocalRegion lr = (LocalRegion) root;
            return lr.createSubregion(name, attributes, internalArgs);
        } catch (IOException ioe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(ioe);
            throw assErr;
        } catch (ClassNotFoundException cnfe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(cnfe);
            throw assErr;
        }
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 7 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class CqServiceImpl method processRegionEvent.

private void processRegionEvent(CacheEvent event, Profile localProfile, Profile[] profiles, FilterRoutingInfo frInfo) throws CqException {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (isDebugEnabled) {
        logger.debug("CQ service processing region event {}", event);
    }
    Integer cqRegionEvent = generateCqRegionEvent(event);
    for (int i = -1; i < profiles.length; i++) {
        CacheProfile cf;
        if (i < 0) {
            cf = (CacheProfile) localProfile;
            if (cf == null)
                continue;
        } else {
            cf = (CacheProfile) profiles[i];
        }
        FilterProfile pf = cf.filterProfile;
        if (pf == null || pf.getCqMap().isEmpty()) {
            continue;
        }
        Map cqs = pf.getCqMap();
        HashMap<Long, Integer> cqInfo = new HashMap<>();
        Iterator cqIter = cqs.entrySet().iterator();
        while (cqIter.hasNext()) {
            Map.Entry cqEntry = (Map.Entry) cqIter.next();
            ServerCQImpl cQuery = (ServerCQImpl) cqEntry.getValue();
            if (!event.isOriginRemote() && event.getOperation().isRegionDestroy() && !((LocalRegion) event.getRegion()).isUsedForPartitionedRegionBucket()) {
                try {
                    if (isDebugEnabled) {
                        logger.debug("Closing CQ on region destroy event. CqName : {}", cQuery.getName());
                    }
                    cQuery.close(false);
                } catch (Exception ex) {
                    if (isDebugEnabled) {
                        logger.debug("Failed to Close CQ on region destroy. CqName : {}", cQuery.getName(), ex);
                    }
                }
            }
            cqInfo.put(cQuery.getFilterID(), cqRegionEvent);
            cQuery.getVsdStats().updateStats(cqRegionEvent);
        }
        if (pf.isLocalProfile()) {
            frInfo.setLocalCqInfo(cqInfo);
        } else {
            frInfo.setCqRoutingInfo(cf.getDistributedMember(), cqInfo);
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LocalRegion(org.apache.geode.internal.cache.LocalRegion) TimeoutException(org.apache.geode.cache.TimeoutException) CqExistsException(org.apache.geode.cache.query.CqExistsException) CqException(org.apache.geode.cache.query.CqException) QueryInvalidException(org.apache.geode.cache.query.QueryInvalidException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CqClosedException(org.apache.geode.cache.query.CqClosedException) QueryException(org.apache.geode.cache.query.QueryException) CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) FilterProfile(org.apache.geode.internal.cache.FilterProfile) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 8 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HADispatcherDUnitTest method createClientCache.

private void createClientCache(String hostName, Integer port1, Integer port2, Boolean isListenerPresent) throws CqException, CqExistsException, RegionNotFoundException {
    int PORT1 = port1.intValue();
    int PORT2 = port2.intValue();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    createCache(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1, PORT2 }, true, -1, 2, null);
    if (isListenerPresent.booleanValue() == true) {
        CacheListener clientListener = new HAClientListener();
        factory.setCacheListener(clientListener);
    }
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(region);
    {
        LocalRegion lr = (LocalRegion) region;
        final PoolImpl pool = (PoolImpl) (lr.getServerProxy().getPool());
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return pool.getPrimary() != null;
            }

            public String description() {
                return null;
            }
        };
        waitForCriterion(ev, 30 * 1000, 200, true);
        ev = new WaitCriterion() {

            public boolean done() {
                return pool.getRedundants().size() >= 1;
            }

            public String description() {
                return null;
            }
        };
        waitForCriterion(ev, 30 * 1000, 200, true);
        assertNotNull(pool.getPrimary());
        assertTrue("backups=" + pool.getRedundants() + " expected=" + 1, pool.getRedundants().size() >= 1);
        assertEquals(PORT1, pool.getPrimaryPort());
    }
    region.registerInterest(KEY1);
    // Register CQ.
    createCQ();
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) HARegion(org.apache.geode.internal.cache.HARegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 9 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class ClientToServerDeltaDUnitTest method testC2SDeltaPropagationWithOldValueInvalidatedAtServer.

@Test
public void testC2SDeltaPropagationWithOldValueInvalidatedAtServer() throws Exception {
    String key = "DELTA_KEY";
    Integer port1 = (Integer) server.invoke(() -> ClientToServerDeltaDUnitTest.createServerCache(false, false, false, true));
    createClientCache("localhost", port1, false, false, false, null, false, false);
    LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
    region.put(key, new DeltaTestImpl());
    server.invoke(() -> ClientToServerDeltaDUnitTest.doInvalidate(key));
    DeltaTestImpl value = new DeltaTestImpl();
    value.setStr("UPDATED_VALUE");
    region.put(key, value);
    assertTrue(region.getCachePerfStats().getDeltasSent() == 1);
    assertTrue(region.getCachePerfStats().getDeltaFullValuesSent() == 1);
}
Also used : DeltaTestImpl(org.apache.geode.DeltaTestImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 10 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class LuceneTestUtilities method verifyInternalRegions.

public static void verifyInternalRegions(LuceneService luceneService, Cache cache, Consumer<LocalRegion> verify) {
    // Get index
    LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
    LocalRegion fileRegion = (LocalRegion) cache.getRegion(index.createFileRegionName());
    verify.accept(fileRegion);
}
Also used : LuceneIndexForPartitionedRegion(org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Aggregations

LocalRegion (org.apache.geode.internal.cache.LocalRegion)243 Test (org.junit.Test)103 Region (org.apache.geode.cache.Region)70 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 IOException (java.io.IOException)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)42 VM (org.apache.geode.test.dunit.VM)39 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)38 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)37 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)34 Cache (org.apache.geode.cache.Cache)31 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)31 Host (org.apache.geode.test.dunit.Host)31 Iterator (java.util.Iterator)29 QueryService (org.apache.geode.cache.query.QueryService)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)27 CancelException (org.apache.geode.CancelException)26 CacheException (org.apache.geode.cache.CacheException)26 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)25