/** * Update an existing key in region REGION_NAME. The keys to update are specified in keyIntervals. * * @return true if all keys to be updated have been completed. */ protected boolean updateExistingKey() { long nextKey = CQUtilBB.getBB().getSharedCounters().incrementAndRead(CQUtilBB.LASTKEY_UPDATE_EXISTING_KEY); if (!keyIntervals.keyInRange(KeyIntervals.UPDATE_EXISTING_KEY, nextKey)) { Log.getLogWriter().info("All existing keys updated; returning from updateExistingKey"); return true; } Object key = NameFactory.getObjectNameForCounter(nextKey); QueryObject existingValue = (QueryObject) aRegion.get(key); if (existingValue == null) throw new TestException("Get of key " + key + " returned unexpected " + existingValue); QueryObject newValue = existingValue.modifyWithNewInstance(QueryObject.NEGATE, 0, true); newValue.extra = key; // encode the key in the object for later validation if (existingValue.aPrimitiveLong < 0) throw new TestException( "Trying to update a key which was already updated: " + existingValue.toStringFull()); Log.getLogWriter() .info("Updating existing key " + key + " with value " + TestHelper.toString(newValue)); aRegion.put(key, newValue); Log.getLogWriter() .info( "Done updating existing key " + key + " with value " + TestHelper.toString(newValue) + ", num remaining: " + (keyIntervals.getLastKey(KeyIntervals.UPDATE_EXISTING_KEY) - nextKey)); return (nextKey >= keyIntervals.getLastKey(KeyIntervals.UPDATE_EXISTING_KEY)); }
/** Initializes a search. Information is taken from the query field */ public void sendQuery() { control.clearResults(); String message = queryField.getText().trim(); QueryObject object = new QueryObject(-181, 10, (short) 0, message); object.setSocketId(-1); // control.deliver(object); }
public ListRequest addOrderBy(FilterNode node, boolean isAsc) { if (queryObject.getOrderByTermList() == null) queryObject.setOrderByTermList(new ArrayList<OrderNode>()); queryObject .getOrderByTermList() .add(new OrderNode(node, isAsc ? OrderTerm.ASC : OrderTerm.DESC)); return this; }
/** * Check that the value of the given key is expected as an updated value. Throw an error if any * problems. * * @param key The key to check. * @param value The value for the key. * @param logStr Used if throwing an error due to an unexpected value. */ protected void checkUpdatedValue(Object key, Object value) { if (value instanceof QueryObject) { QueryObject qo = (QueryObject) value; long keyCounter = NameFactory.getCounterForName(key); if (qo.aPrimitiveLong > 0) { // this value has not been updated; updates are negative throw new TestException( "Expected QueryObject for key " + key + " to contain negative values (indicating it was updated), but the value for this key is " + qo.toStringFull()); } } else { throw new TestException( "Expected value " + TestHelper.toString(value) + " to be a QueryObject"); } }
/** * Check that the value of the given key is expected for this test. Throw an error if any * problems. * * @param key The key to check. * @param value The value for the key. * @param logStr Used if throwing an error due to an unexpected value. */ protected void checkValue(Object key, Object value) { if (value instanceof QueryObject) { QueryObject qo = (QueryObject) value; long keyCounter = NameFactory.getCounterForName(key); if (keyCounter != qo.aPrimitiveLong) { // just pick one field from the QueryObject to test; use aPrimitiveLong throw new TestException( "Inconsistent QueryObject for key " + key + ":" + qo.toStringFull()); } } else { throw new TestException( "For key " + key + ", expected value " + TestHelper.toString(value) + " to be a QueryObject"); } }
public ListRequest select(SelectTerm... terms) { if (terms == null || terms.length == 0) { queryObject.setSelectClause(null); return this; } List<SelectTerm> lst = new ArrayList<SelectTerm>(); for (int i = 0; i < terms.length; i++) lst.add(terms[i]); return select(lst); }
/** * Load a region with keys and values. The number of keys and values is specified by the total * number of keys in keyIntervals. This can be invoked by several threads to accomplish the work. */ public void loadRegion() { final long LOG_INTERVAL_MILLIS = 10000; int numKeysToCreate = keyIntervals.getNumKeys(); long lastLogTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis(); SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); do { long shouldAddCount = CQUtilBB.getBB().getSharedCounters().incrementAndRead(CQUtilBB.SHOULD_ADD_COUNT); if (shouldAddCount > numKeysToCreate) { String aStr = "In loadRegion, shouldAddCount is " + shouldAddCount + ", numOriginalKeysCreated is " + sc.read(CQUtilBB.NUM_ORIGINAL_KEYS_CREATED) + ", numKeysToCreate is " + numKeysToCreate + ", region size is " + aRegion.size(); Log.getLogWriter().info(aStr); NameBB.getBB().printSharedCounters(); throw new StopSchedulingTaskOnClientOrder(aStr); } Object key = NameFactory.getNextPositiveObjectName(); QueryObject value = getValueToAdd(key); value.extra = key; Log.getLogWriter().info("Creating with put, key " + key + ", value " + value.toStringFull()); aRegion.put(key, value); sc.increment(CQUtilBB.NUM_ORIGINAL_KEYS_CREATED); if (System.currentTimeMillis() - lastLogTime > LOG_INTERVAL_MILLIS) { Log.getLogWriter() .info( "Added " + NameFactory.getPositiveNameCounter() + " out of " + numKeysToCreate + " entries into " + TestHelper.regionToString(aRegion, false)); lastLogTime = System.currentTimeMillis(); } } while ((minTaskGranularitySec == -1) || (System.currentTimeMillis() - startTime < minTaskGranularityMS)); }
public ListRequest groupBy(String... groupByTerms) { if (groupByTerms == null || groupByTerms.length == 0) { queryObject.setGroupByTermList(null); return this; } List<String> lst = new ArrayList<String>(); for (int i = 0; i < groupByTerms.length; i++) lst.add(groupByTerms[i]); return groupBy(lst); }
/** Same as traverseStatement but throws only CMIS Exceptions */ public void processStatementUsingCmisExceptions() { try { processStatement(); } catch (RecognitionException e) { String errorMsg = queryObj.getErrorMessage(); throw new CmisInvalidArgumentException( "Walking of statement failed with RecognitionException error: \n " + errorMsg, e); } catch (CmisBaseException e) { throw e; } catch (Exception e) { throw new CmisInvalidArgumentException( "Walking of statement failed with exception: \n ", e); } }
/** * Add a new key to REGION_NAME. * * @return true if all new keys have been added (specified by CQUtilPrms.numNewKeys) */ protected boolean addNewKey() { SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); long numNewKeysCreated = sc.incrementAndRead(CQUtilBB.NUM_NEW_KEYS_CREATED); if (numNewKeysCreated > numNewKeys) { Log.getLogWriter().info("All new keys created; returning from addNewKey"); return true; } Object key = NameFactory.getNextPositiveObjectName(); checkContainsValueForKey(key, false, "before addNewKey"); QueryObject value = new QueryObject( NameFactory.getCounterForName(key), QueryObject.EQUAL_VALUES, -1, queryDepth); value.extra = key; // encode the key in the value for later validation Log.getLogWriter().info("Adding new key " + key + " with put"); aRegion.put(key, value); Log.getLogWriter() .info( "Done adding new key " + key + " with put, " + "num remaining: " + (numNewKeys - numNewKeysCreated)); return (numNewKeysCreated >= numNewKeys); }
/** * parses the QueryObject. This is the main interface method for parsing. * * @exception QMException if there is any exception * @return SQLDescriptor[] Each SQLDescriptor has a different SQL statement */ public SQLDescWithBindParameters[] parse() throws QMException { String[] sFields = mqo.getSelectFields(); // convert fully qualified field names to QualifiedField object. QualifiedField[] selectFields = qualify(sFields); Condition[] conditions = mqo.getConditionsUnion(); mroot = getRoot(selectFields, conditions); /* find all the different objects/objects specified in both selectFields and conditions. Note it is possible to have conditions on objects that are not retrieved in select fields. */ HashSet objects = findObjects(selectFields, conditions); /* Now create all the possible QPath from root to each different leaf. So as explained before, for a tree of form System Person Address Phone Alias, these QPaths would be { System, Person, Address }, { System, Person, Phone }, { System, Person, Alias } this is executed by base class QueryParser */ QPath[] condQpaths = createQPath(mroot, objects); checkForInvalidObjects(objects, condQpaths); ConditionMap[] conditionMaps = createConditionMap(objects, condQpaths, conditions); /* Now we create another set of QPath based on objects specified in the select fields. Based on our top example, these paths would be same as ConditionPath. */ HashSet selectObjects = findObjects(selectFields); QPath[] selectQpaths = createQPath(mroot, selectObjects); for (int i = 0; i < selectQpaths.length; i++) { selectQpaths[i].setConditions(conditions); } /* Now create sub paths for each of selectPath. The sub paths contains objects whose leaf contains a condition and have not been already included in the QPath. So QPath1: {System Person Address} would contain subqpath {Phone Person} QPath2 { System Person Phone} would contain subqpath {Address Person} QPath3 { System Person Phone} would contain subqpaths {Address Person}, {Phone Person} */ createsubQPath(selectQpaths, condQpaths, conditionMaps); SQLDescWithBindParameters[] sql = createSQL( selectQpaths, conditionMaps, selectFields, selectObjects, mqo.getMaxRows(), mqo.getHints()); return sql; }
private ListRequest select(List<SelectTerm> lst) { queryObject.setSelectClause(lst); return this; }
public ListRequest includeObject(String joinPath) { queryObject.include(joinPath); return this; }
public ListRequest and(FilterNode filter) { queryObject.and(filter); return this; }
/** * Verify the result of the CQs registered for this VM. Query results from * executeWithInitialResults are combined with subsequent cq events to form the final result. */ protected void verifyQueryResultsCombine() { Log.getLogWriter().info("In verifyQueryResultsCombine"); Iterator it = queryMap.keySet().iterator(); int count = 0; while (it.hasNext()) { count++; String cqName = (String) (it.next()); Log.getLogWriter() .info("Verifying query " + count + " out of " + queryMap.size() + " with name " + cqName); CqQuery cq = qService.getCq(cqName); String queryStr = cq.getQueryString(); String readableQueryStr = CQTest.getReadableQueryString(queryStr); // combine the initial selectResults with history of events CQHistory history = CQHistoryListener.getCQHistory(cqName); Map combinedMap = history.getCombinedResults(); List combinedList = new ArrayList(combinedMap.values()); List expectedResults = CQTestInstance.getExpectedResults(queryStr); List missingInCombined = new ArrayList(expectedResults); List unexpectedInCombined = new ArrayList(combinedList); unexpectedInCombined.removeAll(expectedResults); missingInCombined.removeAll(combinedList); // prepare error Strings StringBuffer aStr = new StringBuffer(); if (unexpectedInCombined.size() > 0) { String tmpStr = getLocationString(unexpectedInCombined, expectedResults, history) + "\n" + "Found the following " + unexpectedInCombined.size() + " unexpected elements in combined results for cq " + cqName + ", " + readableQueryStr + ": " + QueryObject.toStringFull(unexpectedInCombined); Log.getLogWriter().info(tmpStr); aStr.append(tmpStr); } if (missingInCombined.size() > 0) { String tmpStr = getLocationString(missingInCombined, expectedResults, history) + "\n" + "The following " + missingInCombined.size() + " elements were missing from combined results for cq " + cqName + ", " + readableQueryStr + ": " + QueryObject.toStringFull(missingInCombined); Log.getLogWriter().info(tmpStr); aStr.append(tmpStr); } if (aStr.length() > 0) { throw new TestException( "Probably bug 38065: For cq " + cqName + ", " + readableQueryStr + "\n" + aStr.toString()); } } Log.getLogWriter().info("Done verifying " + count + " queries"); }
public ListRequest groupBy(List<String> groupByTerms) { queryObject.setGroupByTermList(groupByTerms); return this; }
/** * Given a List of QueryObjects known to be inconsistent as determined by validation, log where * the suspect objects are found by checking for it in 1) the expected List 2) the CQ history of * events 3) the select results 4) the localRegion * * @param inconsistencies A List of suspect QueryObjects to check in each location. * @param expected The expected List of objects for a query. * @param history The CQHistory for the query * @returns */ private String getLocationString(List inconsistencies, List expected, CQHistory history) { StringBuffer aStr = new StringBuffer(); for (int i = 0; i < inconsistencies.size(); i++) { QueryObject suspect = (QueryObject) (inconsistencies.get(i)); // check the local region boolean found = false; Iterator it = aRegion.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); Region.Entry entry = aRegion.getEntry(key); QueryObject qo = (QueryObject) (entry.getValue()); if ((qo != null) && (qo.equals(suspect))) { found = true; aStr.append( qo.toStringAbbreviated() + " was found in " + aRegion.getFullPath() + " at key " + key + "\n"); } } if (!found) { aStr.append( suspect.toStringAbbreviated() + " was NOT found in " + aRegion.getFullPath() + "\n"); } // seach for all occurrences in expected list found = false; it = expected.iterator(); while (it.hasNext()) { QueryObject qo = (QueryObject) (it.next()); if (qo.equals(suspect)) { found = true; aStr.append(qo.toStringAbbreviated() + " was found in expected results\n"); } } if (!found) { aStr.append(suspect.toStringAbbreviated() + " was NOT found in expected results\n"); } // seach for all occurrences in selectResults SelectResults selResults = history.getSelectResults(); found = false; it = selResults.iterator(); while (it.hasNext()) { QueryObject qo = (QueryObject) (it.next()); if (qo.equals(suspect)) { found = true; aStr.append(qo.toStringAbbreviated() + " was found in SelectResults\n"); } } if (!found) { aStr.append(suspect.toStringAbbreviated() + " was NOT found in SelectResults\n"); } // seach for all occurrences in history found = false; List eventList = history.getEvents(); for (int j = 0; j < eventList.size(); j++) { CqEvent event = (CqEvent) (eventList.get(j)); QueryObject qo = (QueryObject) (event.getNewValue()); if ((qo != null) && (qo.equals(suspect))) { found = true; aStr.append( qo.toStringAbbreviated() + " was found in event history as new value " + event + "\n"); } } if (!found) { aStr.append(suspect.toStringAbbreviated() + " was NOT found in CqEvent history\n"); } } return aStr.toString(); }