use of org.apache.geode.cache.CacheException in project geode by apache.
the class PutAllCSDUnitTest method testPartialKeyInPRSingleHopWithRedundency.
/**
* Set redundancy=1 to see if retry succeeded after PRE This is a singlehop putAll test.
*/
@Test
public void testPartialKeyInPRSingleHopWithRedundency() throws CacheException, InterruptedException {
final String title = "testPartialKeyInPRSingleHopWithRedundency_";
int client1Size;
int client2Size;
int server1Size;
int server2Size;
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM server2 = host.getVM(1);
final VM client1 = host.getVM(2);
final 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, "ds1");
final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 1, "ds1");
createClient(client1, regionName, serverHost, new int[] { serverPort1, serverPort2 }, -1, -1, false, false, true, false);
createClient(client2, regionName, serverHost, new int[] { serverPort1, serverPort2 }, -1, -1, false, false, true);
server1.invoke(addExceptionTag1(expectedExceptions));
server2.invoke(addExceptionTag1(expectedExceptions));
client1.invoke(addExceptionTag1(expectedExceptions));
client2.invoke(addExceptionTag1(expectedExceptions));
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));
region.registerInterest("ALL_KEYS");
LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
}
});
client1.invoke(new CacheSerializableRunnable(title + "do some putAll to get ClientMetaData for future putAll") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, "key-", numberOfEntries);
}
});
WaitCriterion waitForSizes = new WaitCriterion() {
@Override
public String description() {
return "waiting for conditions to be met";
}
@Override
public boolean done() {
int c1Size = getRegionSize(client1, regionName);
int c2Size = getRegionSize(client2, regionName);
int s1Size = getRegionSize(server1, regionName);
int s2Size = getRegionSize(server2, regionName);
LogWriterUtils.getLogWriter().info("region sizes: " + c1Size + "," + c2Size + "," + s1Size + "," + s2Size);
if (c1Size != numberOfEntries) {
LogWriterUtils.getLogWriter().info("waiting for client1 to get all updates");
return false;
}
if (c2Size != numberOfEntries) {
LogWriterUtils.getLogWriter().info("waiting for client2 to get all updates");
return false;
}
if (s1Size != numberOfEntries) {
LogWriterUtils.getLogWriter().info("waiting for server1 to get all updates");
return false;
}
if (s2Size != numberOfEntries) {
LogWriterUtils.getLogWriter().info("waiting for server2 to get all updates");
return false;
}
return true;
}
};
Wait.waitForCriterion(waitForSizes, 10000, 1000, true);
client1Size = getRegionSize(client1, regionName);
client2Size = getRegionSize(client2, regionName);
server1Size = getRegionSize(server1, regionName);
server2Size = getRegionSize(server2, regionName);
server1.invoke(new CacheSerializableRunnable(title + "server1 add slow listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(true));
}
});
final SharedCounter sc_server2 = new SharedCounter("server2");
server2.invoke(new CacheSerializableRunnable(title + "server2 add slow listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(server2, true, sc_server2, 10));
}
});
AsyncInvocation async1 = client1.invokeAsync(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));
region.registerInterest("ALL_KEYS");
// create keys
doPutAll(regionName, title, numberOfEntries);
}
});
// server2 will closeCache after created 10 keys
ThreadUtils.join(async1, 30 * 1000);
if (async1.exceptionOccurred()) {
Assert.fail("Aync1 get exceptions:", async1.getException());
}
client1Size = getRegionSize(client1, regionName);
// client2Size maybe more than client1Size
client2Size = getRegionSize(client2, regionName);
server1Size = getRegionSize(server1, regionName);
// putAll should succeed after retry
LogWriterUtils.getLogWriter().info("region sizes: " + client1Size + "," + client2Size + "," + server1Size);
assertEquals(server1Size, client1Size);
assertEquals(server1Size, client2Size);
// restart server2
createBridgeServer(server2, regionName, serverPort2, true, 1, "ds1");
server1Size = getRegionSize(server1, regionName);
server2Size = getRegionSize(server2, regionName);
LogWriterUtils.getLogWriter().info("region sizes after server2 restarted: " + client1Size + "," + client2Size + "," + server1Size);
assertEquals(client2Size, server1Size);
assertEquals(client2Size, server2Size);
// close a server to re-run the test
closeCache(server2);
server1Size = getRegionSize(server1, regionName);
client1.invoke(new CacheSerializableRunnable(title + "client1 does putAll again") {
@Override
public void run2() throws CacheException {
doPutAll(regionName, title + "again:", numberOfEntries);
}
});
int new_server1Size = getRegionSize(server1, regionName);
int new_client1Size = getRegionSize(client1, regionName);
int new_client2Size = getRegionSize(client2, regionName);
// putAll should succeed, all the numbers should match
LogWriterUtils.getLogWriter().info("region sizes after re-run the putAll: " + new_client1Size + "," + new_client2Size + "," + new_server1Size);
assertEquals(new_server1Size, new_client1Size);
assertEquals(new_server1Size, new_client2Size);
// Stop server
stopBridgeServers(getCache());
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class PutAllCSDUnitTest method testTX.
/**
* Test TX for putAll. There's no TX for c/s. We only test P2P This is disabled because putAll in
* TX is disabled.
*/
@Ignore("TODO: test is disabled")
@Test
public void testTX() throws CacheException, InterruptedException {
final String title = "testTX:";
disconnectAllFromDS();
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
final String regionName = getUniqueName();
final int serverPort1 = createBridgeServer(server1, regionName, 0, false, 0, null);
final int serverPort2 = createBridgeServer(server2, regionName, 0, false, 0, null);
// final String serverHost = getServerHostName(server1.getHost());
// set notifyBySubscription=true to test register interest
// add slow listener
server1.invoke(new CacheSerializableRunnable(title + "server1 add slow listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(true));
}
});
server2.invoke(new CacheSerializableRunnable(title + "server2 add slow listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
region.getAttributesMutator().addCacheListener(new MyListener(true));
}
});
// TX1: server1 do a putAll
AsyncInvocation async1 = server1.invokeAsync(new CacheSerializableRunnable(title + "TX1: async putAll from server1") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
// Get JNDI(Java Naming and Directory interface) context
// CacheTransactionManager tx = getCache().getCacheTransactionManager();
LinkedHashMap map = new LinkedHashMap();
// tx.begin();
for (int i = 0; i < numberOfEntries; i++) {
// region.put("key-"+i, new TestObject(i));
map.put("key-" + i, new TestObject(i));
}
region.putAll(map, "putAllCallback");
try {
LogWriterUtils.getLogWriter().info("before commit TX1");
// tx.commit();
LogWriterUtils.getLogWriter().info("TX1 committed");
} catch (CommitConflictException e) {
LogWriterUtils.getLogWriter().info("TX1 rollbacked");
}
}
});
// we have to pause a while to let TX1 finish earlier
Wait.pause(500);
// TX2: server2 do a putAll
AsyncInvocation async2 = server2.invokeAsync(new CacheSerializableRunnable(title + "TX2: async putAll from server2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
// Get JNDI(Java Naming and Directory interface) context
// CacheTransactionManager tx = getCache().getCacheTransactionManager();
LinkedHashMap map = new LinkedHashMap();
// tx.begin();
for (int i = 0; i < numberOfEntries; i++) {
// region.put("key-"+i, new TestObject(i + numberOfEntries));
map.put("key-" + i, new TestObject(i + numberOfEntries));
}
region.putAll(map, "putAllCallback");
try {
LogWriterUtils.getLogWriter().info("before commit TX2");
// tx.commit();
LogWriterUtils.getLogWriter().info("TX2 committed");
} catch (CommitConflictException e) {
LogWriterUtils.getLogWriter().info("TX2 rollbacked");
}
}
});
// TX3: server2 do a putAll in another thread
AsyncInvocation async3 = server2.invokeAsync(new CacheSerializableRunnable(title + "TX3: async putAll from server2") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
// Get JNDI(Java Naming and Directory interface) context
// CacheTransactionManager tx = getCache().getCacheTransactionManager();
LinkedHashMap map = new LinkedHashMap();
// tx.begin();
for (int i = 0; i < numberOfEntries; i++) {
// region.put("key-"+i, new TestObject(i+numberOfEntries*2));
map.put("key-" + i, new TestObject(i + numberOfEntries * 2));
}
region.putAll(map, "putAllCallback");
try {
LogWriterUtils.getLogWriter().info("before commit TX3");
// tx.commit();
LogWriterUtils.getLogWriter().info("TX3 committed");
} catch (CommitConflictException e) {
LogWriterUtils.getLogWriter().info("TX3 rollbacked");
}
}
});
ThreadUtils.join(async1, 30 * 1000);
ThreadUtils.join(async2, 30 * 1000);
ThreadUtils.join(async3, 30 * 1000);
// verify server 2 for asyn keys
server2.invoke(new CacheSerializableRunnable(title + "verify Bridge server2 for keys") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
assertEquals(numberOfEntries, region.size());
int tx_no = 0;
for (int i = 0; i < numberOfEntries; i++) {
TestObject obj = (TestObject) region.getEntry("key-" + i).getValue();
if (tx_no == 0) {
// only check which tx took control once
if (obj.getPrice() == i) {
tx_no = 1;
} else if (obj.getPrice() == i + numberOfEntries) {
tx_no = 2;
} else if (obj.getPrice() == i + numberOfEntries * 2) {
tx_no = 3;
}
LogWriterUtils.getLogWriter().info("Verifying TX:" + tx_no);
}
if (tx_no == 1) {
assertEquals(i, obj.getPrice());
} else if (tx_no == 2) {
assertEquals(i + numberOfEntries, obj.getPrice());
} else {
assertEquals(i + numberOfEntries * 2, obj.getPrice());
}
}
}
});
// clean up
// Stop server
stopBridgeServers(getCache());
}
use of org.apache.geode.cache.CacheException 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.cache.CacheException 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.cache.CacheException 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());
}
Aggregations