use of org.apache.geode.cache30.CacheSerializableRunnable 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.cache30.CacheSerializableRunnable in project geode by apache.
the class PutAllCSDUnitTest method testPRServer.
/**
* Tests putAll to 2 PR servers.
*/
@Test
public void testPRServer() throws CacheException, InterruptedException {
final String title = "testPRServer:";
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 <true, false> means <PR=true, notifyBySubscription=false> to test local-invalidates
final int serverPort1 = createBridgeServer(server1, regionName, 0, true, 1, null);
final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 1, null);
createBridgeClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, 59000, false);
createBridgeClient(client2, regionName, serverHost, new int[] { serverPort2 }, -1, 59000, false);
client2.invoke(new CacheSerializableRunnable(title + "client2 add listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(false));
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 add listener and putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(false));
doPutAll(regionName, "key-", numberOfEntries);
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().setCacheWriter(new MyWriter("key-"));
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().setCacheWriter(new MyWriter("key-"));
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "verify client2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doRemoveAll(regionName, "key-", numberOfEntries);
assertEquals(0, region.size());
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify removeAll Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
MyWriter mywriter = (MyWriter) region.getAttributes().getCacheWriter();
LogWriterUtils.getLogWriter().info("server cachewriter triggered for destroy: " + mywriter.num_destroyed);
// beforeDestroys are only triggered at primary buckets. server1 and server2 each holds half
// of buckets
assertEquals(numberOfEntries / 2, mywriter.num_destroyed);
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
MyWriter mywriter = (MyWriter) region.getAttributes().getCacheWriter();
LogWriterUtils.getLogWriter().info("server cachewriter triggered for destroy: " + mywriter.num_destroyed);
// beforeDestroys are only triggered at primary buckets. server1 and server2 each holds half
// of buckets
assertEquals(numberOfEntries / 2, mywriter.num_destroyed);
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
// Execute client putAll from multithread client
{
AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll1 from client1") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "async1key-", numberOfEntries);
}
});
AsyncInvocation async2 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll2 from client1") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "async2key-", numberOfEntries);
}
});
ThreadUtils.join(async1, 30 * 1000);
ThreadUtils.join(async2, 30 * 1000);
}
client1.invoke(new CacheSerializableRunnable(title + "verify client 1 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
long ts1 = 0, ts2 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("async1key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
obj = (TestObject) region.getEntry("async2key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts2);
ts2 = obj.getTS();
}
}
});
// verify bridge server 2 for asyn keys
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
long ts1 = 0, ts2 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("async1key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
obj = (TestObject) region.getEntry("async2key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts2);
ts2 = obj.getTS();
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify async putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries * 2);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("async1key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("async2key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
{
// Execute client removeAll from multithread client
AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll1 from client1") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "async1key-", numberOfEntries);
}
});
AsyncInvocation async2 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll2 from client1") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "async2key-", numberOfEntries);
}
});
ThreadUtils.join(async1, 30 * 1000);
ThreadUtils.join(async2, 30 * 1000);
}
client1.invoke(new CacheSerializableRunnable(title + "client1 removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doRemoveAll(regionName, "key-", numberOfEntries);
assertEquals(0, region.size());
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify async removeAll Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify async removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify async removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
// Execute p2p putAll
server1.invoke(new CacheSerializableRunnable(title + "server1 execute P2P putAll") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "p2pkey-", numberOfEntries);
Region region = getRootRegion().getSubregion(regionName);
long ts1 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("p2pkey-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
}
}
});
// verify bridge server 2 for p2p keys
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
long ts1 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("p2pkey-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify p2p putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("p2pkey-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 verify p2p putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("p2pkey-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
// Execute p2p removeAll
server1.invoke(new CacheSerializableRunnable(title + "server1 execute P2P removeAll") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "p2pkey-", numberOfEntries);
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify p2p removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify p2p removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 verify p2p removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
// putAll at client2 to trigger local-invalidates at client1
client2.invoke(new CacheSerializableRunnable(title + "execute putAll on client2 for key 0-10") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "key-", 10);
}
});
// verify client 2 for key 0-10
client1.invoke(new CacheSerializableRunnable(title + "verify client1 for local invalidate") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(regionName);
for (int i = 0; i < 10; i++) {
final int ii = i;
WaitCriterion ev = new WaitCriterion() {
@Override
public boolean done() {
Entry entry = region.getEntry("key-" + ii);
return entry != null && entry.getValue() == null;
}
@Override
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 1000, true);
// local invalidate will set the value to null
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(null, obj);
}
}
});
// Stop server
stopBridgeServers(getCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class PutAllCSDUnitTest method test2Server.
/**
* Tests putAll and removeAll to 2 servers. Use Case: 1) putAll from a single-threaded client to a
* replicated region 2) putAll from a multi-threaded client to a replicated region 3)
*/
@Test
public void test2Server() throws CacheException, InterruptedException {
final String title = "test2Server:";
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=false to test local-invalidates
final int serverPort1 = createBridgeServer(server1, regionName, 0, false, 0, null);
final int serverPort2 = createBridgeServer(server2, regionName, 0, false, 0, null);
createBridgeClient(client1, regionName, serverHost, new int[] { serverPort1 }, -1, -1, true);
createBridgeClient(client2, regionName, serverHost, new int[] { serverPort2 }, -1, -1, true);
client2.invoke(new CacheSerializableRunnable(title + "client2 add listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(false));
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 add listener and putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(false));
doPutAll(regionName, "key-", numberOfEntries);
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().setCacheWriter(new MyWriter("key-"));
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().setCacheWriter(new MyWriter("key-"));
assertEquals(numberOfEntries, region.size());
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(i, obj.getPrice());
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doRemoveAll(regionName, "key-", numberOfEntries);
assertEquals(0, region.size());
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify removeAll Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
MyWriter mywriter = (MyWriter) region.getAttributes().getCacheWriter();
LogWriterUtils.getLogWriter().info("server cachewriter triggered for destroy: " + mywriter.num_destroyed);
assertEquals(numberOfEntries, mywriter.num_destroyed);
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
MyWriter mywriter = (MyWriter) region.getAttributes().getCacheWriter();
LogWriterUtils.getLogWriter().info("server cachewriter triggered for destroy: " + mywriter.num_destroyed);
// beforeDestroys are only triggered at server1 since the removeAll is submitted from
// client1
assertEquals(0, mywriter.num_destroyed);
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
{
// Execute client putAll from multithread client
AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll1 from client1") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "async1key-", numberOfEntries);
}
});
AsyncInvocation async2 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll2 from client1") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "async2key-", numberOfEntries);
}
});
ThreadUtils.join(async1, 30 * 1000);
ThreadUtils.join(async2, 30 * 1000);
}
client1.invoke(new CacheSerializableRunnable(title + "verify client 1 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
long ts1 = 0, ts2 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("async1key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
obj = (TestObject) region.getEntry("async2key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts2);
ts2 = obj.getTS();
}
}
});
// verify bridge server 1 for asyn keys
server1.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 1 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
long ts1 = 0, ts2 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("async1key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
obj = (TestObject) region.getEntry("async2key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts2);
ts2 = obj.getTS();
}
}
});
// verify bridge server 2 for asyn keys
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2 for async keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries * 2, region.size());
long ts1 = 0, ts2 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("async1key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
obj = (TestObject) region.getEntry("async2key-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts2);
ts2 = obj.getTS();
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify async putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries * 2);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("async1key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("async2key-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
{
// Execute client removeAll from multithread client
AsyncInvocation async1 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll1 from client1") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "async1key-", numberOfEntries);
}
});
AsyncInvocation async2 = client1.invokeAsync(new CacheSerializableRunnable(title + "async putAll2 from client1") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "async2key-", numberOfEntries);
}
});
ThreadUtils.join(async1, 30 * 1000);
ThreadUtils.join(async2, 30 * 1000);
}
client1.invoke(new CacheSerializableRunnable(title + "client1 removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
doRemoveAll(regionName, "key-", numberOfEntries);
assertEquals(0, region.size());
}
});
// verify bridge server 1, its data are from client
server1.invoke(new CacheSerializableRunnable(title + "verify async removeAll Bridge Server 1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify async removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify async removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
// Execute p2p putAll
server1.invoke(new CacheSerializableRunnable(title + "server1 execute P2P putAll") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "p2pkey-", numberOfEntries);
Region region = getRootRegion().getSubregion(regionName);
long ts1 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("p2pkey-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
}
}
});
// verify bridge server 2 for p2p keys
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge Server 2 for p2p keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
long ts1 = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("p2pkey-" + i).getValue();
assertEquals(i, obj.getPrice());
assertTrue(obj.getTS() >= ts1);
ts1 = obj.getTS();
}
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify p2p putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("p2pkey-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 verify p2p putAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, numberOfEntries);
for (int i = 0; i < numberOfEntries; i++) {
Region.Entry re = region.getEntry("p2pkey-" + i);
assertNotNull(re);
assertEquals(null, re.getValue());
}
}
});
// Execute p2p removeAll
server1.invoke(new CacheSerializableRunnable(title + "server1 execute P2P removeAll") {
@Override
public void run2() throws CacheException {
doRemoveAll(regionName, "p2pkey-", numberOfEntries);
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
// verify bridge server 2, because its data are from distribution
server2.invoke(new CacheSerializableRunnable(title + "verify p2p removeAll Bridge Server 2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(0, region.size());
}
});
client2.invoke(new CacheSerializableRunnable(title + "client2 verify p2p removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
client1.invoke(new CacheSerializableRunnable(title + "client1 verify p2p removeAll") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
checkRegionSize(region, 0);
}
});
// putAll at client2 to trigger local-invalidates at client1
client2.invoke(new CacheSerializableRunnable(title + "execute putAll on client2 for key 0-10") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "key-", 10);
}
});
// verify client 2 for key 0-10
client1.invoke(new CacheSerializableRunnable(title + "verify client1 for local invalidate") {
@Override
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(regionName);
for (int i = 0; i < 10; i++) {
final int ii = i;
WaitCriterion ev = new WaitCriterion() {
@Override
public boolean done() {
Entry entry = region.getEntry("key-" + ii);
return entry != null && entry.getValue() == null;
}
@Override
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 1000, true);
// local invalidate will set the value to null
TestObject obj = null;
obj = (TestObject) region.getEntry("key-" + i).getValue();
assertEquals(null, obj);
}
}
});
// clean up
// Stop server
stopBridgeServers(getCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable 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.cache30.CacheSerializableRunnable in project geode by apache.
the class QueryMonitorDUnitTest method testQueryExecutionLocallyAndCacheOp.
/**
* Tests query execution on local vm.
*/
@Test
public void testQueryExecutionLocallyAndCacheOp() throws Exception {
setup(2);
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
final int numberOfEntries = 1000;
// Start server
// All
server1.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
// the
// queries
// taking
// more
// than
// 20ms
// should
// be
// canceled
// by
// Query
// monitor.
server1.invoke("createRegion", () -> createRegion());
// All
server2.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
// the
// queries
// taking
// more
// than
// 20ms
// should
// be
// canceled
// by
// Query
// monitor.
server2.invoke("createRegion", () -> createRegion());
// Initialize server regions.
server1.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
// Initialize server regions.
server2.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
// Execute server queries
SerializableRunnable executeQuery = new CacheSerializableRunnable("Execute queries") {
public void run2() throws CacheException {
try {
QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
String qStr = "SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion x, x.positions.values pos" + " WHERE x.ID = p.ID) as itrX";
executeQuery(queryService, qStr);
// Create index and Perform cache op. Bug#44307
queryService.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/root/exampleRegion");
queryService.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/root/exampleRegion");
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
for (int i = (1 + 100); i <= (numberOfEntries + 200); i++) {
exampleRegion.put("" + i, new Portfolio(i));
}
} catch (Exception ex) {
Assert.fail("Exception creating the query service", ex);
}
}
};
server1.invoke(executeQuery);
server2.invoke(executeQuery);
stopServer(server1);
stopServer(server2);
}
Aggregations