use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqResultSetUsingPoolDUnitTest method testCqResultsCachingForPR.
/**
* Tests CQ Result Set.
*
* @throws Exception
*/
@Test
public void testCqResultsCachingForPR() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
cqDUnitTest.createServerWithPR(server1, 0, false, 0);
cqDUnitTest.createServerWithPR(server2, 0, false, 0);
final int port = server1.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
String poolName = "testCqResults";
final String cqName = "testCqResultsP_0";
cqDUnitTest.createPool(client, poolName, host0, port);
// Create client.
cqDUnitTest.createClient(client, port, host0);
// create CQ.
cqDUnitTest.createCQ(client, poolName, cqName, cqDUnitTest.cqs[0]);
final int numObjects = 300;
final int totalObjects = 500;
// initialize Region.
server1.invoke(new CacheSerializableRunnable("Update Region") {
public void run2() throws CacheException {
Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
for (int i = 1; i <= numObjects; i++) {
Portfolio p = new Portfolio(i);
region.put("" + i, p);
}
}
});
cqDUnitTest.executeCQ(client, cqName, true, null);
// Keep updating region (async invocation).
server2.invoke(new CacheSerializableRunnable("Update Region") {
public void run2() throws CacheException {
Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
// Update (totalObjects - 1) entries.
for (int i = 1; i < totalObjects; i++) {
// Destroy entries.
if (i > 25 && i < 201) {
region.destroy("" + i);
continue;
}
Portfolio p = new Portfolio(i);
region.put("" + i, p);
}
// recreate destroyed entries.
for (int j = 26; j < 201; j++) {
Portfolio p = new Portfolio(j);
region.put("" + j, p);
}
// Add the last key.
Portfolio p = new Portfolio(totalObjects);
region.put("" + totalObjects, p);
}
});
// Verify CQ Cache results.
server1.invoke(new CacheSerializableRunnable("Verify CQ Cache results") {
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;
if (cqQuery.getCqResultKeysSize() <= 0) {
fail("The Result Cache for CQ on PR is not working. CQ :" + cqName);
}
}
}
});
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server1);
cqDUnitTest.closeServer(server2);
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqStatsDUnitTest method validateCQStats.
public void validateCQStats(VM vm, final String cqName, final int creates, final int updates, final int deletes, final int totalEvents, final int cqListenerInvocations) {
vm.invoke(new CacheSerializableRunnable("Validate CQs") {
@Override
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Validating CQ Stats. ### " + cqName);
// Get CQ Service.
QueryService qService = null;
try {
qService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to get query service.");
}
CqService cqService = null;
try {
cqService = ((DefaultQueryService) qService).getCqService();
} catch (CqException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("Failed to get CqService, CQ : " + cqName);
}
Collection<? extends InternalCqQuery> cqs = cqService.getAllCqs();
if (cqs.size() == 0) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqQueryImpl cQuery = (CqQueryImpl) cqs.iterator().next();
CqStatistics cqStats = cQuery.getStatistics();
CqQueryVsdStats cqVsdStats = cQuery.getVsdStats();
if (cqStats == null || cqVsdStats == null) {
fail("Failed to get CqQuery Stats for CQ : " + cqName);
}
getCache().getLogger().info("#### CQ stats for " + cQuery.getName() + ": " + " Events Total: " + cqStats.numEvents() + " Events Created: " + cqStats.numInserts() + " Events Updated: " + cqStats.numUpdates() + " Events Deleted: " + cqStats.numDeletes() + " CQ Listener invocations: " + cqVsdStats.getNumCqListenerInvocations() + " Initial results time (nano sec): " + cqVsdStats.getCqInitialResultsTime());
// Check for totalEvents count.
if (totalEvents != CqQueryDUnitTest.noTest) {
// Result size validation.
assertEquals("Total Event Count mismatch", totalEvents, cqStats.numEvents());
}
// Check for create count.
if (creates != CqQueryDUnitTest.noTest) {
assertEquals("Create Event mismatch", creates, cqStats.numInserts());
}
// Check for update count.
if (updates != CqQueryDUnitTest.noTest) {
assertEquals("Update Event mismatch", updates, cqStats.numUpdates());
}
// Check for delete count.
if (deletes != CqQueryDUnitTest.noTest) {
assertEquals("Delete Event mismatch", deletes, cqStats.numDeletes());
}
// Check for CQ listener invocations.
if (cqListenerInvocations != CqQueryDUnitTest.noTest) {
assertEquals("CQ Listener invocations mismatch", cqListenerInvocations, cqVsdStats.getNumCqListenerInvocations());
}
//// Check for initial results time.
// if (initialResultsTime != CqQueryDUnitTest.noTest && cqVsdStats.getCqInitialResultsTime()
//// <= 0) {
// assertIndexDetailsEquals("Initial results time mismatch", initialResultsTime,
//// cqVsdStats.getCqInitialResultsTime());
// }
}
});
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqStatsUsingPoolDUnitTest method validateCQServiceStats.
private void validateCQServiceStats(VM vm, final int created, final int activated, final int stopped, final int closed, final int cqsOnClient, final int cqsOnRegion, final int clientsWithCqs) {
vm.invoke(new CacheSerializableRunnable("Validate CQ Service Stats") {
@Override
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Validating CQ Service Stats. ### ");
// Get CQ Service.
QueryService qService = null;
try {
qService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
CqServiceStatistics cqServiceStats = null;
cqServiceStats = qService.getCqStatistics();
CqServiceVsdStats cqServiceVsdStats = null;
try {
cqServiceVsdStats = ((CqServiceImpl) ((DefaultQueryService) qService).getCqService()).stats();
} catch (CqException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (cqServiceStats == null) {
fail("Failed to get CQ Service Stats");
}
getCache().getLogger().info("#### CQ Service stats: " + " CQs created: " + cqServiceStats.numCqsCreated() + " CQs active: " + cqServiceStats.numCqsActive() + " CQs stopped: " + cqServiceStats.numCqsStopped() + " CQs closed: " + cqServiceStats.numCqsClosed() + " CQs on Client: " + cqServiceStats.numCqsOnClient() + " CQs on region /root/regionA : " + cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA") + " Clients with CQs: " + cqServiceVsdStats.getNumClientsWithCqs());
// Check for created count.
if (created != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs created mismatch", created, cqServiceStats.numCqsCreated());
}
// Check for activated count.
if (activated != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs activated mismatch", activated, cqServiceStats.numCqsActive());
}
// Check for stopped count.
if (stopped != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs stopped mismatch", stopped, cqServiceStats.numCqsStopped());
}
// Check for closed count.
if (closed != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs closed mismatch", closed, cqServiceStats.numCqsClosed());
}
// Check for CQs on client count.
if (cqsOnClient != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs on client mismatch", cqsOnClient, cqServiceStats.numCqsOnClient());
}
// Check for CQs on region.
if (cqsOnRegion != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Number of CQs on region /root/regionA mismatch", cqsOnRegion, cqServiceVsdStats.numCqsOnRegion(GemFireCacheImpl.getInstance(), "/root/regionA"));
}
// Check for clients with CQs count.
if (clientsWithCqs != CqQueryUsingPoolDUnitTest.noTest) {
assertEquals("Clints with CQs mismatch", clientsWithCqs, cqServiceVsdStats.getNumClientsWithCqs());
}
}
});
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryUsingPoolDUnitTest method createClient.
/* Create Client */
public void createClient(VM client, final int[] serverPorts, final String serverHost, final String redundancyLevel, final String poolName) {
SerializableRunnable createQService = new CacheSerializableRunnable("Create Client") {
@Override
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create Client. ###");
// Initialize CQ Service.
try {
getCache().getQueryService();
IgnoredException.addIgnoredException("java.net.ConnectException");
} catch (Exception cqe) {
Assert.fail("Failed to getCQService.", cqe);
}
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
if (poolName != null) {
regionFactory.setPoolName(poolName);
} else {
if (redundancyLevel != null) {
ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, Integer.parseInt(redundancyLevel), -1, null);
} else {
ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, -1, -1, null);
}
}
for (int i = 0; i < regions.length; i++) {
createRegion(regions[i], regionFactory.createRegionAttributes());
LogWriterUtils.getLogWriter().info("### Successfully Created Region on Client :" + regions[i]);
// region1.getAttributesMutator().setCacheListener(new CqListener());
}
}
};
client.invoke(createQService);
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryUsingPoolDUnitTest method testGetCQsForARegionName.
/**
* Test getCQs for a regions
*/
@Test
public void testGetCQsForARegionName() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
createServer(server);
final int thePort = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
String poolName = "testGetCQsForARegionName";
createPool(client, poolName, host0, thePort);
// Create CQs.
createCQ(client, poolName, "testQuery_3", cqs[3]);
executeCQ(client, "testQuery_3", true, null);
createCQ(client, poolName, "testQuery_4", cqs[4]);
executeCQ(client, "testQuery_4", true, null);
createCQ(client, poolName, "testQuery_5", cqs[5]);
executeCQ(client, "testQuery_5", true, null);
createCQ(client, poolName, "testQuery_6", cqs[6]);
executeCQ(client, "testQuery_6", true, null);
// with regions[1]
createCQ(client, poolName, "testQuery_7", cqs[7]);
executeCQ(client, "testQuery_7", true, null);
createCQ(client, poolName, "testQuery_8", cqs[8]);
executeCQ(client, "testQuery_8", true, null);
client.invoke(new CacheSerializableRunnable("Client disableCQs()") {
@Override
public void run2() throws CacheException {
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
CqQuery[] cq = cqService.getCqs("/root/" + regions[0]);
assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[0], cq);
getCache().getLogger().info("cqs for region: /root/" + regions[0] + " : " + cq.length);
// closing on of the cqs.
cq[0].close();
cq = cqService.getCqs("/root/" + regions[0]);
assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[0], cq);
getCache().getLogger().info("cqs for region: /root/" + regions[0] + " after closeing one of the cqs : " + cq.length);
cq = cqService.getCqs("/root/" + regions[1]);
getCache().getLogger().info("cqs for region: /root/" + regions[1] + " : " + cq.length);
assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[1], cq);
} catch (Exception cqe) {
Assert.fail("Failed to getCQService", cqe);
}
}
});
// Close.
closeClient(client);
closeServer(server);
}
Aggregations