use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyWithCacheXML.
/**
* This test method is disabled because it is failing periodically and causing cruise control
* failures See bug #47060 (test seems to be enabled now!)
*/
@Test
public void testReadyForEventsNotCalledImplicitlyWithCacheXML() {
try {
setPeriodicACKObserver(durableClientVM);
final String cqName = "cqTest";
// Start a server
int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXml(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
// Start a durable client that is not kept alive on the server when it
// stops normally
final String durableClientId = getName() + "_client";
// create client cache from xml
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// verify that readyForEvents has not yet been called on all the client's pools
this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@Override
public void run2() throws CacheException {
for (Pool p : PoolManager.getAll().values()) {
assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
registerDurableCq(cqName);
// Verify durable client on server1
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
// Publish some entries
final int numberOfEntries = 10;
publishEntries(numberOfEntries);
// Verify the durable client received the updates
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail("interrupted", e);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
// Verify the durable client still exists on the server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
}
});
// Publish some more entries
publishEntries(numberOfEntries);
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Re-start the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register cq") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Create CQ Attributes.
CqAttributesFactory cqAf = new CqAttributesFactory();
// Initialize and set CqListener.
CqListener[] cqListeners = { new CacheServerTestUtil.ControlCqListener() };
cqAf.initCqListeners(cqListeners);
CqAttributes cqa = cqAf.create();
// Create cq's
// Get the query service for the Pool
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
try {
CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
query.execute();
} catch (CqExistsException e) {
fail("Failed due to ", e);
} catch (CqException e) {
fail("Failed due to ", e);
} catch (RegionNotFoundException e) {
fail("Could not find specified region:" + regionName + ":", e);
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Verify the durable client received the updates held for it on the server
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
} finally {
unsetPeriodicACKObserver(durableClientVM);
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class DurableClientSimpleDUnitTest method testCloseAllCqsAndDrainEvents.
/**
* Test functionality to close the cq and drain all events from the ha queue from the server This
* draining should not affect events that still have register interest
*
* @throws Exception
*/
@Test
public void testCloseAllCqsAndDrainEvents() 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";
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// register durable cqs
registerInterest(durableClientVM, regionName, true);
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");
ccnInstance.closeClientCq(durableClientId, "GreaterThan5");
ccnInstance.closeClientCq(durableClientId, "LessThan5");
} catch (CqException e) {
fail("failed", e);
}
}
});
// Restart the durable client
startDurableClient(durableClientVM, durableClientId, serverPort, regionName);
// Reregister durable cqs
registerInterest(durableClientVM, regionName, true);
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);
checkCqListenerEvents(durableClientVM, "GreaterThan5", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
checkCqListenerEvents(durableClientVM, "LessThan5", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
checkCqListenerEvents(durableClientVM, "All", 0, /* numEventsExpected */
1, /* numEventsToWaitFor */
5);
checkInterestEvents(durableClientVM, regionName, 10);
// 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 ProxyQueryService method getCqs.
public ClientCQ[] getCqs(String regionName) throws CqException {
preOp();
Collection<? extends InternalCqQuery> cqs = null;
try {
ArrayList<CqQuery> cqList = new ArrayList<CqQuery>();
cqs = ((DefaultQueryService) realQueryService).getCqService().getAllCqs(regionName);
for (InternalCqQuery cq : cqs) {
if (this.cqNames.contains(cq.getName())) {
cqList.add((CqQuery) cq);
}
}
ClientCQ[] results = new ClientCQ[cqList.size()];
cqList.toArray(results);
return results;
} catch (CqException cqe) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to get Cqs. Error: {}", cqe.getMessage(), cqe);
}
throw cqe;
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceImpl method addToCqMap.
/**
* Adds the given CQ and cqQuery object into the CQ map.
*/
void addToCqMap(CqQueryImpl cq) throws CqExistsException, CqException {
// On server side cqName will be server side cqName.
String sCqName = cq.getServerCqName();
if (logger.isDebugEnabled()) {
logger.debug("Adding to CQ Repository. CqName : {} ServerCqName : {}", cq.getName(), sCqName);
}
HashMap<String, CqQueryImpl> cqMap = cqQueryMap;
if (cqMap.containsKey(sCqName)) {
throw new CqExistsException(LocalizedStrings.CqService_A_CQ_WITH_THE_GIVEN_NAME_0_ALREADY_EXISTS.toLocalizedString(sCqName));
}
synchronized (cqQueryMapLock) {
HashMap<String, CqQueryImpl> tmpCqQueryMap = new HashMap<>(cqQueryMap);
try {
tmpCqQueryMap.put(sCqName, cq);
} catch (Exception ex) {
StringId errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_STORE_CONTINUOUS_QUERY_IN_THE_REPOSITORY_CQNAME_0_1;
Object[] errMsgArgs = new Object[] { sCqName, ex.getLocalizedMessage() };
String s = errMsg.toLocalizedString(errMsgArgs);
logger.error(s);
throw new CqException(s, ex);
}
UserAttributes attributes = UserAttributes.userAttributes.get();
if (attributes != null) {
this.cqNameToUserAttributesMap.put(cq.getName(), attributes);
}
cqQueryMap = tmpCqQueryMap;
}
}
use of org.apache.geode.cache.query.CqException in project geode by apache.
the class CqServiceVsdStats method numCqsOnRegion.
/**
* This is a test method. It silently ignores exceptions and should not be used outside of unit
* tests.
* <p>
* Returns the number of CQs (active + suspended) on the given region.
*/
public long numCqsOnRegion(final InternalCache cache, String regionName) {
if (cache == null) {
return 0;
}
DefaultQueryService queryService = (DefaultQueryService) cache.getQueryService();
CqService cqService = null;
try {
cqService = queryService.getCqService();
} catch (CqException e) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to get CqService {}", e.getLocalizedMessage());
}
e.printStackTrace();
// We're confused
return -1;
}
if (((CqServiceImpl) cqService).isServer()) {
// If we are on the server, look at the number of CQs in the filter profile.
try {
FilterProfile fp = cache.getFilterProfile(regionName);
if (fp == null) {
return 0;
}
return fp.getCqCount();
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to get serverside CQ count for region: {} {}", regionName, ex.getLocalizedMessage());
}
}
} else {
try {
CqQuery[] cqs = queryService.getCqs(regionName);
if (cqs != null) {
return cqs.length;
}
} catch (Exception ex) {
// Dont do anything.
}
}
return 0;
}
Aggregations