Search in sources :

Example 56 with Entry

use of org.apache.geode.cache.Region.Entry in project geode by apache.

the class RegionTestCase method testCustomEntryIdleTimeout3.

/**
   * Configure custome entry expiration with an idle time. Create an entry and records its scheduled
   * expiration time. Then mutate the region expiration configuration and confirm that the entry's
   * expiration time is rescheduled.
   */
@Test
public void testCustomEntryIdleTimeout3() {
    final String name = this.getUniqueName();
    // test no longer waits for this expiration to happen
    // ms
    final int timeout1 = 500 * 1000;
    // ms
    final int timeout2 = 2000 * 1000;
    final String key1 = "KEY1";
    final String value1 = "VALUE1";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    ExpirationAttributes expire1 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
    factory.setCustomEntryIdleTimeout(new TestExpiry(key1, expire1));
    factory.setStatisticsEnabled(true);
    TestCacheListener list = new TestCacheListener() {

        public void afterCreate2(EntryEvent e) {
        }

        public void afterUpdate2(EntryEvent e) {
        }

        public void afterInvalidate2(EntryEvent e) {
            eventCount++;
        }
    };
    eventCount = 0;
    factory.addCacheListener(list);
    RegionAttributes attrs = factory.create();
    LocalRegion region;
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {
        region = (LocalRegion) createRegion(name, attrs);
    } finally {
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
    }
    region.create(key1, value1);
    EntryExpiryTask eet = region.getEntryExpiryTask(key1);
    final long firstExpiryTime = eet.getExpirationTime();
    AttributesMutator mutt = region.getAttributesMutator();
    ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
    mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire2));
    eet = region.getEntryExpiryTask(key1);
    final long secondExpiryTime = eet.getExpirationTime();
    if ((secondExpiryTime - firstExpiryTime) <= 0) {
        fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
    }
    // now set back to be more recent
    mutt = region.getAttributesMutator();
    ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
    mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire3));
    eet = region.getEntryExpiryTask(key1);
    final long thirdExpiryTime = eet.getExpirationTime();
    assertEquals(firstExpiryTime, thirdExpiryTime);
    // confirm that it still has not expired
    assertEquals(0, eventCount);
    // now set it to a really short time and make sure it expires immediately
    Wait.waitForExpiryClockToChange(region);
    final Region.Entry entry = region.getEntry(key1);
    mutt = region.getAttributesMutator();
    ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
    mutt.setCustomEntryIdleTimeout(new TestExpiry(key1, expire4));
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return fetchEntryValue(entry) == null;
        }

        public String description() {
            return "entry never became invalid";
        }
    };
    Wait.waitForCriterion(wc, 10 * 1000, 10, true);
    WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {

        public boolean done() {
            return eventCount == 1;
        }

        public String description() {
            return "eventCount never became 1";
        }
    };
    Wait.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
    eventCount = 0;
}
Also used : EntryExpiryTask(org.apache.geode.internal.cache.EntryExpiryTask) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Entry(org.apache.geode.cache.Region.Entry) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 57 with Entry

use of org.apache.geode.cache.Region.Entry in project geode by apache.

the class RegionTestCase method testEntryUserAttribute.

/**
   * Tests a region entry's user attribute
   */
