/** * 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)); }
/** * 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"); } }