use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class GlobalRegionCCEDUnitTest method testTombstoneExpirationRace.
/**
* make sure that an operation performed on a new region entry created after a tombstone has been
* reaped is accepted by another member that has yet to reap the tombstone
*/
@Test
public void testTombstoneExpirationRace() {
VM vm0 = Host.getHost(0).getVM(0);
VM vm1 = Host.getHost(0).getVM(1);
// VM vm2 = Host.getHost(0).getVM(2);
final String name = this.getUniqueName() + "-CC";
SerializableRunnable createRegion = new SerializableRunnable("Create Region") {
public void run() {
try {
RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
CCRegion = (LocalRegion) f.create(name);
CCRegion.put("cckey0", "ccvalue");
// version number will end up at 4
CCRegion.put("cckey0", "ccvalue");
} catch (CacheException ex) {
Assert.fail("While creating region", ex);
}
}
};
vm0.invoke(createRegion);
vm1.invoke(createRegion);
// vm2.invoke(createRegion);
vm1.invoke(new SerializableRunnable("Create local tombstone and adjust time") {
public void run() {
// make the entry for cckey0 a tombstone in this VM and set its
// modification time to be older than the tombstone GC interval. This
// means it could be in the process of being reaped by distributed-GC
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
VersionTag tag = entry.getVersionStamp().asVersionTag();
assertTrue(tag.getEntryVersion() > 1);
tag.setVersionTimeStamp(System.currentTimeMillis() - TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT - 1000);
entry.getVersionStamp().setVersionTimeStamp(tag.getVersionTimeStamp());
try {
entry.makeTombstone(CCRegion, tag);
} catch (RegionClearedException e) {
Assert.fail("region was mysteriously cleared during unit testing", e);
}
}
});
// now remove the entry on vm0, simulating that it initiated a GC, and
// perform a CREATE with a new version number
vm0.invoke(new SerializableRunnable("Locally destroy the entry and do a create that will be propagated with v1") {
public void run() {
CCRegion.getRegionMap().removeEntry("cckey0", CCRegion.getRegionEntry("cckey0"), true);
if (CCRegion.getRegionEntry("ckey0") != null) {
fail("expected removEntry to remove the entry from the region's map");
}
CCRegion.put("cckey0", "updateAfterReap");
}
});
vm1.invoke(new SerializableRunnable("Check that the create() was applied") {
public void run() {
RegionEntry entry = CCRegion.getRegionEntry("cckey0");
assertTrue(entry.getVersionStamp().getEntryVersion() == 1);
}
});
disconnectAllFromDS();
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class RRSynchronizationDUnitTest method createEntry2.
private boolean createEntry2(VM vm, final InternalDistributedMember forMember, final VersionSource memberVersionID) {
return (Boolean) vm.invoke(new SerializableCallable("create entry2") {
public Object call() {
// create a fake event that looks like it came from the lost member and apply it to
// this cache
DistributedRegion dr = (DistributedRegion) TestRegion;
VersionTag tag = new VMVersionTag();
tag.setMemberID(memberVersionID);
tag.setRegionVersion(2);
tag.setEntryVersion(1);
tag.setIsRemoteForTesting();
EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "Object3", true, forMember, true, false);
LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
event.setNewValue(new VMCachedDeserializable("value3", 12));
event.setVersionTag(tag);
dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
event.release();
// now create a tombstone so we can be sure these are transferred in delta-GII
tag = new VMVersionTag();
tag.setMemberID(memberVersionID);
tag.setRegionVersion(3);
tag.setEntryVersion(1);
tag.setIsRemoteForTesting();
event = EntryEventImpl.create(dr, Operation.CREATE, "Object5", true, forMember, true, false);
event.setNewValue(Token.TOMBSTONE);
event.setVersionTag(tag);
LogWriterUtils.getLogWriter().info("applying this event to the cache: " + event);
dr.getRegionMap().basicPut(event, System.currentTimeMillis(), true, false, null, false, false);
event.release();
dr.dumpBackingMap();
LogWriterUtils.getLogWriter().info("version vector is now " + dr.getVersionVector().fullToString());
assertTrue("should hold entry Object3 now", dr.containsKey("Object3"));
return true;
}
});
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class DiskRegionTestingBase method compareVersionTags.
protected void compareVersionTags(HashMap<String, VersionTag> map1, HashMap<String, VersionTag> map2) {
assertEquals(map1.size(), map2.size());
for (String key : map1.keySet()) {
VersionTag tag1 = map1.get(key);
VersionTag tag2 = map2.get(key);
assertEquals(tag1.getEntryVersion(), tag2.getEntryVersion());
assertEquals(tag1.getRegionVersion(), tag2.getRegionVersion());
assertEquals(tag1.getMemberID(), tag2.getMemberID());
}
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class DiskRegionTestingBase method saveVersionTags.
protected HashMap<String, VersionTag> saveVersionTags(LocalRegion region) {
HashMap<String, VersionTag> tagmap = new HashMap<String, VersionTag>();
Iterator entryItr = region.entrySet().iterator();
while (entryItr.hasNext()) {
RegionEntry entry = ((NonTXEntry) entryItr.next()).getRegionEntry();
String key = (String) entry.getKey();
VersionTag tag = entry.getVersionStamp().asVersionTag();
tagmap.put(key, tag);
}
return tagmap;
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class DistributedRegionSearchLoadJUnitTest method createSearchLoad.
private void createSearchLoad() {
SearchLoadAndWriteProcessor proc = mock(SearchLoadAndWriteProcessor.class);
PowerMockito.mockStatic(SearchLoadAndWriteProcessor.class);
PowerMockito.when(SearchLoadAndWriteProcessor.getProcessor()).thenReturn(proc);
VersionTag tag = createVersionTag(true);
doAnswer(new Answer<EntryEventImpl>() {
public EntryEventImpl answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
if (args[0] instanceof EntryEventImpl) {
EntryEventImpl event = (EntryEventImpl) args[0];
event.setNewValue("NewLoadedValue");
event.setOperation(Operation.LOCAL_LOAD_CREATE);
}
return null;
}
}).when(proc).doSearchAndLoad(any(EntryEventImpl.class), anyObject(), anyObject());
}
Aggregations