use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryDUnitTest method validateServerClientRegionEntries.
// HELPER METHODS....
/* For debug purpose - Compares entries in the region */
private void validateServerClientRegionEntries(VM server, VM client, final String regionName) {
server.invoke(new CacheSerializableRunnable("Server Region Entries") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
LogWriterUtils.getLogWriter().info("### Entries in Server :" + region.keySet().size());
}
});
client.invoke(new CacheSerializableRunnable("Client Region Entries") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
LogWriterUtils.getLogWriter().info("### Entries in Client :" + region.keySet().size());
}
});
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryDUnitTest method stopExecCQ.
// Stop and execute CQ repeatedly
/* Stop/pause CQ */
private void stopExecCQ(VM vm, final String cqName, final int count) throws Exception {
vm.invoke(new CacheSerializableRunnable("Stop CQ :" + cqName) {
public void run2() throws CacheException {
CqQuery cq1 = null;
LogWriterUtils.getLogWriter().info("### Stop and Exec CQ. ###" + cqName);
// Get CQ Service.
QueryService cqService = null;
try {
cqService = getCache().getQueryService();
} catch (Exception cqe) {
cqe.printStackTrace();
fail("Failed to getCqService.");
}
// Get CQ.
try {
cq1 = cqService.getCq(cqName);
} catch (Exception ex) {
ex.printStackTrace();
fail("Failed to get CQ " + cqName + " . " + ex.getMessage());
}
for (int i = 0; i < count; ++i) {
// Stop CQ.
try {
cq1.stop();
} catch (Exception ex) {
ex.printStackTrace();
fail("Count = " + i + "Failed to stop CQ " + cqName + " . " + ex.getMessage());
}
assertTrue("Stop CQ state mismatch, count = " + i, cq1.getState().isStopped());
LogWriterUtils.getLogWriter().info("After stop in Stop and Execute loop, ran successfully, loop count: " + i);
LogWriterUtils.getLogWriter().info("CQ state: " + cq1.getState());
// Re-execute CQ
try {
cq1.execute();
} catch (Exception ex) {
ex.printStackTrace();
fail("Count = " + i + "Failed to execute CQ " + cqName + " . " + ex.getMessage());
}
assertTrue("Execute CQ state mismatch, count = " + i, cq1.getState().isRunning());
LogWriterUtils.getLogWriter().info("After execute in Stop and Execute loop, ran successfully, loop count: " + i);
LogWriterUtils.getLogWriter().info("CQ state: " + cq1.getState());
}
}
});
}
use of org.apache.geode.cache.CacheException 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();
}
});
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryDUnitTest method waitForCqState.
/**
* Waits till the CQ state is same as the expected. Waits for max time, if the CQ state is not
* same as expected throws exception.
*/
public void waitForCqState(VM vm, final String cqName, final int state) {
vm.invoke(new CacheSerializableRunnable("Wait For cq State") {
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);
}
// Get CQ State.
final CqStateImpl cqState = (CqStateImpl) cQuery.getState();
// Wait max time, till the CQ state is as expected.
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return cqState.getState() == state;
}
public String description() {
return "cqState never became " + state;
}
};
Wait.waitForCriterion(ev, MAX_TIME, 200, true);
}
});
}
use of org.apache.geode.cache.CacheException in project geode by apache.
the class CqQueryDUnitTest method testForSupportedRegionAttributes.
/**
* Tests execution of queries with NULL in where clause like where ID = NULL etc.
*
* @throws Exception
*/
@Test
public void testForSupportedRegionAttributes() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
// Create server with Global scope.
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
// Create region with Global scope
AttributesFactory factory1 = new AttributesFactory();
factory1.setScope(Scope.GLOBAL);
factory1.setMirrorType(MirrorType.KEYS_VALUES);
createRegion(regions[0], factory1.createRegionAttributes());
// Create region with non Global, distributed_ack scope
AttributesFactory factory2 = new AttributesFactory();
factory2.setScope(Scope.DISTRIBUTED_NO_ACK);
factory2.setMirrorType(MirrorType.KEYS_VALUES);
createRegion(regions[1], factory2.createRegionAttributes());
Wait.pause(2000);
try {
startBridgeServer(port, true);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
Wait.pause(2000);
}
};
server1.invoke(createServer);
server2.invoke(createServer);
final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
// Create client.
createClient(client, new int[] { port1, thePort2 }, host0, "-1");
// Create CQ on region with GLOBAL SCOPE.
createCQ(client, "testForSupportedRegionAttributes_0", cqs[0]);
executeCQ(client, "testForSupportedRegionAttributes_0", false, null);
int size = 5;
createValues(server1, regions[0], size);
for (int i = 1; i <= size; i++) {
waitForCreated(client, "testForSupportedRegionAttributes_0", KEY + i);
}
// Create CQ on region with non GLOBAL, DISTRIBUTED_ACK SCOPE.
createCQ(client, "testForSupportedRegionAttributes_1", cqs[2]);
String errMsg = "The replicated region " + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
final String expectedErr = "Cq not registered on primary";
client.invoke(new CacheSerializableRunnable("Set expect") {
public void run2() {
getCache().getLogger().info("<ExpectedException action=add>" + expectedErr + "</ExpectedException>");
}
});
try {
executeCQ(client, "testForSupportedRegionAttributes_1", false, "CqException");
fail("The test should have failed with exception, " + errMsg);
} catch (Exception ex) {
// Expected.
} finally {
client.invoke(new CacheSerializableRunnable("Remove expect") {
public void run2() {
getCache().getLogger().info("<ExpectedException action=remove>" + expectedErr + "</ExpectedException>");
}
});
}
// Close.
closeClient(client);
closeServer(server1);
closeServer(server2);
}
Aggregations