Search in sources :

Example 11 with HARegion

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

the class HAExpiryDUnitTest method checkSizeAfterExpiration.

/**
   * This function checks the regionqueue size After expiration. size should be = 0.
   * 
   * @throws Exception
   */
public static void checkSizeAfterExpiration() throws Exception {
    HARegion regionForQueue = (HARegion) cache.getRegion(Region.SEPARATOR + HARegionQueue.createRegionName(regionQueueName));
    final HARegionQueue regionqueue = regionForQueue.getOwner();
    cache.getLogger().info("Size of the regionqueue After expiration is " + regionqueue.size());
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return regionqueue.size() <= regionQueueSize;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
/*
     * if (regionqueue.size() > regionQueueSize) fail("RegionQueue size should be 0 after
     * expiration");
     */
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) HARegion(org.apache.geode.internal.cache.HARegion)

Example 12 with HARegion

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

the class HAExpiryDUnitTest method checkSizeBeforeExpiration.

/**
   * This function checks the regionqueue size before expiration. size should be > 0.
   * 
   * @throws Exception
   */
public static void checkSizeBeforeExpiration() throws Exception {
    HARegion regionForQueue = (HARegion) cache.getRegion(Region.SEPARATOR + HARegionQueue.createRegionName(regionQueueName));
    final HARegionQueue regionqueue = regionForQueue.getOwner();
    regionQueueSize = regionqueue.size();
    cache.getLogger().info("Size of the regionqueue before expiration is " + regionQueueSize);
    WaitCriterion ev = new WaitCriterion() {

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

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
/*
     * if (regionqueue.size() < 1) fail("RegionQueue size canot be less than 1 before expiration");
     */
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) HARegion(org.apache.geode.internal.cache.HARegion)

Example 13 with HARegion

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

the class vmListenerToCheckHARegionQueue method validateResults.

private void validateResults(boolean isSecond) {
    HARegion regionForQueue = (HARegion) cache.getRegion(Region.SEPARATOR + HARegionQueue.createRegionName(HAExpiryDUnitTest.regionQueueName));
    LogWriterUtils.getLogWriter().info("Region Queue size : " + regionForQueue.keys().size());
    Iterator itr = regionForQueue.entrySet(false).iterator();
    while (itr.hasNext()) {
        Entry entry = (Entry) itr.next();
        if (entry.getKey() instanceof Long) {
            String strValue = (String) ((ConflatableObject) entry.getValue()).getKey();
            if (isSecond) {
                if (strValue.indexOf("_2") != -1) {
                    if (keys_set_after_gii.contains(((ConflatableObject) entry.getValue()).getKey())) {
                        keys_set_after_gii.remove(strValue);
                    }
                }
            } else {
                if (strValue.indexOf("_1") != -1) {
                    if (!keys_set_before_gii.contains(strValue)) {
                        fail("Key " + ((ConflatableObject) entry.getValue()).getKey() + " not present in the region queue before GII");
                    } else {
                        keys_set_before_gii.remove(strValue);
                    }
                }
            }
        }
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) Iterator(java.util.Iterator) HARegion(org.apache.geode.internal.cache.HARegion)

Example 14 with HARegion

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

the class HARegionJUnitTest method testPut.

/**
   * test no exception being thrown while put is being done on an HARegion
   */
@Test
public void testPut() throws Exception {
    Region region = createHARegion();
    region.put("key1", "value1");
    assertEquals(region.get("key1"), "value1");
}
Also used : HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with HARegion

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

the class QueueRemovalMessage method process.

/**
   * Extracts the region from the message list and hands over the message removal task to the
   * executor
   */
@Override
protected void process(DistributionManager dm) {
    final InternalCache cache;
    // use GemFireCache.getInstance to avoid blocking during cache.xml processing.
    cache = GemFireCacheImpl.getInstance();
    if (cache != null) {
        Iterator iterator = this.messagesList.iterator();
        int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
        try {
            while (iterator.hasNext()) {
                final String regionName = (String) iterator.next();
                final int size = (Integer) iterator.next();
                final LocalRegion region = (LocalRegion) cache.getRegion(regionName);
                final HARegionQueue hrq;
                if (region == null || !region.isInitialized()) {
                    hrq = null;
                } else {
                    HARegionQueue tmp = ((HARegion) region).getOwner();
                    if (tmp != null && tmp.isQueueInitialized()) {
                        hrq = tmp;
                    } else {
                        hrq = null;
                    }
                }
                // a bunch of event IDs to go through
                for (int i = 0; i < size; i++) {
                    final EventID id = (EventID) iterator.next();
                    boolean interrupted = Thread.interrupted();
                    if (hrq == null || !hrq.isQueueInitialized()) {
                        continue;
                    }
                    try {
                        // {
                        try {
                            if (logger.isTraceEnabled()) {
                                logger.trace("QueueRemovalMessage: removing dispatched events on queue {} for {}", regionName, id);
                            }
                            hrq.removeDispatchedEvents(id);
                        } catch (RegionDestroyedException ignore) {
                            logger.info(LocalizedMessage.create(LocalizedStrings.QueueRemovalMessage_QUEUE_FOUND_DESTROYED_WHILE_PROCESSING_THE_LAST_DISPTACHED_SEQUENCE_ID_FOR_A_HAREGIONQUEUES_DACE_THE_EVENT_ID_IS_0_FOR_HAREGION_WITH_NAME_1, new Object[] { id, regionName }));
                        } catch (CancelException ignore) {
                            // cache or DS is closing
                            return;
                        } catch (CacheException e) {
                            logger.error(LocalizedMessage.create(LocalizedStrings.QueueRemovalMessage_QUEUEREMOVALMESSAGEPROCESSEXCEPTION_IN_PROCESSING_THE_LAST_DISPTACHED_SEQUENCE_ID_FOR_A_HAREGIONQUEUES_DACE_THE_PROBLEM_IS_WITH_EVENT_ID__0_FOR_HAREGION_WITH_NAME_1, new Object[] { regionName, id }), e);
                        } catch (InterruptedException ignore) {
                            // interrupt occurs during shutdown. this runs in an executor, so just stop
                            return;
                        // processing
                        }
                    } catch (RejectedExecutionException ignore) {
                        interrupted = true;
                    } finally {
                        if (interrupted) {
                            Thread.currentThread().interrupt();
                        }
                    }
                }
            // if
            }
        // for
        } finally {
            LocalRegion.setThreadInitLevelRequirement(oldLevel);
        }
    }
// cache != null
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) InternalCache(org.apache.geode.internal.cache.InternalCache) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Iterator(java.util.Iterator) EventID(org.apache.geode.internal.cache.EventID) HARegion(org.apache.geode.internal.cache.HARegion) CancelException(org.apache.geode.CancelException)

Aggregations

HARegion (org.apache.geode.internal.cache.HARegion)15 Iterator (java.util.Iterator)7 Region (org.apache.geode.cache.Region)6 CacheException (org.apache.geode.cache.CacheException)4 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)3 Test (org.junit.Test)3 Map (java.util.Map)2 Set (java.util.Set)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Cache (org.apache.geode.cache.Cache)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 EventID (org.apache.geode.internal.cache.EventID)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1