use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class QueryIndexUpdateRIDUnitTest method registerInterestList.
/* Register Interest on data on server */
public void registerInterestList(VM vm, final String regionName, final int keySize, final int policy, final int start) {
vm.invoke(new CacheSerializableRunnable("Register InterestList") {
public void run2() throws CacheException {
// Get Query Service.
Region region = null;
try {
if ("root".equals(regionName)) {
region = getRootRegion();
} else {
region = getRootRegion().getSubregion(regionName);
}
region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
} catch (Exception cqe) {
AssertionError err = new AssertionError("Failed to get Region.");
err.initCause(cqe);
throw err;
}
try {
switch(policy) {
case REGEX:
region.registerInterestRegex(REGULAR_EXPRESSION);
break;
case KEYS:
List list = new ArrayList();
for (int i = start != 0 ? start : 1; i <= keySize; i++) {
list.add(KEY + i);
}
region.registerInterest(list);
break;
default:
region.registerInterest("ALL_KEYS");
}
} catch (Exception ex) {
AssertionError err = new AssertionError("Failed to Register InterestList");
err.initCause(ex);
throw err;
}
}
});
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class DurableClientTestCase method restartDurableClient.
public void restartDurableClient(Object[] args) {
this.durableClientVM.invoke(CacheServerTestUtil.class, "createCacheClient", args);
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class DurableClientTestCase method test39630.
/**
* Test that starting, stopping then restarting a durable client is correctly processed by the
* server. This is a test of bug 39630
*/
@Test
public void test39630() {
// Start a server
int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Start a durable client that is kept alive on the server when it stops
// normally
final String durableClientId = getName() + "_client";
// keep the client alive for 60 seconds
final int durableClientTimeout = 60;
// final boolean durableClientKeepAlive = true; // keep the client alive when it stops normally
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true), regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout)));
// // Send clientReady message
// this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
// public void run2() throws CacheException {
// CacheServerTestUtil.getCache().readyForEvents();
// }
// });
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
assertEquals(durableClientTimeout, proxy.getDurableTimeout());
// assertIndexDetailsEquals(durableClientKeepAlive, proxy.getDurableKeepAlive());
}
});
// Stop the durable client
this.disconnectDurableClient(true);
// Verify the durable client still exists on the server, and the socket is closed
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
assertNotNull(proxy._socket);
long end = System.currentTimeMillis() + 60000;
while (!proxy._socket.isClosed()) {
if (System.currentTimeMillis() > end) {
break;
}
}
assertTrue(proxy._socket.isClosed());
}
});
// Re-start the durable client (this is necessary so the
// netDown test will set the appropriate system properties.
this.restartDurableClient(new Object[] { getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true), regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout) });
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class DurableClientTestCase method durableFailoverAfterReconnect.
public void durableFailoverAfterReconnect(int redundancyLevel) {
// Start server 1
Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
final int server1Port = ports[0].intValue();
final int mcastPort = ports[1].intValue();
// Start server 2 using the same mcast port as server 1
fail("Trying to get a result from a void method");
final int server2Port = 0;
// final int server2Port = ((Integer) this.server2VM.invoke(() ->
// CacheServerTestUtil.createCacheServer(regionName, new Boolean(true), new
// Integer(mcastPort))))
// .intValue();
// Start a durable client
final String durableClientId = getName() + "_client";
// keep the client alive for 60 seconds
final int durableClientTimeout = 60;
Pool clientPool;
if (redundancyLevel == 1) {
clientPool = getClientPool(NetworkUtils.getServerHostName(Host.getHost(0)), server1Port, server2Port, true);
} else {
clientPool = getClientPool(NetworkUtils.getServerHostName(Host.getHost(0)), server1Port, server2Port, true, 0);
}
this.durableClientVM.invoke(() -> CacheServerTestUtil.disableShufflingOfEndpoints());
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(clientPool, regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout), Boolean.TRUE));
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Have the durable client register interest in all keys
this.durableClientVM.invoke(new CacheSerializableRunnable("Register interest") {
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.NONE, true);
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), server1Port, server2Port, false), regionName));
// Publish some entries
final int numberOfEntries = 1;
publishEntries(numberOfEntries);
try {
java.lang.Thread.sleep(10000);
} catch (java.lang.InterruptedException ex) {
fail("interrupted");
}
// Verify the durable client received the updates
this.verifyListenerUpdates(numberOfEntries);
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
}
});
// Stop the durable client
this.disconnectDurableClient(true);
// Stop server 1 - publisher will put 10 entries during shutdown/primary identification
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
// Publish updates during client downtime
publishEntries(numberOfEntries);
// Re-start the durable client that is kept alive on the server
this.restartDurableClient(new Object[] { clientPool, regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout), Boolean.TRUE });
// Have the durable client register interest in all keys
this.durableClientVM.invoke(new CacheSerializableRunnable("Register interest") {
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.NONE, true);
}
});
// Publish second round of updates
this.publisherClientVM.invoke(new CacheSerializableRunnable("Publish entries before failover") {
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Publish some entries
for (int i = 1; i < numberOfEntries + 1; i++) {
String keyAndValue = String.valueOf(i);
region.put(keyAndValue, keyAndValue);
}
}
});
// Verify the durable client received the updates before failover
if (redundancyLevel == 1) {
this.verifyListenerUpdates(numberOfEntries + 1, numberOfEntries);
} else {
this.verifyListenerUpdates(numberOfEntries, numberOfEntries);
}
this.durableClientVM.invoke(new CacheSerializableRunnable("Get") {
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
assertNull(region.getEntry("0"));
}
});
// Publish second round of updates after failover
this.publisherClientVM.invoke(new CacheSerializableRunnable("Publish entries after failover") {
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Publish some entries
for (int i = 2; i < numberOfEntries + 2; i++) {
String keyAndValue = String.valueOf(i);
region.put(keyAndValue, keyAndValue);
}
}
});
// Verify the durable client received the updates after failover
if (redundancyLevel == 1) {
this.verifyListenerUpdates(numberOfEntries + 2, numberOfEntries);
} else {
this.verifyListenerUpdates(numberOfEntries + 1, numberOfEntries);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop server 2
this.server2VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class NewWANConcurrencyCheckForDestroyDUnitTest method testConflictChecksBasedOnDsidAndTimeStamp.
/**
* Tests if conflict checks are happening based on DSID and timestamp even if version tag is
* generated in local distributed system.
*/
@Test
public void testConflictChecksBasedOnDsidAndTimeStamp() {
// create two distributed systems with each having a cache containing
// a Replicated Region with one entry and concurrency checks enabled.
// Site 1
Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
createCacheInVMs(lnPort, vm1);
Integer lnRecPort = (Integer) vm1.invoke(() -> WANTestBase.createReceiver());
// Site 2
Integer nyPort = (Integer) vm2.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
createCacheInVMs(nyPort, vm3);
Integer nyRecPort = (Integer) vm3.invoke(() -> WANTestBase.createReceiver());
LogWriterUtils.getLogWriter().info("Created locators and receivers in 2 distributed systems");
// Site 1
vm1.invoke(() -> WANTestBase.createSender("ln1", 2, false, 10, 1, false, false, null, true));
vm1.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ln1", isOffHeap()));
vm1.invoke(() -> WANTestBase.startSender("ln1"));
vm1.invoke(() -> WANTestBase.waitForSenderRunningState("ln1"));
// Site 2
vm3.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
vm4.invoke(() -> WANTestBase.createCache(nyPort));
vm4.invoke(() -> WANTestBase.createSender("ny1", 1, false, 10, 1, false, false, null, true));
vm4.invoke(() -> WANTestBase.createReplicatedRegion("repRegion", "ny1", isOffHeap()));
vm4.invoke(() -> WANTestBase.startSender("ny1"));
vm4.invoke(() -> WANTestBase.waitForSenderRunningState("ny1"));
Wait.pause(2000);
// Perform a put in vm1
vm1.invoke(new CacheSerializableRunnable("Putting an entry in ds1") {
@Override
public void run2() throws CacheException {
assertNotNull(cache);
Region region = cache.getRegion("/repRegion");
region.put("testKey", "testValue1");
assertEquals(1, region.size());
}
});
// wait for vm4 to have later timestamp before sending operation to vm1
Wait.pause(300);
AsyncInvocation asynch = vm4.invokeAsync(new CacheSerializableRunnable("Putting an entry in ds2 in vm4") {
@Override
public void run2() throws CacheException {
assertNotNull(cache);
Region region = cache.getRegion("/repRegion");
region.put("testKey", "testValue2");
assertEquals(1, region.size());
assertEquals("testValue2", region.get("testKey"));
}
});
try {
asynch.join(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Wait for all local ds events be received by vm3.
Wait.pause(1000);
vm3.invoke(new CacheSerializableRunnable("Check dsid") {
@Override
public void run2() throws CacheException {
Region region = cache.getRegion("repRegion");
Region.Entry entry = ((LocalRegion) region).getEntry("testKey", /* null, */
true);
// commented while merging revision 43582
RegionEntry re = null;
if (entry instanceof EntrySnapshot) {
re = ((EntrySnapshot) entry).getRegionEntry();
} else if (entry instanceof NonTXEntry) {
re = ((NonTXEntry) entry).getRegionEntry();
}
VersionTag tag = re.getVersionStamp().asVersionTag();
assertEquals(2, tag.getDistributedSystemId());
}
});
// Check vm3 has latest timestamp from vm4.
long putAllTimeStampVm1 = (Long) vm4.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
long putAllTimeStampVm3 = (Long) vm3.invoke(() -> NewWANConcurrencyCheckForDestroyDUnitTest.getVersionTimestampAfterPutAllOp());
assertEquals(putAllTimeStampVm1, putAllTimeStampVm3);
}
Aggregations