use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterCreate.
/**
* Tests for LocalRegion.
*/
@Test
public void testUpdateVersionAfterCreate() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
try {
region.create("key-1", "value-1");
Entry entry = region.getEntry("key-1");
assertTrue(entry instanceof NonTXEntry);
RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis() + 1;
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
assertTrue(region instanceof LocalRegion);
EntryEventImpl event = createNewEvent((LocalRegion) region, tag, entry.getKey());
((LocalRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = region.getEntry("key-1");
assertTrue(entry instanceof NonTXEntry);
regionEntry = ((NonTXEntry) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class UpdateVersionJUnitTest method testUpdateVersionAfterDestroyOnPR.
@Test
public void testUpdateVersionAfterDestroyOnPR() {
Cache cache = new CacheFactory().set(MCAST_PORT, "0").create();
Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(regionName);
try {
region.create("key-1", "value-1");
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
region.destroy("key-1");
assertTrue(region instanceof PartitionedRegion);
Entry entry = ((PartitionedRegion) region).getEntry("key-1", true);
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
// Create a duplicate entry version tag from stamp with newer time-stamp.
VersionTag tag = VersionTag.create(stamp.getMemberID());
int entryVersion = stamp.getEntryVersion();
VersionSource member = stamp.getMemberID();
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis();
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsGatewayTag(true);
assertTrue(region instanceof PartitionedRegion);
EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, "key-1");
((PartitionedRegion) region).basicUpdateEntryVersion(event);
// Verify the new stamp
entry = ((PartitionedRegion) region).getEntry("key-1", true);
assertTrue(entry instanceof EntrySnapshot);
regionEntry = ((EntrySnapshot) entry).getRegionEntry();
stamp = regionEntry.getVersionStamp();
assertEquals("Time stamp did NOT get updated by UPDATE_VERSION operation on LocalRegion", time, stamp.getVersionTimeStamp());
assertEquals(++entryVersion, stamp.getEntryVersion());
assertEquals(member, stamp.getMemberID());
assertEquals(dsid, stamp.getDistributedSystemId());
} finally {
region.destroyRegion();
cache.close();
}
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testEntryTtlDestroy.
/**
* Tests that an entry in a region expires with a destroy after a given time to live.
*/
@Test
public void testEntryTtlDestroy() throws CacheException, InterruptedException {
final String name = this.getUniqueName();
// ms
final int timeout = 20;
final String key = "KEY";
final String value = "VALUE";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
factory.setEntryTimeToLive(expire);
factory.setStatisticsEnabled(true);
RegionAttributes attrs = factory.create();
Region region = null;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = createRegion(name, attrs);
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
region.put(key, value);
tilt = System.currentTimeMillis();
entry = region.getEntry(key);
assertNotNull(entry.getValue());
} finally {
ExpiryTask.permitExpiration();
}
waitForDestroy(entry, tilt);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class SlowRecDUnitTest method checkLastValueInOtherVm.
private void checkLastValueInOtherVm(final String lastValue, final Object lcb) {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("check last value") {
public void run2() throws CacheException {
Region r1 = getRootRegion("slowrec");
if (lcb != null) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return lcb.equals(lastCallback);
}
public String description() {
return "waiting for callback";
}
};
Wait.waitForCriterion(ev, 50 * 1000, 200, true);
assertEquals(lcb, lastCallback);
}
if (lastValue == null) {
final Region r = r1;
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return r.getEntry("key") == null;
}
public String description() {
return "waiting for key to become null";
}
};
Wait.waitForCriterion(ev, 50 * 1000, 200, true);
assertEquals(null, r1.getEntry("key"));
} else if (CHECK_INVALID.equals(lastValue)) {
// should be invalid
{
final Region r = r1;
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
Entry e = r.getEntry("key");
if (e == null) {
return false;
}
return e.getValue() == null;
}
public String description() {
return "waiting for invalidate";
}
};
Wait.waitForCriterion(ev, 50 * 1000, 200, true);
}
} else {
{
int retryCount = 1000;
Region.Entry re = null;
Object value = null;
while (retryCount-- > 0) {
re = r1.getEntry("key");
if (re != null) {
value = re.getValue();
if (value != null && value.equals(lastValue)) {
break;
}
}
try {
Thread.sleep(50);
} catch (InterruptedException ignore) {
fail("interrupted");
}
}
assertNotNull(re);
assertNotNull(value);
assertEquals(lastValue, value);
}
}
}
});
}
use of org.apache.geode.cache.Region.Entry in project geode by apache.
the class RegionTestCase method testLocalDestroyEntry.
/**
* Tests {@link Region#localDestroy locally destroying} an entry and attempting to access it
* afterwards. (Not too useful with a <code>LOCAL</code> region.)
*/
@Test
public void testLocalDestroyEntry() throws CacheException {
if (!supportsLocalDestroyAndLocalInvalidate()) {
return;
}
String name = this.getUniqueName();
Object key = name;
Object value = new Integer(42);
Region region = createRegion(name);
boolean isMirrored = getRegionAttributes().getMirrorType().isMirrored();
try {
region.localDestroy(key);
if (isMirrored)
fail("Should have thrown an IllegalStateException");
fail("Should have thrown an EntryNotFoundException");
} catch (EntryNotFoundException ex) {
// pass...
} catch (IllegalStateException ex) {
if (!isMirrored)
throw ex;
else
// abort test
return;
}
region.put(key, value);
Region.Entry entry = region.getEntry(key);
assertNotNull(entry);
region.localDestroy(key);
assertNull(region.getEntry(key));
assertTrue(entry.isDestroyed());
assertEquals(0, region.keySet().size());
try {
entry.getKey();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getRegion();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getStatistics();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getUserAttribute();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.setUserAttribute("blah");
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
try {
entry.getValue();
fail("Should have thrown an EntryDestroyedException");
} catch (EntryDestroyedException ex) {
// pass...
}
}
Aggregations