use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCqCloseExceptionDueToActivatingClient.
/**
* Tests scenario where close cq will throw an exception due to a client being reactivated
*/
// GEODE-1060: random ports, async actions, time sensitive, eats
@Category(FlakyTest.class)
// exceptions (fixed 1)
@Test
public void testCqCloseExceptionDueToActivatingClient() throws Exception {
try {
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start server 1
Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
final int serverPort = ports[0].intValue();
final String durableClientId = getName() + "_client";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
// Verify durable client on server
verifyDurableClientOnServer(server1VM, durableClientId);
// Stop the durable client
this.disconnectDurableClient(true);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
AsyncInvocation async = this.server1VM.invokeAsync(new CacheSerializableRunnable("Close cq for durable client") {
@Override
public void run2() throws CacheException {
// Set the Test Hook!
// This test hook will pause during the drain process
CacheClientProxy.testHook = new CqExceptionDueToActivatingClientTestHook();
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
fail("Should have thrown an exception due to activating client");
} catch (CqException e) {
String expected = LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_RESTARTING_DURABLE_CLIENT.toLocalizedString("All", proxyId.getDurableId());
if (!e.getMessage().equals(expected)) {
Assert.fail("Not the expected exception, was expecting " + (LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_RESTARTING_DURABLE_CLIENT.toLocalizedString("All", proxyId.getDurableId()) + " instead of exception: " + e.getMessage()), e);
}
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// Reregister durable cqs
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
async.join();
assertEquals(async.getException() != null ? async.getException().toString() : "No error", false, async.exceptionOccurred());
// verify cq listener events
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 10, /* numEventsExpected */
10, /* numEventsToWaitFor */
15);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
} finally {
this.server1VM.invoke(new CacheSerializableRunnable("unset test hook") {
@Override
public void run2() throws CacheException {
CacheClientProxy.testHook = null;
}
});
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCloseCqAndDrainEvents2Client.
/**
* Test functionality to close the cq and drain all events from the ha queue from the server Two
* durable clients, one will have a cq be closed, the other should be unaffected
*/
@Test
public void testCloseCqAndDrainEvents2Client() throws Exception {
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start server 1
Integer[] ports = ((Integer[]) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerReturnPorts(regionName, new Boolean(true))));
final int serverPort = ports[0].intValue();
final String durableClientId = getName() + "_client";
final String durableClientId2 = getName() + "_client2";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
// Verify durable client on server
verifyDurableClientOnServer(server1VM, durableClientId);
// Stop the durable client
this.disconnectDurableClient(true);
startDurableClient(durableClientVM, durableClientId2, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
// Verify 2nd durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify 2nd durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(2);
}
});
this.disconnectDurableClient(true);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
this.server1VM.invoke(new CacheSerializableRunnable("Close cq for durable client 1") {
@Override
public void run2() throws CacheException {
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
} catch (CqException e) {
fail("failed", e);
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// Reregister durable cqs
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
// verify cq events for all 3 cqs, where ALL should have 0 entries
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
this.disconnectDurableClient(false);
// Restart the 2nd durable client
startDurableClient(durableClientVM, durableClientId2, serverPort, regionName);
// Reregister durable cqs
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
// verify cq events for all 3 cqs, where ALL should have 10 entries
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 10, /* numEventsExpected */
10, /* numEventsToWaitFor */
15);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCloseCqAndDrainEvents.
/**
* Test functionality to close the cq and drain all events from the ha queue from the server
*/
@Test
public void testCloseCqAndDrainEvents() throws Exception {
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start a server
int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Start a durable client that is kept alive on the server when it stops
// normally
final String durableClientId = getName() + "_client";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
// send client ready
sendClientReady(durableClientVM);
// Verify durable client on server
verifyDurableClientOnServer(server1VM, durableClientId);
// Stop the durable client
this.disconnectDurableClient(true);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
this.server1VM.invoke(new CacheSerializableRunnable("Close cq for durable client") {
@Override
public void run2() throws CacheException {
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
} catch (CqException e) {
fail("failed", e);
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// Reregister durable cqs
createCq(durableClientVM, "GreaterThan5", "select * from /" + regionName + " p where p.ID > 5", true);
createCq(durableClientVM, "All", "select * from /" + regionName + " p where p.ID > -1", true);
createCq(durableClientVM, "LessThan5", "select * from /" + regionName + " p where p.ID < 5", true);
// send client ready
sendClientReady(durableClientVM);
// verify cq events for all 3 cqs
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCqCloseExceptionDueToActiveConnection.
/**
* Tests situation where a client is trying to reconnect while a cq is being drained
*/
@Test
public void testCqCloseExceptionDueToActiveConnection() throws Exception {
String greaterThan5Query = "select * from /" + regionName + " p where p.ID > 5";
String allQuery = "select * from /" + regionName + " p where p.ID > -1";
String lessThan5Query = "select * from /" + regionName + " p where p.ID < 5";
// Start a server
int serverPort = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Start a durable client that is kept alive on the server when it stops
// normally
final String durableClientId = getName() + "_client";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
sendClientReady(durableClientVM);
// register durable cqs
createCq(durableClientVM, "GreaterThan5", greaterThan5Query, true);
createCq(durableClientVM, "All", allQuery, true);
createCq(durableClientVM, "LessThan5", lessThan5Query, true);
verifyDurableClientOnServer(server1VM, durableClientId);
// Start normal publisher client
startClient(publisherClientVM, serverPort, regionName);
// Publish some entries
publishEntries(publisherClientVM, regionName, 10);
// Attempt to close a cq even though the client is running
this.server1VM.invoke(new CacheSerializableRunnable("Close cq for durable client") {
@Override
public void run2() throws CacheException {
final CacheClientNotifier ccnInstance = CacheClientNotifier.getInstance();
final CacheClientProxy clientProxy = ccnInstance.getClientProxy(durableClientId);
ClientProxyMembershipID proxyId = clientProxy.getProxyID();
try {
ccnInstance.closeClientCq(durableClientId, "All");
fail("expected a cq exception. We have an active client proxy, the close cq command should have failed");
} catch (CqException e) {
// expected exception;
String expected = LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_ACTIVE_DURABLE_CLIENT.toLocalizedString("All", proxyId.getDurableId());
if (!e.getMessage().equals(expected)) {
fail("Not the expected exception, was expecting " + (LocalizedStrings.CacheClientProxy_COULD_NOT_DRAIN_CQ_DUE_TO_ACTIVE_DURABLE_CLIENT.toLocalizedString("All", proxyId.getDurableId()) + " instead of exception: " + e.getMessage()), e);
}
}
}
});
// verify cq events for all 3 cqs
checkCqListenerEvents(durableClientVM, "GreaterThan5", 4, /* numEventsExpected */
4, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "LessThan5", 5, /* numEventsExpected */
5, /* numEventsToWaitFor */
15);
checkCqListenerEvents(durableClientVM, "All", 10, /* numEventsExpected */
10, /* numEventsToWaitFor */
15);
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqStatsDUnitTest 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 != CqQueryDUnitTest.noTest) {
assertEquals("Number of CQs created mismatch", created, cqServiceStats.numCqsCreated());
}
// Check for activated count.
if (activated != CqQueryDUnitTest.noTest) {
assertEquals("Number of CQs activated mismatch", activated, cqServiceStats.numCqsActive());
}
// Check for stopped count.
if (stopped != CqQueryDUnitTest.noTest) {
assertEquals("Number of CQs stopped mismatch", stopped, cqServiceStats.numCqsStopped());
}
// Check for closed count.
if (closed != CqQueryDUnitTest.noTest) {
assertEquals("Number of CQs closed mismatch", closed, cqServiceStats.numCqsClosed());
}
// Check for CQs on client count.
if (cqsOnClient != CqQueryDUnitTest.noTest) {
assertEquals("Number of CQs on client mismatch", cqsOnClient, cqServiceStats.numCqsOnClient());
}
// Check for CQs on region.
if (cqsOnRegion != CqQueryDUnitTest.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 != CqQueryDUnitTest.noTest) {
assertEquals("Clints with CQs mismatch", clientsWithCqs, cqServiceVsdStats.getNumClientsWithCqs());
}
}
});
}
Aggregations