use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class PutAllCSDUnitTest method testVersionsOnClientsWithNotificationsOnly.
@Test
public void testVersionsOnClientsWithNotificationsOnly() {
final String title = "testVersionsInClients";
disconnectAllFromDS();
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client1 = host.getVM(2);
VM client2 = host.getVM(3);
final String regionName = getUniqueName();
final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
// set notifyBySubscription=true to test register interest
final int serverPort1 = createBridgeServer(server1, regionName, 0, true, 0, null);
final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 0, null);
// set queueRedundency=1
createBridgeClient(client1, regionName, serverHost, new int[] { serverPort1 }, 0, 59000, true);
createBridgeClient(client2, regionName, serverHost, new int[] { serverPort2 }, 0, 59000, true);
server1.invoke(addExceptionTag1(expectedExceptions));
server2.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(addExceptionTag1(expectedExceptions));
client2.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(new CacheSerializableRunnable(title + "client1 putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doPutAll(regionName, "key-", numberOfEntries * 2);
assertEquals(numberOfEntries * 2, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 versions collection") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.registerInterest("ALL_KEYS");
LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
}
});
client1Versions = (List<VersionTag>) client1.invoke(new SerializableCallable(title + "client1 versions collection") {
@Override
public Object call() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
RegionMap entries = ((LocalRegion) region).entries;
for (Object key : entries.keySet()) {
RegionEntry internalRegionEntry = entries.getEntry(key);
VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
versions.add(tag);
}
return versions;
}
});
client2Versions = (List<VersionTag>) client2.invoke(new SerializableCallable(title + "client2 versions collection") {
@Override
public Object call() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
RegionMap entries = ((LocalRegion) region).entries;
for (Object key : entries.keySet()) {
RegionEntry internalRegionEntry = entries.getEntry(key);
VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
versions.add(tag);
}
return versions;
}
});
assertEquals(numberOfEntries * 2, client1Versions.size());
LogWriterUtils.getLogWriter().info(Arrays.toString(client1Versions.toArray()));
LogWriterUtils.getLogWriter().info(Arrays.toString(client2Versions.toArray()));
for (VersionTag tag : client1Versions) {
if (!client2Versions.contains(tag)) {
fail("client 2 does not have the tag contained in client 1" + tag);
}
}
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class PutAllCSDUnitTest method testRAVersionsOnClientsWithNotificationsOnly.
/**
* basically same test as testVersionsOnClientsWithNotificationsOnly but also do a removeAll
*/
// GEODE-1419
@Category(FlakyTest.class)
@Test
public void testRAVersionsOnClientsWithNotificationsOnly() {
final String title = "testRAVersionsInClients";
disconnectAllFromDS();
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client1 = host.getVM(2);
VM client2 = host.getVM(3);
final String regionName = getUniqueName();
final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
// set notifyBySubscription=true to test register interest
final int serverPort1 = createBridgeServer(server1, regionName, 0, true, 0, null);
final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 0, null);
// set queueRedundency=1
createBridgeClient(client1, regionName, serverHost, new int[] { serverPort1 }, 0, 59000, true);
createBridgeClient(client2, regionName, serverHost, new int[] { serverPort2 }, 0, 59000, true);
server1.invoke(addExceptionTag1(expectedExceptions));
server2.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(addExceptionTag1(expectedExceptions));
client2.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(new CacheSerializableRunnable(title + "client1 putAll+removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doPutAll(regionName, "key-", numberOfEntries * 2);
assertEquals(numberOfEntries * 2, region.size());
doRemoveAll(regionName, "key-", numberOfEntries);
assertEquals(numberOfEntries, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 versions collection") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.registerInterest("ALL_KEYS");
assertEquals(numberOfEntries, region.size());
LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
}
});
client1RAVersions = (List<VersionTag>) client1.invoke(new SerializableCallable(title + "client1 versions collection") {
@Override
public Object call() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries, region.size());
List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
RegionMap entries = ((LocalRegion) region).entries;
assertEquals(numberOfEntries * 2, entries.size());
for (Object key : entries.keySet()) {
RegionEntry internalRegionEntry = entries.getEntry(key);
VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
versions.add(tag);
}
return versions;
}
});
client2RAVersions = (List<VersionTag>) client2.invoke(new SerializableCallable(title + "client2 versions collection") {
@Override
public Object call() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries, region.size());
List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
RegionMap entries = ((LocalRegion) region).entries;
assertEquals(numberOfEntries * 2, entries.size());
for (Object key : entries.keySet()) {
RegionEntry internalRegionEntry = entries.getEntry(key);
VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
versions.add(tag);
}
return versions;
}
});
assertEquals(numberOfEntries * 2, client1RAVersions.size());
LogWriterUtils.getLogWriter().info(Arrays.toString(client1RAVersions.toArray()));
LogWriterUtils.getLogWriter().info(Arrays.toString(client2RAVersions.toArray()));
for (VersionTag tag : client1RAVersions) {
if (!client2RAVersions.contains(tag)) {
fail("client 2 does not have the tag contained in client 1" + tag);
}
}
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithParallelSender.
@Test
public void testUpdateVersionAfterCreateWithParallelSender() {
Host host = Host.getHost(0);
// server1 site1
VM vm0 = host.getVM(0);
// server2 site1
VM vm1 = host.getVM(1);
// server1 site2
VM vm2 = host.getVM(2);
// server2 site2
VM vm3 = host.getVM(3);
// Site 1
Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
final String key = "key-1";
vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
vm0.invoke(() -> UpdateVersionDUnitTest.createSender("ln1", 2, true, 10, 1, false, false, null, true));
vm0.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "ln1", 1, 1));
vm0.invoke(() -> UpdateVersionDUnitTest.startSender("ln1"));
vm0.invoke(() -> UpdateVersionDUnitTest.waitForSenderRunningState("ln1"));
// Site 2
Integer nyPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createFirstRemoteLocator(2, lnPort));
Integer nyRecPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createReceiver(nyPort));
vm2.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
vm3.invoke(() -> UpdateVersionDUnitTest.createPartitionedRegion(regionName, "", 1, 1));
final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Put a single entry and get its version") {
@Override
public Object call() throws CacheException {
Cache cache = CacheFactory.getAnyInstance();
Region region = cache.getRegion(regionName);
assertTrue(region instanceof PartitionedRegion);
region.put(key, "value-1");
region.put(key, "value-2");
Entry entry = region.getEntry(key);
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.
VersionSource memberId = (VersionSource) cache.getDistributedSystem().getDistributedMember();
VersionTag tag = VersionTag.create(memberId);
int entryVersion = stamp.getEntryVersion() - 1;
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis();
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsRemoteForTesting();
EntryEventImpl event = createNewEvent((PartitionedRegion) region, tag, entry.getKey(), "value-3");
((LocalRegion) region).basicUpdate(event, false, true, 0L, false);
// Verify the new stamp
entry = region.getEntry(key);
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(dsid, stamp.getDistributedSystemId());
return stamp.asVersionTag();
}
});
VersionTag remoteTag = (VersionTag) vm3.invoke(new SerializableCallable("Get timestamp from remote site") {
@Override
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
final PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
// wait for entry to be received
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
Entry<?, ?> entry = null;
try {
entry = region.getDataStore().getEntryLocally(0, key, false, false);
} catch (EntryNotFoundException e) {
// expected
} catch (ForceReattemptException e) {
// expected
} catch (PRLocallyDestroyedException e) {
throw new RuntimeException("unexpected exception", e);
}
if (entry != null) {
LogWriterUtils.getLogWriter().info("found entry " + entry);
}
return (entry != null);
}
public String description() {
return "Expected key-1 to be received on remote WAN site";
}
};
Wait.waitForCriterion(wc, 30000, 500, true);
wc = new WaitCriterion() {
public boolean done() {
Entry entry = region.getEntry(key);
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
return regionEntry.getVersionStamp().getVersionTimeStamp() == tag.getVersionTimeStamp();
}
public String description() {
return "waiting for timestamp to be updated";
}
};
Wait.waitForCriterion(wc, 30000, 500, true);
Entry entry = region.getEntry(key);
assertTrue(entry instanceof EntrySnapshot);
RegionEntry regionEntry = ((EntrySnapshot) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
return stamp.asVersionTag();
}
});
assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class UpdateVersionDUnitTest method testUpdateVersionAfterCreateWithSerialSenderOnDR.
@Test
public void testUpdateVersionAfterCreateWithSerialSenderOnDR() {
Host host = Host.getHost(0);
// server1 site1
VM vm0 = host.getVM(0);
// server2 site1
VM vm1 = host.getVM(1);
// server1 site2
VM vm2 = host.getVM(2);
// server2 site2
VM vm3 = host.getVM(3);
final String key = "key-1";
// Site 1
Integer lnPort = (Integer) vm0.invoke(() -> UpdateVersionDUnitTest.createFirstLocatorWithDSId(1));
vm0.invoke(() -> UpdateVersionDUnitTest.createCache(lnPort));
vm0.invoke(() -> UpdateVersionDUnitTest.createSender("ln1", 2, false, 10, 1, false, false, null, true));
vm0.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, "ln1"));
vm0.invoke(() -> UpdateVersionDUnitTest.startSender("ln1"));
vm0.invoke(() -> UpdateVersionDUnitTest.waitForSenderRunningState("ln1"));
// Site 2
Integer nyPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createFirstRemoteLocator(2, lnPort));
Integer nyRecPort = (Integer) vm2.invoke(() -> UpdateVersionDUnitTest.createReceiver(nyPort));
vm2.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
vm3.invoke(() -> UpdateVersionDUnitTest.createCache(nyPort));
vm3.invoke(() -> UpdateVersionDUnitTest.createReplicatedRegion(regionName, ""));
final VersionTag tag = (VersionTag) vm0.invoke(new SerializableCallable("Update a single entry and get its version") {
@Override
public Object call() throws CacheException {
Cache cache = CacheFactory.getAnyInstance();
Region region = cache.getRegion(regionName);
assertTrue(region instanceof DistributedRegion);
region.put(key, "value-1");
region.put(key, "value-2");
Entry entry = region.getEntry(key);
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.
VersionSource memberId = (VersionSource) cache.getDistributedSystem().getDistributedMember();
VersionTag tag = VersionTag.create(memberId);
int entryVersion = stamp.getEntryVersion() - 1;
int dsid = stamp.getDistributedSystemId();
long time = System.currentTimeMillis();
tag.setEntryVersion(entryVersion);
tag.setDistributedSystemId(dsid);
tag.setVersionTimeStamp(time);
tag.setIsRemoteForTesting();
EntryEventImpl event = createNewEvent((DistributedRegion) region, tag, entry.getKey(), "value-3");
((LocalRegion) region).basicUpdate(event, false, true, 0L, false);
// Verify the new stamp
entry = region.getEntry(key);
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 + 1, stamp.getEntryVersion());
assertEquals(dsid, stamp.getDistributedSystemId());
return stamp.asVersionTag();
}
});
VersionTag remoteTag = (VersionTag) vm3.invoke(new SerializableCallable("Get timestamp from remote site") {
@Override
public Object call() throws Exception {
Cache cache = CacheFactory.getAnyInstance();
final Region region = cache.getRegion(regionName);
// wait for entry to be received
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return (region.getEntry(key) != null);
}
public String description() {
return "Expected key-1 to be received on remote WAN site";
}
};
Wait.waitForCriterion(wc, 30000, 500, true);
wc = new WaitCriterion() {
public boolean done() {
Entry entry = region.getEntry(key);
assertTrue(entry instanceof NonTXEntry);
RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
return regionEntry.getVersionStamp().getVersionTimeStamp() == tag.getVersionTimeStamp();
}
public String description() {
return "waiting for timestamp to be updated";
}
};
Wait.waitForCriterion(wc, 30000, 500, true);
Entry entry = region.getEntry(key);
assertTrue(entry instanceof NonTXEntry);
RegionEntry regionEntry = ((NonTXEntry) entry).getRegionEntry();
VersionStamp stamp = regionEntry.getVersionStamp();
return stamp.asVersionTag();
}
});
assertEquals("Local and remote site have different timestamps", tag.getVersionTimeStamp(), remoteTag.getVersionTimeStamp());
}
use of org.apache.geode.internal.cache.versions.VersionTag in project geode by apache.
the class NewWANConcurrencyCheckForDestroyDUnitTest method getVersionTimestampAfterPutAllOp.
/*
* For VM1 in ds 1. Used in testPutAllEventSequenceOnSerialGatewaySender.
*/
public static long getVersionTimestampAfterPutAllOp() {
Region region = cache.getRegion("repRegion");
while (!(region.containsKey("testKey"))) {
Wait.pause(10);
}
assertEquals(1, region.size());
Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
true);
RegionEntry re = null;
if (entry instanceof EntrySnapshot) {
re = ((EntrySnapshot) entry).getRegionEntry();
} else if (entry instanceof NonTXEntry) {
re = ((NonTXEntry) entry).getRegionEntry();
}
if (re != null) {
LogWriterUtils.getLogWriter().fine("RegionEntry for testKey: " + re.getKey() + " " + re.getValueInVM((LocalRegion) region));
VersionTag tag = re.getVersionStamp().asVersionTag();
return tag.getVersionTimeStamp();
} else {
return -1;
}
}
Aggregations