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