/** * Check event counters in the ControllerBB shared map. For example, if baseKey is * ControllerBB.NumForcedDiscEventsKey and vmList is a list containing vmId 2, and expectedCount * is 1, then the event count of key with base NumForcedDiscEvents plus vmId 2 is expected to be * 1, and any other key found in the map that is prefixed by baseKey should have value be 0. * Throws an exception if the conditions are not satisfied. * * @param baseKey The base string of the key to check (the prefix to the vm id) * @param vmList The vms (ClientVmInfo) for the baseKey should have a value of expectedCount. * @param expectedCount The expected value of any baseKeys that refer to the given vmIds, * otherwise the expectedCount is 0. */ public static void checkEventCounters(String baseKey, List vmList, int expectedCount) { Map aMap = ControllerBB.getBB().getSharedMap().getMap(); Iterator it = aMap.keySet().iterator(); while (it.hasNext()) { String key = (String) (it.next()); if (key.startsWith(baseKey)) { // found a key prefixed by baseKey int value = ((Integer) (aMap.get(key))).intValue(); // value for the key boolean foundInVmIdList = false; for (int i = 0; i < vmList.size(); i++) { int vmId = ((Integer) ((ClientVmInfo) (vmList.get(i))).getVmid()).intValue(); if (key.endsWith("_" + vmId)) { // found a baseKey with a vmid in the vmList foundInVmIdList = true; if (value != expectedCount) { throw new TestException( "Expected value for BB key " + key + " to be " + expectedCount + " but it is " + value); } } } if (!foundInVmIdList) { // this key's value should be 0 if (value != 0) { throw new TestException( "Expected value for BB key " + key + " to be 0 but it is " + value); } } } } }
/** Start all cqs running for this VM, and create a CQHistory instance for each CQ. */ private void startCQsWithHistory() { initializeQueryService(); CqAttributesFactory cqFac = new CqAttributesFactory(); cqFac.addCqListener(new CQHistoryListener()); cqFac.addCqListener(new CQGatherListener()); CqAttributes cqAttr = cqFac.create(); Iterator it = queryMap.keySet().iterator(); while (it.hasNext()) { String queryName = (String) (it.next()); String query = (String) (queryMap.get(queryName)); try { CqQuery cq = qService.newCq(queryName, query, cqAttr); CQHistory history = new CQHistory(cq.getName()); CQHistoryListener.recordHistory(history); Log.getLogWriter() .info( "Creating CQ with name " + queryName + ": " + query + ", cq attributes: " + cqAttr); Log.getLogWriter().info("Calling executeWithInitialResults on " + cq); CqResults rs = cq.executeWithInitialResults(); SelectResults sr = CQUtil.getSelectResults(rs); if (sr == null) { throw new TestException( "For cq " + cq + " with name " + cq.getName() + " executeWithInitialResults returned " + sr); } Log.getLogWriter() .info( "Done calling executeWithInitializResults on " + cq + " with name " + queryName + ", select results size is " + sr.size()); history.setSelectResults(sr); logNumOps(); // log the select results List srList = sr.asList(); StringBuffer aStr = new StringBuffer(); aStr.append("SelectResults returned from " + queryName + " is\n"); for (int i = 0; i < srList.size(); i++) { aStr.append(srList.get(i) + "\n"); } Log.getLogWriter().info(aStr.toString()); } catch (CqExistsException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (RegionNotFoundException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (CqException e) { throw new TestException(TestHelper.getStackTrace(e)); } } }