use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataUsingPoolDUnitTest method testGetDurableCQsFromServerWithEmptyList.
@Test
public void testGetDurableCQsFromServerWithEmptyList() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client1 = host.getVM(1);
/* Create Server and Client */
cqDUnitTest.createServer(server);
final int port = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
final String poolName1 = "pool1";
cqDUnitTest.createPool(client1, poolName1, host0, port);
client1.invoke(new CacheSerializableRunnable("test getDurableCQsFromServer for client1") {
@Override
public void run2() throws CacheException {
QueryService queryService = null;
try {
queryService = (PoolManager.find(poolName1)).getQueryService();
} catch (Exception cqe) {
Assert.fail("Failed to getCQService.", cqe);
}
List<String> list = null;
try {
list = queryService.getAllDurableCqsFromServer();
} catch (CqException e) {
fail("failed", e);
}
assertEquals(0, list.size());
assertFalse(list.contains("client1DCQ1"));
assertFalse(list.contains("client1DCQ2"));
}
});
cqDUnitTest.closeClient(client1);
cqDUnitTest.closeServer(server);
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataUsingPoolDUnitTest method cycleDurableClient.
private void cycleDurableClient(VM client, final String dcName, final int serverPort, final String regionName, final int durableClientTimeout) {
client.invoke(new CacheSerializableRunnable("cycle client") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.closeCache(true);
}
});
client.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client.getHost()), serverPort), regionName, getDurableClientProperties(dcName, durableClientTimeout)));
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataUsingPoolDUnitTest method testGetDurableCqsFromServer.
@Test
public void testGetDurableCqsFromServer() {
disconnectAllFromDS();
final String regionName = "testGetAllDurableCqsFromServer";
final String cq1Name = "testCq1";
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client1 = host.getVM(1);
VM client2 = host.getVM(2);
// Start server 1
final int server1Port = ((Integer) server.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Start client 1
client1.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client1.getHost()), server1Port), regionName));
// Start client 2
client2.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client2.getHost()), server1Port), regionName));
createClient1CqsAndDurableCqs(client1, regionName);
createClient2CqsAndDurableCqs(client2, regionName);
client2.invoke(new CacheSerializableRunnable("check durable cqs for client 2") {
@Override
public void run2() throws CacheException {
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
List<String> list = null;
try {
list = queryService.getAllDurableCqsFromServer();
} catch (CqException e) {
fail("failed", e);
}
assertEquals(4, list.size());
assertTrue(list.contains("client2DCQ1"));
assertTrue(list.contains("client2DCQ2"));
assertTrue(list.contains("client2DCQ3"));
assertTrue(list.contains("client2DCQ4"));
}
});
client1.invoke(new CacheSerializableRunnable("check durable cqs for client 1") {
@Override
public void run2() throws CacheException {
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
List<String> list = null;
try {
list = queryService.getAllDurableCqsFromServer();
} catch (CqException e) {
fail("failed", e);
}
assertEquals(2, list.size());
assertTrue(list.contains("client1DCQ1"));
assertTrue(list.contains("client1DCQ2"));
}
});
client1.invoke(() -> CacheServerTestUtil.closeCache());
client2.invoke(() -> CacheServerTestUtil.closeCache());
server.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqPerfDUnitTest method validateMatchingCqs.
public void validateMatchingCqs(VM server, final int mapSize, final String query, final int numCqSize) {
server.invoke(new CacheSerializableRunnable("validateMatchingCqs") {
public void run2() throws CacheException {
CqServiceImpl cqService = null;
try {
cqService = (CqServiceImpl) ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Map matchedCqMap = cqService.getMatchingCqMap();
assertEquals("The number of matched cq is not as expected.", mapSize, matchedCqMap.size());
if (query != null) {
if (!matchedCqMap.containsKey(query)) {
fail("Query not found in the matched cq map. Query:" + query);
}
Collection cqs = (Collection) matchedCqMap.get(query);
assertEquals("Number of matched cqs are not equal to the expected matched cqs", numCqSize, cqs.size());
}
}
});
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqPerfDUnitTest method testKeyMaintainance.
/**
* Test for maintaining keys for update optimization.
*
* @throws Exception
*/
@Test
public void testKeyMaintainance() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
cqDUnitTest.createServer(server);
final int port = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
cqDUnitTest.createClient(client, port, host0);
// HashSet for caching purpose will be created for cqs.
final int cqSize = 2;
// Cq1
cqDUnitTest.createCQ(client, "testKeyMaintainance_0", cqDUnitTest.cqs[0]);
cqDUnitTest.executeCQ(client, "testKeyMaintainance_0", false, null);
// Cq2
cqDUnitTest.createCQ(client, "testKeyMaintainance_1", cqDUnitTest.cqs[10]);
cqDUnitTest.executeCQ(client, "testKeyMaintainance_1", false, null);
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 1);
cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 1);
// Entry is made into the CQs cache hashset.
// testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 0
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeys1") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 1, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 0, cqQuery.getCqResultKeysSize());
}
}
}
});
// Update 1.
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 10);
cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 10);
// Entry/check is made into the CQs cache hashset.
// testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate1") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 10, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 5, cqQuery.getCqResultKeysSize());
}
}
}
});
// Update.
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 12);
cqDUnitTest.waitForCreated(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 12);
// Entry/check is made into the CQs cache hashset.
// testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 6, cqQuery.getCqResultKeysSize());
}
}
}
});
// Delete.
cqDUnitTest.deleteValues(server, cqDUnitTest.regions[0], 6);
cqDUnitTest.waitForDestroyed(client, "testKeyMaintainance_0", CqQueryDUnitTest.KEY + 6);
// Entry/check is made into the CQs cache hashset.
// testKeyMaintainance_0 with 1 entry and testKeyMaintainance_1 with 1
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 6, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 3, cqQuery.getCqResultKeysSize());
}
}
}
});
// Stop CQ.
// This should still needs to process the events so that Results are up-to-date.
cqDUnitTest.stopCQ(client, "testKeyMaintainance_1");
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 12);
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_1 is wrong.", 6, cqQuery.getCqResultKeysSize());
}
}
}
});
// re-start the CQ.
cqDUnitTest.executeCQ(client, "testKeyMaintainance_1", false, null);
// This will remove the caching for this CQ.
cqDUnitTest.closeCQ(client, "testKeyMaintainance_1");
server.invoke(new CacheSerializableRunnable("LookForCachedEventKeysAfterUpdate2") {
public void run2() throws CacheException {
CqService cqService = null;
try {
cqService = ((DefaultQueryService) getCache().getQueryService()).getCqService();
} catch (Exception ex) {
LogWriterUtils.getLogWriter().info("Failed to get the internal CqService.", ex);
Assert.fail("Failed to get the internal CqService.", ex);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
for (InternalCqQuery cq : cqs) {
ServerCQImpl cqQuery = (ServerCQImpl) cq;
String serverCqName = (String) cqQuery.getServerCqName();
if (serverCqName.startsWith("testKeyMaintainance_0")) {
assertEquals("The number of keys cached for cq testKeyMaintainance_0 is wrong.", 12, cqQuery.getCqResultKeysSize());
} else if (serverCqName.startsWith("testKeyMaintainance_1")) {
fail("The key maintainance should not be present for this CQ.");
}
}
}
});
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server);
}
Aggregations