use of org.apache.geode.cache.query.CqAttributes in project geode by apache.
the class CqQueryDUnitTest method validateCQ.
public void validateCQ(VM vm, final String cqName, final int resultSize, final int creates, final int updates, final int deletes, final int queryInserts, final int queryUpdates, final int queryDeletes, final int totalEvents) {
vm.invoke(new CacheSerializableRunnable("Validate CQs") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Validating CQ. ### " + cqName);
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
CqQuery cQuery = cqService.getCq(cqName);
if (cQuery == null) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqAttributes cqAttr = cQuery.getCqAttributes();
CqListener[] cqListeners = cqAttr.getCqListeners();
CqQueryTestListener listener = (CqQueryTestListener) cqListeners[0];
listener.printInfo(false);
// Check for totalEvents count.
if (totalEvents != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Total Event Count mismatch", totalEvents, listener.getTotalEventCount());
}
if (resultSize != noTest) {
// SelectResults results = cQuery.getCqResults();
// getLogWriter().info("### CQ Result Size is :" + results.size());
// Result size validation.
// Since ResultSet is not maintained for this release.
// Instead of resultSize its been validated with total number of events.
fail("test for event counts instead of results size");
// assertIndexDetailsEquals("Result Size mismatch", resultSize,
// listener.getTotalEventCount());
}
// Check for create count.
if (creates != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Create Event mismatch", creates, listener.getCreateEventCount());
}
// Check for update count.
if (updates != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Update Event mismatch", updates, listener.getUpdateEventCount());
}
// Check for delete count.
if (deletes != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Delete Event mismatch", deletes, listener.getDeleteEventCount());
}
// Check for queryInsert count.
if (queryInserts != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Query Insert Event mismatch", queryInserts, listener.getQueryInsertEventCount());
}
// Check for queryUpdate count.
if (queryUpdates != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Query Update Event mismatch", queryUpdates, listener.getQueryUpdateEventCount());
}
// Check for queryDelete count.
if (queryDeletes != noTest) {
// Result size validation.
listener.printInfo(true);
assertEquals("Query Delete Event mismatch", queryDeletes, listener.getQueryDeleteEventCount());
}
}
});
}
use of org.apache.geode.cache.query.CqAttributes in project geode by apache.
the class CqQueryDUnitTest method waitForCqsDisconnected.
protected void waitForCqsDisconnected(VM vm, final String cqName, final int count) {
vm.invoke(new CacheSerializableRunnable("validate cq disconnected count") {
public void run2() throws CacheException {
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
CqQuery cQuery = cqService.getCq(cqName);
if (cQuery == null) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqAttributes cqAttr = cQuery.getCqAttributes();
CqListener[] cqListener = cqAttr.getCqListeners();
CqQueryTestListener listener = (CqQueryTestListener) cqListener[0];
listener.waitForCqsDisconnectedEvents(count);
}
});
}
use of org.apache.geode.cache.query.CqAttributes in project geode by apache.
the class CqQueryDUnitTest method waitForEvent.
private void waitForEvent(VM vm, final int event, final String cqName, final String key) {
vm.invoke(new CacheSerializableRunnable("validate cq count") {
public void run2() throws CacheException {
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
Assert.fail("Failed to getCQService.", cqe);
}
CqQuery cQuery = cqService.getCq(cqName);
if (cQuery == null) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqAttributes cqAttr = cQuery.getCqAttributes();
CqListener[] cqListener = cqAttr.getCqListeners();
CqQueryTestListener listener = (CqQueryTestListener) cqListener[0];
switch(event) {
case CREATE:
listener.waitForCreated(key);
break;
case UPDATE:
listener.waitForUpdated(key);
break;
case DESTROY:
listener.waitForDestroyed(key);
break;
case INVALIDATE:
listener.waitForInvalidated(key);
break;
case CLOSE:
listener.waitForClose();
break;
case REGION_CLEAR:
listener.waitForRegionClear();
break;
case REGION_INVALIDATE:
listener.waitForRegionInvalidate();
break;
}
}
});
}
use of org.apache.geode.cache.query.CqAttributes in project geode by apache.
the class CqQueryDUnitTest method executeAndCloseAndExecuteIRMultipleTimes.
// helps test case where executeIR is called multiple times as well as after close
public void executeAndCloseAndExecuteIRMultipleTimes(VM vm, final String cqName, final String queryStr) {
vm.invoke(new CacheSerializableRunnable("Create CQ :" + cqName) {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
// Create CQ Attributes.
CqAttributesFactory cqf = new CqAttributesFactory();
CqListener[] cqListeners = { new CqQueryTestListener(LogWriterUtils.getLogWriter()) };
cqf.initCqListeners(cqListeners);
CqAttributes cqa = cqf.create();
CqQuery cq1;
// Create CQ.
try {
cq1 = cqService.newCq(cqName, queryStr, cqa);
assertTrue("newCq() state mismatch", cq1.getState().isStopped());
} catch (Exception ex) {
AssertionError err = new AssertionError("Failed to create CQ " + cqName + " . ");
err.initCause(ex);
LogWriterUtils.getLogWriter().info("CqService is :" + cqService, err);
throw err;
}
try {
cq1.executeWithInitialResults();
try {
cq1.executeWithInitialResults();
} catch (IllegalStateException e) {
// expected
}
cq1.close();
try {
cq1.executeWithInitialResults();
} catch (CqClosedException e) {
// expected
return;
}
fail("should have received cqClosedException");
} catch (Exception e) {
fail("exception not expected here " + e);
}
}
});
}
use of org.apache.geode.cache.query.CqAttributes in project geode by apache.
the class CqQueryDUnitTest method clearCQListenerEvents.
public void clearCQListenerEvents(VM vm, final String cqName) {
vm.invoke(new CacheSerializableRunnable("validate cq count") {
public void run2() throws CacheException {
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCQService.");
}
CqQuery cQuery = cqService.getCq(cqName);
if (cQuery == null) {
fail("Failed to get CqQuery for CQ : " + cqName);
}
CqAttributes cqAttr = cQuery.getCqAttributes();
CqListener cqListener = cqAttr.getCqListener();
CqQueryTestListener listener = (CqQueryTestListener) cqListener;
listener.getEventHistory();
}
});
}
Aggregations