Search in sources :

Example 56 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class RegionAttributesCreation method setRegionIdleTimeout.

public ExpirationAttributes setRegionIdleTimeout(ExpirationAttributes idleTimeout) {
    ExpirationAttributes old = this.regionIdleTimeout;
    this.regionIdleTimeout = idleTimeout;
    setHasRegionIdleTimeout(true);
    return old;
}
Also used : ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 57 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class CacheXmlParser method endEntryIdleTime.

/**
   * When a <code>entry-idle-time</code> element is finished, an optional Declarable (the
   * custom-expiry) is followed by the {@link ExpirationAttributes} are on top of the stack followed
   * by the {@link RegionAttributesCreation} to which the expiration attributes are assigned.
   */
private void endEntryIdleTime() {
    Declarable custom = null;
    if (stack.peek() instanceof Declarable) {
        custom = (Declarable) stack.pop();
    }
    ExpirationAttributes expire = (ExpirationAttributes) stack.pop();
    Object a = stack.peek();
    // } else
    if (a instanceof RegionAttributesCreation) {
        ((RegionAttributesCreation) a).setEntryIdleTimeout(expire);
        if (custom != null) {
            ((RegionAttributesCreation) a).setCustomEntryIdleTimeout((CustomExpiry) custom);
        }
    } else {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_PARTITIONATTRIBUTES.toLocalizedString(ENTRY_IDLE_TIME));
    }
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 58 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class RegionReliabilityTestCase method testNoAccessWithLocalEntryExpiration.

/**
   * Tests affect of NO_ACCESS on local entry expiration actions.
   */
@Test
public void testNoAccessWithLocalEntryExpiration() throws Exception {
    final String name = this.getUniqueName();
    final String roleA = name + "-A";
    // assign names to 4 vms...
    final String[] requiredRoles = { roleA };
    Set requiredRolesSet = new HashSet();
    for (int i = 0; i < requiredRoles.length; i++) {
        requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
    }
    assertEquals(requiredRoles.length, requiredRolesSet.size());
    // connect controller to system...
    Properties config = new Properties();
    config.setProperty(ROLES, "");
    getSystem(config);
    getCache();
    // create region in controller...
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(getRegionScope());
    fac.setStatisticsEnabled(true);
    RegionAttributes attr = fac.create();
    final Region region = createExpiryRootRegion(name, attr);
    // wait for memberTimeout to expire
    waitForMemberTimeout();
    // use vm1 to create role
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            createConnection(new String[] { roleA });
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    // test to make sure expiration is not suspended
    region.put("expireMe", "expireMe");
    assertTrue(region.size() == 1);
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Close Region") {

        public void run2() throws CacheException {
            Region region = getRootRegion(name);
            region.close();
        }
    });
    // TODO: waitForMemberTimeout(); ?
    // set expiration and sleep
    AttributesMutator mutator = region.getAttributesMutator();
    mutator.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
    sleep(200);
    // make sure no values were expired
    Set entries = ((LocalRegion) region).basicEntries(false);
    assertTrue(entries.size() == 1);
    // create region again in vm1
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {

        public void run2() throws CacheException {
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(getRegionScope());
            RegionAttributes attr = fac.create();
            createRootRegion(name, attr);
        }
    });
    waitForEntryDestroy(region, "expireMe");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesFactory(org.apache.geode.cache.AttributesFactory) AbstractRegion(org.apache.geode.internal.cache.AbstractRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) HashSet(java.util.HashSet) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 59 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class RegionTestCase method testEntryExpirationAfterMutate.

@Test
public void testEntryExpirationAfterMutate() throws CacheException, InterruptedException {
    final String name = this.getUniqueName();
    // ms
    final int timeout = 20;
    final int hugeTimeout = Integer.MAX_VALUE;
    final ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
    final ExpirationAttributes hugeExpire = new ExpirationAttributes(hugeTimeout, ExpirationAction.INVALIDATE);
    final String key = "KEY";
    final String value = "VALUE";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    factory.setStatisticsEnabled(true);
    RegionAttributes attrs = factory.create();
    Region region = null;
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {
        region = createRegion(name, attrs);
    } finally {
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
    }
    long tilt;
    region.create(key, value);
    tilt = System.currentTimeMillis() + timeout;
    // Now go from huge timeout to a timeout
    ExpiryTask.suspendExpiration();
    Region.Entry entry = null;
    try {
        region.getAttributesMutator().setEntryIdleTimeout(expire);
        entry = region.getEntry(key);
        assertEquals(value, entry.getValue());
    } finally {
        ExpiryTask.permitExpiration();
    }
    waitForInvalidate(entry, tilt);
    // Now go from a big timeout to a short one
    region.getAttributesMutator().setEntryIdleTimeout(hugeExpire);
    region.put(key, value);
    tilt = System.currentTimeMillis() + timeout;
    entry = region.getEntry(key);
    Wait.pause(timeout * 2);
    assertEquals(value, entry.getValue());
    region.getAttributesMutator().setEntryIdleTimeout(expire);
    waitForInvalidate(entry, tilt);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Entry(org.apache.geode.cache.Region.Entry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 60 with ExpirationAttributes

use of org.apache.geode.cache.ExpirationAttributes in project geode by apache.

the class RegionExpirationDUnitTest method testRegionTTLAfterMutating.

@Test
public void testRegionTTLAfterMutating() throws InterruptedException, CacheException {
    String regionName = getUniqueName();
    int firstTimeout = 2;
    int secondTimeout = 6;
    createWithExpiration(regionName, new ExpirationAttributes(firstTimeout, ExpirationAction.DESTROY), null);
    long startTime = System.currentTimeMillis();
    final Region region = getOrCreateRootRegion().getSubregion(regionName);
    region.getAttributesMutator().setRegionTimeToLive(new ExpirationAttributes(secondTimeout, ExpirationAction.DESTROY));
    Thread.sleep(firstTimeout * 1000 + 100);
    if (region.isDestroyed()) {
        assertTrue(System.currentTimeMillis() >= startTime + secondTimeout * 1000);
    }
    Thread.sleep((secondTimeout - firstTimeout) * 1000 + 100);
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return region.isDestroyed();
        }

        public String description() {
            return "region never destroyed";
        }
    };
    Wait.waitForCriterion(wc, 30 * 1000, 1000, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)84 Region (org.apache.geode.cache.Region)51 AttributesFactory (org.apache.geode.cache.AttributesFactory)50 Test (org.junit.Test)50 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 LocalRegion (org.apache.geode.internal.cache.LocalRegion)41 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)35 Entry (org.apache.geode.cache.Region.Entry)21 EntryEvent (org.apache.geode.cache.EntryEvent)15 CacheException (org.apache.geode.cache.CacheException)12 AttributesMutator (org.apache.geode.cache.AttributesMutator)11 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)11 Host (org.apache.geode.test.dunit.Host)11 VM (org.apache.geode.test.dunit.VM)11 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)11 Properties (java.util.Properties)10 EntryExpiryTask (org.apache.geode.internal.cache.EntryExpiryTask)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 Cache (org.apache.geode.cache.Cache)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8