/** * Do a get on a key in region REGION_NAME. Keys to get are specified in keyIntervals. * * @return true if all keys to have get performaed have been completed. */ protected boolean get() { SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); long nextKey = sc.incrementAndRead(CQUtilBB.LASTKEY_GET); if (!keyIntervals.keyInRange(KeyIntervals.GET, nextKey)) { Log.getLogWriter().info("All gets completed; returning from get"); return true; } Object key = NameFactory.getObjectNameForCounter(nextKey); Log.getLogWriter().info("Getting " + key); try { Object existingValue = aRegion.get(key); Log.getLogWriter() .info( "Done getting " + key + ", num remaining: " + (keyIntervals.getLastKey(KeyIntervals.GET) - nextKey)); if (existingValue == null) throw new TestException("Get of key " + key + " returned unexpected " + existingValue); } catch (TimeoutException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (CacheLoaderException e) { throw new TestException(TestHelper.getStackTrace(e)); } return (nextKey >= keyIntervals.getLastKey(KeyIntervals.GET)); }
/** * Invalidate a key in region REGION_NAME. The keys to invalidate are specified in keyIntervals. * * @return true if all keys to be invalidated have been completed. */ protected boolean invalidate() { SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); long nextKey = sc.incrementAndRead(CQUtilBB.LASTKEY_INVALIDATE); if (!keyIntervals.keyInRange(KeyIntervals.INVALIDATE, nextKey)) { Log.getLogWriter().info("All existing keys invalidated; returning from invalidate"); return true; } Object key = NameFactory.getObjectNameForCounter(nextKey); Log.getLogWriter().info("Invalidating " + key); checkContainsValueForKey(key, true, "before invalidate"); try { aRegion.invalidate(key); Log.getLogWriter() .info( "Done invalidating " + key + ", num remaining: " + (keyIntervals.getLastKey(KeyIntervals.INVALIDATE) - nextKey)); } catch (TimeoutException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (EntryNotFoundException e) { throw new TestException(TestHelper.getStackTrace(e)); } return (nextKey >= keyIntervals.getLastKey(KeyIntervals.INVALIDATE)); }
/** * Destroy a key in region REGION_NAME. The keys to destroy are specified in keyIntervals. * * @return true if all keys to be destroyed have been completed. */ protected boolean destroy() { SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); long nextKey = sc.incrementAndRead(CQUtilBB.LASTKEY_DESTROY); if (!keyIntervals.keyInRange(KeyIntervals.DESTROY, nextKey)) { Log.getLogWriter().info("All destroys completed; returning from destroy"); return true; } Object key = NameFactory.getObjectNameForCounter(nextKey); Log.getLogWriter().info("Destroying " + key); checkContainsValueForKey(key, true, "before destroy"); try { aRegion.destroy(key); Log.getLogWriter() .info( "Done Destroying " + key + ", num remaining: " + (keyIntervals.getLastKey(KeyIntervals.DESTROY) - nextKey)); } catch (CacheWriterException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (TimeoutException e) { throw new TestException(TestHelper.getStackTrace(e)); } catch (EntryNotFoundException e) { throw new TestException(TestHelper.getStackTrace(e)); } return (nextKey >= keyIntervals.getLastKey(KeyIntervals.DESTROY)); }
/** * 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); }
/** Log the number of ops that have completed. */ protected void logNumOps() { SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); int totalOps = keyIntervals.getNumKeys() - keyIntervals.getNumKeys(KeyIntervals.NONE) + numNewKeys; long numOpsCompleted = sc.read(CQUtilBB.LASTKEY_INVALIDATE) - keyIntervals.getFirstKey(KeyIntervals.INVALIDATE) + sc.read(CQUtilBB.LASTKEY_DESTROY) - keyIntervals.getFirstKey(KeyIntervals.DESTROY) + sc.read(CQUtilBB.LASTKEY_UPDATE_EXISTING_KEY) - keyIntervals.getFirstKey(KeyIntervals.UPDATE_EXISTING_KEY) + sc.read(CQUtilBB.LASTKEY_GET) - keyIntervals.getFirstKey(KeyIntervals.GET) + sc.read(CQUtilBB.NUM_NEW_KEYS_CREATED); Log.getLogWriter() .info( "Total ops is " + totalOps + ", current number of ops completed is " + numOpsCompleted); }
/** Clear the event counters (associated with number of operations performed */ public void zeroEventCounters() { SharedCounters sc = getSharedCounters(); sc.zero(LOCAL_CREATE); sc.zero(LOCAL_CREATE_ISLOAD); sc.zero(LOCAL_UPDATE); sc.zero(LOCAL_UPDATE_ISLOAD); sc.zero(LOCAL_DESTROY); sc.zero(LOCAL_INVALIDATE); sc.zero(LOCAL_LOCAL_DESTROY); sc.zero(LOCAL_LOCAL_INVALIDATE); sc.zero(CONFLATED_CREATE_DESTROY); sc.zero(CREATE_IN_DESTROYED_REGION); sc.zero(CREATE_IN_DESTROYED_REGION_ISLOAD); sc.zero(REMOTE_CREATE); sc.zero(REMOTE_CREATE_ISLOAD); sc.zero(REMOTE_UPDATE); sc.zero(REMOTE_UPDATE_ISLOAD); sc.zero(REMOTE_DESTROY); sc.zero(REMOTE_INVALIDATE); sc.zero(REMOTE_LOCAL_DESTROY); sc.zero(REMOTE_LOCAL_INVALIDATE); // TransactionListener callback counters sc.zero(TX_SUCCESS); sc.zero(TX_FAILURE); sc.zero(TX_ROLLBACK); sc.zero(NUM_EXPECTED_FAILED_COMMIT); sc.zero(NUM_EXPECTED_ROLLBACK); }
/** * Check event counters. If numCloseIsExact is true, then the number of close events must be an * exact match, otherwise allow numClose events to be the minimum of the expected numClose * counter. This is useful in tests where the timing of shutting down the VMs/C clients may or may * not cause a close event. * * @param eventCountExact - True if the event counters must exactly match the expected value, * false if the event counters must be no less than the expected counter. */ protected void checkEventCounters(boolean eventCountExact) { SharedCounters counters = BridgeNotifyBB.getBB().getSharedCounters(); long numCreate = counters.read(BridgeNotifyBB.NUM_CREATE); long numUpdate = counters.read(BridgeNotifyBB.NUM_UPDATE); long numPutAllCreate = counters.read(BridgeNotifyBB.NUM_PUTALL_CREATE); long numPutAllUpdate = counters.read(BridgeNotifyBB.NUM_PUTALL_UPDATE); long numDestroy = counters.read(BridgeNotifyBB.NUM_DESTROY); long numInval = counters.read(BridgeNotifyBB.NUM_INVALIDATE); long numRegionCreate = counters.read(BridgeNotifyBB.NUM_REGION_CREATE); long numRegionDestroy = counters.read(BridgeNotifyBB.NUM_REGION_DESTROY); long numRegionInval = counters.read(BridgeNotifyBB.NUM_REGION_INVALIDATE); long numLocalDestroy = counters.read(BridgeNotifyBB.NUM_LOCAL_DESTROY); long numLocalInval = counters.read(BridgeNotifyBB.NUM_LOCAL_INVALIDATE); long numLocalRegionDestroy = counters.read(BridgeNotifyBB.NUM_LOCAL_REGION_DESTROY); long numLocalRegionInval = counters.read(BridgeNotifyBB.NUM_LOCAL_REGION_INVALIDATE); long numClose = counters.read(BridgeNotifyBB.NUM_CLOSE); /* the ALL_KEYS client will always get events (including creates on new keys) * the ALL_KEYS and one of the KeyList (odd/even) clients will always get all events * on the original keySet * we'll get 3 events per operation if we happen to select the singleKey client's key * This is written to the BB by the VM performing the operation (it knows how many * clients should get the update) */ // factor this out to separate lines to track down an NPE issue // 2006-08-29 jpenney BridgeNotifyBB bnbb = BridgeNotifyBB.getBB(); SharedMap sm = bnbb.getSharedMap(); Object nl = sm.get(BridgeNotifyBB.numListeners); int numVmsWithList = ((Integer) nl).intValue(); Log.getLogWriter().info("num VMs with listener installed: " + numVmsWithList); // This mixedBridgeNotify test always uses notifyBySubscription/registerInterest // Note: to some degree we have to know if this key was in the original keyList ArrayList al = new ArrayList(); al.add( new ExpCounterValue( "numAfterCreateEvents_isNotExp", (numCreate * numVmsWithList + numPutAllCreate * numVmsWithList), eventCountExact)); al.add( new ExpCounterValue( "numAfterDestroyEvents_isNotExp", (numDestroy * numVmsWithList), eventCountExact)); al.add( new ExpCounterValue( "numAfterInvalidateEvents_isNotExp", (numInval * numVmsWithList), eventCountExact)); al.add( new ExpCounterValue( "numAfterUpdateEvents_isNotExp", (numUpdate * numVmsWithList + numPutAllUpdate * numVmsWithList), eventCountExact)); al.add(new ExpCounterValue("numAfterRegionDestroyEvents_isNotExp", 0, eventCountExact)); al.add(new ExpCounterValue("numAfterRegionInvalidateEvents_isNotExp", 0, eventCountExact)); al.add(new ExpCounterValue("numClose", numClose, eventCountExact)); EventCountersBB.getBB().checkEventCounters(al); // This only works on a serial basis, since each operation performed has a different // number of listeners with registered interest, therefore, we must clean the // BridgeNotifyBB operation counters each time counters.zero(BridgeNotifyBB.NUM_CREATE); counters.zero(BridgeNotifyBB.NUM_UPDATE); counters.zero(BridgeNotifyBB.NUM_PUTALL_CREATE); counters.zero(BridgeNotifyBB.NUM_PUTALL_UPDATE); counters.zero(BridgeNotifyBB.NUM_DESTROY); counters.zero(BridgeNotifyBB.NUM_INVALIDATE); // clear EventCountersBB as well (for actual event counters recv'd) EventCountersBB.getBB().zeroAllCounters(); }