@Test
public void testEntryUserAttribute() throws CacheException {
    String name = this.getUniqueName();
    String key = "KEY";
    String attr = "USER_ATTRIBUTE";
    Region region = createRegion(name);
    region.create(key, null);
    Region.Entry entry = region.getEntry(key);
    entry.setUserAttribute(attr);
    assertEquals(attr, entry.getUserAttribute());
    entry = region.getEntry(key);
    assertEquals(attr, entry.getUserAttribute());
}
Also used : Entry(org.apache.geode.cache.Region.Entry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 58 with Entry

use of org.apache.geode.cache.Region.Entry in project geode by apache.

the class RegionTestCase method testCustomEntryTtl2.

/**
   * Verify that special entries don't expire but other entries in the region do
   */
@Test
public void testCustomEntryTtl2() {
    final String name = this.getUniqueName();
    // ms
    final int timeout = 20;
    final String key1 = "KEY1";
    final String key2 = "KEY2";
    final String value = "VALUE";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    // factory.setEntryIdleTimeout(expire);
    ExpirationAttributes expire2 = new ExpirationAttributes(timeout, ExpirationAction.INVALIDATE);
    factory.setCustomEntryTimeToLive(new TestExpiry(key2, expire2));
    factory.setStatisticsEnabled(true);
    TestCacheListener list = new TestCacheListener() {

        public void afterCreate2(EntryEvent e) {
        }

        public void afterUpdate2(EntryEvent e) {
        }

        public void afterInvalidate2(EntryEvent e) {
        }
    };
    factory.addCacheListener(list);
    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);
    }
    region.create(key1, value);
    // This value should NOT expire.
    Wait.pause(timeout * 2);
    assertTrue(region.get(key1).equals(value));
    // This value SHOULD expire
    // DebuggerSupport.waitForJavaDebugger(getLogWriter(), "Set breakpoint in invalidate");
    ExpiryTask.suspendExpiration();
    Region.Entry entry = null;
    long tilt;
    try {
        region.create(key2, value);
        tilt = System.currentTimeMillis() + timeout;
        entry = region.getEntry(key2);
        assertTrue(list.waitForInvocation(5000));
        assertNotNull(entry.getValue());
    } finally {
        ExpiryTask.permitExpiration();
    }
    waitForInvalidate(entry, tilt);
    // First value should still be in there
    assertTrue(region.get(key1).equals(value));
    // Do it again with a put (I guess)
    ExpiryTask.suspendExpiration();
    try {
        region.put(key2, value);
        tilt = System.currentTimeMillis() + timeout;
        entry = region.getEntry(key2);
        assertNotNull(entry.getValue());
    } finally {
        ExpiryTask.permitExpiration();
    }
    waitForInvalidate(entry, tilt);
    // First value should still be in there
    assertTrue(region.get(key1).equals(value));
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Entry(org.apache.geode.cache.Region.Entry) EntryEvent(org.apache.geode.cache.EntryEvent) 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 59 with Entry

use of org.apache.geode.cache.Region.Entry in project geode by apache.

the class TXState method getEntryOnRemote.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.InternalDataView#getEntryOnRemote(java.lang.Object,
   * org.apache.geode.internal.cache.LocalRegion)
   */
public Entry getEntryOnRemote(KeyInfo key, LocalRegion localRegion, boolean allowTombstones) throws DataLocationException {
    PartitionedRegion pr = (PartitionedRegion) localRegion;
    Region.Entry txval = getEntry(key, pr, allowTombstones);
    if (txval == null) {
        throw new EntryNotFoundException(LocalizedStrings.PartitionedRegionDataStore_ENTRY_NOT_FOUND.toLocalizedString());
    } else {
        NonLocalRegionEntry nlre = new NonLocalRegionEntry(txval, localRegion);
        LocalRegion dataReg = localRegion.getDataRegionForRead(key);
        return new EntrySnapshot(nlre, dataReg, (LocalRegion) txval.getRegion(), allowTombstones);
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) Region(org.apache.geode.cache.Region)

Example 60 with Entry

use of org.apache.geode.cache.Region.Entry in project geode by apache.

the class TXStateProxyImpl method getEntry.

public Entry getEntry(KeyInfo keyInfo, LocalRegion region, boolean allowTombstones) {
    try {
        this.operationCount++;
        Entry retVal = getRealDeal(keyInfo, region).getEntry(keyInfo, region, allowTombstones);
        trackBucketForTx(keyInfo);
        return retVal;
    } catch (TransactionDataRebalancedException | PrimaryBucketException re) {
        throw getTransactionException(keyInfo, re);
    }
}
Also used : Entry(org.apache.geode.cache.Region.Entry) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException)

Aggregations

Entry (org.apache.geode.cache.Region.Entry)67 Test (org.junit.Test)52 Region (org.apache.geode.cache.Region)51 LocalRegion (org.apache.geode.internal.cache.LocalRegion)37 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)37 AttributesFactory (org.apache.geode.cache.AttributesFactory)22 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)21 RegionAttributes (org.apache.geode.cache.RegionAttributes)21 VM (org.apache.geode.test.dunit.VM)13 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)13 EntryEvent (org.apache.geode.cache.EntryEvent)12 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)12 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)12 Host (org.apache.geode.test.dunit.Host)11 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)10 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 Iterator (java.util.Iterator)7