use of org.apache.geode.test.dunit.AsyncInvocation 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.test.dunit.AsyncInvocation 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.test.dunit.AsyncInvocation 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.test.dunit.AsyncInvocation in project geode by apache.
the class ConcurrentWANPropagation_1_DUnitTest method testReplicatedSerialPropagationWithLocalRegionDestroy.
/**
* Two regions configured with the same sender and put is in progress on both the regions. One of
* the two regions is destroyed in the middle.
*
* @throws Exception
*/
@Test
public void testReplicatedSerialPropagationWithLocalRegionDestroy() throws Exception {
Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
// these are part of remote site
createCacheInVMs(nyPort, vm2, vm3);
createReceiverInVMs(vm2, vm3);
// these are part of local site
createCacheInVMs(lnPort, vm4, vm5, vm6, vm7);
// senders are created on local site
vm4.invoke(() -> WANTestBase.createConcurrentSender("ln", 2, false, 100, 20, false, false, null, true, 3, OrderPolicy.THREAD));
vm5.invoke(() -> WANTestBase.createConcurrentSender("ln", 2, false, 100, 20, false, false, null, true, 3, OrderPolicy.THREAD));
// create one RR (RR_1) on remote site
vm2.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
vm3.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
// create another RR (RR_2) on remote site
vm2.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", null, isOffHeap()));
vm3.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", null, isOffHeap()));
// start the senders on local site
startSenderInVMs("ln", vm4, vm5);
// create one RR (RR_1) on local site
vm4.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
vm5.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
vm6.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
vm7.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
// create another RR (RR_2) on local site
vm4.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
vm5.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
vm6.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
vm7.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
// start puts in RR_1 in another thread
AsyncInvocation inv1 = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_RR_1", 1000));
// do puts in RR_2 in main thread
vm4.invoke(() -> WANTestBase.doPuts(getTestMethodName() + "_RR_2", 500));
// destroy RR_2 after above puts are complete
vm4.invoke(() -> WANTestBase.destroyRegion(getTestMethodName() + "_RR_2"));
try {
inv1.join();
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
// sleep for some time to let all the events propagate to remote site
Thread.sleep(20);
// vm4.invoke(() -> WANTestBase.verifyQueueSize( "ln", 0 ));
vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_RR_1", 1000));
vm3.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_RR_2", 500));
}
use of org.apache.geode.test.dunit.AsyncInvocation in project geode by apache.
the class CommonParallelGatewaySenderDUnitTest method testPRWithGatewaySenderPersistenceEnabled_Restart.
/**
* Enable persistence for GatewaySender. Pause the sender and do some puts in local region. Close
* the local site and rebuild the region and sender from disk store. Dispatcher should not start
* dispatching events recovered from persistent sender. Check if the remote site receives all the
* events. Below test is disabled intentionally 1> In this release 8.0, for rolling upgrade
* support queue name is changed to old style 2>Common parallel sender for different non colocated
* regions is not supported in 8.0 so no need to bother about
* ParallelGatewaySenderQueue#convertPathToName 3> We have to enabled it in next release 4>
* Version based rolling upgrade support should be provided. based on the version of the gemfire
* QSTRING should be used between 8.0 and version prior to 8.0
*/
@Test
@Ignore("TODO")
public void testPRWithGatewaySenderPersistenceEnabled_Restart() {
// create locator on local site
Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
// create locator on remote site
Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
// create receiver on remote site
createCacheInVMs(nyPort, vm2, vm3);
createReceiverInVMs(vm2, vm3);
// create cache in local site
createCacheInVMs(lnPort, vm4, vm5, vm6, vm7);
// create senders with disk store
String diskStore1 = (String) vm4.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, null, true));
String diskStore2 = (String) vm5.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, null, true));
String diskStore3 = (String) vm6.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, null, true));
String diskStore4 = (String) vm7.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, null, true));
LogWriterUtils.getLogWriter().info("The DS are: " + diskStore1 + "," + diskStore2 + "," + diskStore3 + "," + diskStore4);
// create PR on remote site
vm2.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", null, 1, 100, isOffHeap()));
vm3.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", null, 1, 100, isOffHeap()));
// create PR on remote site
vm2.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", null, 1, 100, isOffHeap()));
vm3.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", null, 1, 100, isOffHeap()));
// create PR on local site
vm4.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
vm5.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
vm6.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
vm7.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
// create PR on local site
vm4.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
vm5.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
vm6.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
vm7.invoke(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
// start the senders on local site
startSenderInVMs("ln", vm4, vm5, vm6, vm7);
// wait for senders to become running
vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm5.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm6.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm7.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
// pause the senders
vm4.invoke(() -> WANTestBase.pauseSender("ln"));
vm5.invoke(() -> WANTestBase.pauseSender("ln"));
vm6.invoke(() -> WANTestBase.pauseSender("ln"));
vm7.invoke(() -> WANTestBase.pauseSender("ln"));
// start puts in region on local site
vm4.invoke(() -> WANTestBase.doPuts(getTestMethodName() + "PR1", 3000));
vm4.invoke(() -> WANTestBase.doPuts(getTestMethodName() + "PR2", 5000));
LogWriterUtils.getLogWriter().info("Completed puts in the region");
// --------------------close and rebuild local site
// -------------------------------------------------
// kill the senders
vm4.invoke(() -> WANTestBase.killSender());
vm5.invoke(() -> WANTestBase.killSender());
vm6.invoke(() -> WANTestBase.killSender());
vm7.invoke(() -> WANTestBase.killSender());
LogWriterUtils.getLogWriter().info("Killed all the senders.");
// restart the vm
vm4.invoke(() -> WANTestBase.createCache(lnPort));
vm5.invoke(() -> WANTestBase.createCache(lnPort));
vm6.invoke(() -> WANTestBase.createCache(lnPort));
vm7.invoke(() -> WANTestBase.createCache(lnPort));
LogWriterUtils.getLogWriter().info("Created back the cache");
// create senders with disk store
vm4.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, diskStore1, true));
vm5.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, diskStore2, true));
vm6.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, diskStore3, true));
vm7.invoke(() -> WANTestBase.createSenderWithDiskStore("ln", 2, true, 100, 10, false, true, null, diskStore4, true));
LogWriterUtils.getLogWriter().info("Created the senders back from the disk store.");
// create PR on local site
AsyncInvocation inv1 = vm4.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
AsyncInvocation inv2 = vm5.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
AsyncInvocation inv3 = vm6.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
AsyncInvocation inv4 = vm7.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR1", "ln", 1, 100, isOffHeap()));
try {
inv1.join();
inv2.join();
inv3.join();
inv4.join();
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
inv1 = vm4.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
inv2 = vm5.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
inv3 = vm6.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
inv4 = vm7.invokeAsync(() -> WANTestBase.createPartitionedRegion(getTestMethodName() + "PR2", "ln", 1, 100, isOffHeap()));
try {
inv1.join();
inv2.join();
inv3.join();
inv4.join();
} catch (InterruptedException e) {
e.printStackTrace();
fail();
}
LogWriterUtils.getLogWriter().info("Created back the partitioned regions");
// start the senders in async mode. This will ensure that the
// node of shadow PR that went down last will come up first
startSenderInVMsAsync("ln", vm4, vm5, vm6, vm7);
LogWriterUtils.getLogWriter().info("Waiting for senders running.");
// wait for senders running
vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm5.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm6.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
vm7.invoke(() -> WANTestBase.waitForSenderRunningState("ln"));
LogWriterUtils.getLogWriter().info("All the senders are now running...");
// ----------------------------------------------------------------------------------------------------
vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "PR1", 3000));
vm3.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "PR1", 3000));
vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "PR2", 5000));
vm3.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "PR2", 5000));
}
Aggregations