Search in sources :

Example 81 with ExpirationAttributes

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

the class CQListGIIDUnitTest method createRegion.

public static Region createRegion(String name, String rootName, RegionAttributes attrs) throws CacheException {
    Region root = cache.getRegion(rootName);
    if (root == null) {
        // don't put listeners on root region
        RegionAttributes rootAttrs = attrs;
        AttributesFactory fac = new AttributesFactory(attrs);
        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 = cache.createRegion(rootName, rootAttrs);
    }
    return createSubregion(root, name, attrs, null);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 82 with ExpirationAttributes

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

the class Bug40632DUnitTest method testLocalInvalidateTimeToLive.

@Test
public void testLocalInvalidateTimeToLive() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 83 with ExpirationAttributes

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

the class Bug40632DUnitTest method testLocalDestroyIdleTimeout.

@Test
public void testLocalDestroyIdleTimeout() throws Exception {
    Cache cache = getCache();
    AttributesFactory attr = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(1);
    paf.setRecoveryDelay(-1);
    paf.setStartupRecoveryDelay(-1);
    PartitionAttributes prAttr = paf.create();
    attr.setStatisticsEnabled(true);
    attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
    attr.setPartitionAttributes(prAttr);
    try {
        cache.createRegion("region1", attr.create());
        fail("We should not have been able to create the region");
    } catch (IllegalStateException expected) {
    }
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 84 with ExpirationAttributes

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

the class RemoteTransactionDUnitTest method testExpirySuspend_bug45984.

@Test
public void testExpirySuspend_bug45984() {
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String regionName = getName();
    // create region with expiration
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
            try {
                RegionFactory<String, String> rf = getCache().createRegionFactory();
                rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
                rf.setScope(Scope.DISTRIBUTED_ACK);
                rf.create(regionName);
            } finally {
                System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
            }
            return null;
        }
    });
    // create replicate region
    vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            final Region<String, String> r = getCache().getRegion(regionName);
            WaitCriterion wc2 = new WaitCriterion() {

                @Override
                public boolean done() {
                    return !r.containsKey("key") && !r.containsKey("nonTXKey");
                }

                @Override
                public String description() {
                    return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
                }
            };
            ExpiryTask.suspendExpiration();
            Region.Entry entry = null;
            long tilt;
            try {
                r.put("key", "value");
                LocalRegion lr = (LocalRegion) r;
                r.put("nonTXkey", "nonTXvalue");
                getCache().getCacheTransactionManager().begin();
                r.put("key", "newvalue");
                TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
            } finally {
                ExpiryTask.permitExpiration();
            }
            TransactionId tx = getCache().getCacheTransactionManager().suspend();
            // A remote tx will allow expiration to happen on the side that
            // is not hosting the tx. But it will not allow an expiration
            // initiated on the hosting jvm.
            // tx is hosted in vm2 so expiration can happen in vm1.
            Wait.waitForCriterion(wc2, 30000, 5, true);
            getCache().getCacheTransactionManager().resume(tx);
            assertTrue(r.containsKey("key"));
            getCache().getCacheTransactionManager().commit();
            Wait.waitForCriterion(wc2, 30000, 5, true);
            return null;
        }
    });
}
Also used : Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) TransactionId(org.apache.geode.cache.TransactionId) Entry(org.apache.geode.cache.Region.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

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