use of org.apache.geode.cache.query.QueryExecutionTimeoutException in project geode by apache.
the class QueryMonitorDUnitTest method testCacheOpAfterQueryCancel.
/**
* Tests cache operation right after query cancellation.
*/
@Test
public void testCacheOpAfterQueryCancel() throws Exception {
setup(4);
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM server3 = host.getVM(2);
VM server4 = host.getVM(3);
final int numberOfEntries = 1000;
// Start server
server1.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
server1.invoke("Create Partition Regions", () -> createPRRegion());
server2.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
server2.invoke("Create Partition Regions", () -> createPRRegion());
server3.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
server3.invoke("Create Partition Regions", () -> createPRRegion());
server4.invoke("Create BridgeServer", () -> configServer(5, "testQueryExecutionLocally"));
server4.invoke("Create Partition Regions", () -> createPRRegion());
server1.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
try {
QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
queryService.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/root/exampleRegion");
queryService.createIndex("secIdIndex", IndexType.FUNCTIONAL, "pos.secId", "/root/exampleRegion p, p.positions.values pos");
} catch (Exception ex) {
fail("Failed to create index.");
}
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
for (int i = 100; i <= (numberOfEntries); i++) {
exampleRegion.put("" + i, new Portfolio(i));
}
}
});
// Initialize server regions.
AsyncInvocation ai1 = server1.invokeAsync(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
for (int j = 0; j < 5; j++) {
for (int i = 1; i <= (numberOfEntries + 1000); i++) {
exampleRegion.put("" + i, new Portfolio(i));
}
}
LogWriterUtils.getLogWriter().info("### Completed updates in server1 in testCacheOpAfterQueryCancel");
}
});
AsyncInvocation ai2 = server2.invokeAsync(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
for (int j = 0; j < 5; j++) {
for (int i = (1 + 1000); i <= (numberOfEntries + 2000); i++) {
exampleRegion.put("" + i, new Portfolio(i));
}
}
LogWriterUtils.getLogWriter().info("### Completed updates in server2 in testCacheOpAfterQueryCancel");
}
});
// Execute server queries
SerializableRunnable executeQuery = new CacheSerializableRunnable("Execute queries") {
public void run2() throws CacheException {
try {
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
String qStr = "SELECT DISTINCT * FROM /root/exampleRegion p, p.positions.values pos1, p.positions.values pos" + " where p.ID < pos.sharesOutstanding OR p.ID > 0 OR p.position1.mktValue > 0 " + " OR pos.secId in SET ('SUN', 'IBM', 'YHOO', 'GOOG', 'MSFT', " + " 'AOL', 'APPL', 'ORCL', 'SAP', 'DELL', 'RHAT', 'NOVL', 'HP')" + " order by p.status, p.ID desc";
for (int i = 0; i < 500; i++) {
try {
GemFireCacheImpl.getInstance().getLogger().info("Executing query :" + qStr);
Query query = queryService.newQuery(qStr);
query.execute();
} catch (QueryExecutionTimeoutException qet) {
LogWriterUtils.getLogWriter().info("### Got Expected QueryExecutionTimeout exception. " + qet.getMessage());
if (qet.getMessage().contains("cancelled after exceeding max execution")) {
LogWriterUtils.getLogWriter().info("### Doing a put operation");
exampleRegion.put("" + i, new Portfolio(i));
}
} catch (Exception e) {
fail("Exception executing query." + e.getMessage());
}
}
LogWriterUtils.getLogWriter().info("### Completed Executing queries in testCacheOpAfterQueryCancel");
} catch (Exception ex) {
Assert.fail("Exception creating the query service", ex);
}
}
};
AsyncInvocation ai3 = server3.invokeAsync(executeQuery);
AsyncInvocation ai4 = server4.invokeAsync(executeQuery);
LogWriterUtils.getLogWriter().info("### Waiting for async threads to join in testCacheOpAfterQueryCancel");
try {
ThreadUtils.join(ai1, 5 * 60 * 1000);
ThreadUtils.join(ai2, 5 * 60 * 1000);
ThreadUtils.join(ai3, 5 * 60 * 1000);
ThreadUtils.join(ai4, 5 * 60 * 1000);
} catch (Exception ex) {
fail("Async thread join failure");
}
LogWriterUtils.getLogWriter().info("### DONE Waiting for async threads to join in testCacheOpAfterQueryCancel");
validateQueryMonitorThreadCnt(server1, 0, 1000);
validateQueryMonitorThreadCnt(server2, 0, 1000);
validateQueryMonitorThreadCnt(server3, 0, 1000);
validateQueryMonitorThreadCnt(server4, 0, 1000);
LogWriterUtils.getLogWriter().info("### DONE validating query monitor threads testCacheOpAfterQueryCancel");
stopServer(server1);
stopServer(server2);
stopServer(server3);
stopServer(server4);
}
Aggregations