/** * 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"); } }
/** * 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); }
/** Return a value to add to a region for the given key */ protected QueryObject getValueToAdd(Object key) { return new QueryObject( NameFactory.getCounterForName(key), QueryObject.EQUAL_VALUES, -1, queryDepth); }