/** * Get a list of "other" vms, along with stop modes. The "other" vms are any vms other than the * currently executing vm. The stop mode for each VM is chosen from util.StopStartPrms.stopMode. * * @param numVMsToTarget The number of VMs to target for a stop/start. * @param clientMatchStr A string the must be contained in the client name to be included in the * vms to target, or null. * @throws TestException if there aren't numToTarget VMs available. * @returns Object[0] - a List of ClientVmInfos. Object[1] - a List of stop modes. Object[2] - a * List of vms eligible but not chosen. */ public static Object[] getOtherVMs(int numToTarget, String clientMatchStr) { Log.getLogWriter().info("Choosing " + numToTarget + " vms (other than this one)"); // get the VMs; vmList and stopModeList are parallel lists ArrayList vmList = new ArrayList(); ArrayList stopModeList = new ArrayList(); int myVmID = RemoteTestModule.getMyVmid(); // get VMs that contain the clientMatchStr List vmInfoList = getAllVMs(); vmInfoList = getMatchVMs(vmInfoList, clientMatchStr); // now all vms in vmInfoList match the clientMatchStr do { if (vmInfoList.size() == 0) { throw new TestException( "Unable to find " + numToTarget + " vms to stop with client match string " + clientMatchStr + "; either a test problem or add StopStartVMs.StopStart_initTask to the test"); } // add a VmId to the list of vms to stop int randInt = TestConfig.tab().getRandGen().nextInt(0, vmInfoList.size() - 1); ClientVmInfo info = (ClientVmInfo) (vmInfoList.get(randInt)); if (info.getVmid().intValue() != myVmID) { // info is not the current VM vmList.add(info); // choose a stopMode String choice = TestConfig.tab().stringAt(StopStartPrms.stopModes); stopModeList.add(choice); } vmInfoList.remove(randInt); } while (vmList.size() < numToTarget); return new Object[] {vmList, stopModeList, vmInfoList}; }
/** * Hydra start task to initialize key intervals, which are ranges of keys which are to have an * operation done on them (invalidate, destroy, etc) */ public static synchronized void StartTask_initialize() { int numKeys = TestConfig.tab().intAt(CQUtilPrms.numKeys); KeyIntervals intervals = new KeyIntervals( new int[] { KeyIntervals.NONE, KeyIntervals.INVALIDATE, KeyIntervals.DESTROY, KeyIntervals.UPDATE_EXISTING_KEY, KeyIntervals.GET }, numKeys); CQUtilBB.getBB().getSharedMap().put(CQUtilBB.KeyIntervals, intervals); Log.getLogWriter().info("Created keyIntervals: " + intervals); // Set the counters for the next keys to use for each operation hydra.blackboard.SharedCounters sc = CQUtilBB.getBB().getSharedCounters(); sc.setIfLarger(CQUtilBB.LASTKEY_INVALIDATE, intervals.getFirstKey(KeyIntervals.INVALIDATE) - 1); sc.setIfLarger( CQUtilBB.LASTKEY_LOCAL_INVALIDATE, intervals.getFirstKey(KeyIntervals.LOCAL_INVALIDATE) - 1); sc.setIfLarger(CQUtilBB.LASTKEY_DESTROY, intervals.getFirstKey(KeyIntervals.DESTROY) - 1); sc.setIfLarger( CQUtilBB.LASTKEY_LOCAL_DESTROY, intervals.getFirstKey(KeyIntervals.LOCAL_DESTROY) - 1); sc.setIfLarger( CQUtilBB.LASTKEY_UPDATE_EXISTING_KEY, intervals.getFirstKey(KeyIntervals.UPDATE_EXISTING_KEY) - 1); sc.setIfLarger(CQUtilBB.LASTKEY_GET, intervals.getFirstKey(KeyIntervals.GET) - 1); // show the blackboard CQUtilBB.getBB().printSharedMap(); CQUtilBB.getBB().printSharedCounters(); }
/** * Get a random operation to perform. The set of operations available are in the BitSet. These * bits correspond to the operations defined in this class. * * @param bs True bits correspond to operations available to be chosen. * @param bsSize The number of bits to consider. * @return An operation as defined in this class. */ protected int getOp(BitSet bs, int bsSize) { int randInt; do { randInt = TestConfig.tab().getRandGen().nextInt(1, bsSize); } while (!bs.get(randInt)); return randInt; }
/** * Return a List of all other vms except for one along with a parallel stop mode list, and also * return the one vm not in the list. * * @return [0] (List<ClientVmInfo>)A List of ClientVmInfo instances; this includes all vms except * the current vm and except for one other vm. [1] (List<String>) A parallel List to [0] * containing stop modes. [2] (ClientVMInfo) The ClientVmInfo instance of the one vm excluded * from [0] (other than this vm) [3] (String) The stop mode for [2] [4] (List<ClientVmInfo>) A * List of ClientVmInfo instances for all vms except this one. [5] (List<String>) A parallel * List to [4] of stop modes. */ public static Object[] getOtherVMsDivided(String[] excludedClientNames) { Vector<Integer> otherVmIDs = ClientVmMgr.getOtherClientVmids(); List<ClientVmInfo> allOtherVMs = new ArrayList(); List<String> stopModeList = new ArrayList(); for (int i = 0; i < otherVmIDs.size(); i++) { ClientVmInfo info = new ClientVmInfo(otherVmIDs.get(i)); ClientVmInfo infoFromBB = (ClientVmInfo) StopStartBB.getBB().getSharedMap().get(VmInfoKey + otherVmIDs.get(i)); if (infoFromBB != null) { info = infoFromBB; } String clientName = info.getClientName(); if (clientName == null) { allOtherVMs.add(info); stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes)); } else { boolean inExcludedNames = false; for (String excludeName : excludedClientNames) { if (clientName.indexOf(excludeName) >= 0) inExcludedNames = true; break; } if (!inExcludedNames) { allOtherVMs.add(info); stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes)); } } } List<ClientVmInfo> allOtherVMsExceptOne = allOtherVMs.subList(0, allOtherVMs.size() - 1); List<String> stopModesExceptOne = stopModeList.subList(0, stopModeList.size() - 1); ClientVmInfo remainingVM = allOtherVMs.get(allOtherVMs.size() - 1); String remainingStopMode = stopModeList.get(stopModeList.size() - 1); return new Object[] { allOtherVMsExceptOne, stopModesExceptOne, remainingVM, remainingStopMode, allOtherVMs, stopModeList }; }
/** * Get a list of "other" vms, along with stop modes. The "other" vms are any vms other than the * currently executing vm. The stop mode for each VM is chosen from util.StopStartPrms.stopMode. * * @param numVMsToTarget The number of VMs to target for a stop/start. * @param clientExcludeStr Any vm name that contains this string as a substring is excluded from * consideration. * @throws TestException if there aren't numToTarget VMs available. * @returns Object[0] - a List of ClientVmInfos. Object[1] - a List of stop modes. Object[2] - a * List of vms eligible but not chosen. */ public static Object[] getOtherVMsWithExclude(int numToTarget, String clientExcludeStr) { Log.getLogWriter().info("Choosing " + numToTarget + " vms (other than this one)"); // get the VMs; vmList and stopModeList are parallel lists ArrayList vmList = new ArrayList(); ArrayList stopModeList = new ArrayList(); int myVmID = RemoteTestModule.getMyVmid(); // put numToTarget in vmList List vmInfoList = getAllVMs(); do { if (vmInfoList.size() == 0) { throw new TestException( "Unable to find " + numToTarget + " vms to stop with client exclude string " + clientExcludeStr + "; either a test problem or add StopStartVMs.StopStart_initTask to the test"); } // add a VmId to the list of vms to stop int randInt = TestConfig.tab().getRandGen().nextInt(0, vmInfoList.size() - 1); Object anObj = vmInfoList.get(randInt); if (anObj instanceof ClientVmInfo) { ClientVmInfo info = (ClientVmInfo) (anObj); if (info.getVmid().intValue() != myVmID) { // info is not the current VM if ((clientExcludeStr != null) && (info.getClientName().indexOf(clientExcludeStr) >= 0)) { // exclude this vm } else { vmList.add(info); // choose a stopMode String choice = TestConfig.tab().stringAt(StopStartPrms.stopModes); stopModeList.add(choice); } } } vmInfoList.remove(randInt); } while (vmList.size() < numToTarget); return new Object[] {vmList, stopModeList, vmInfoList}; }
/** Initialize fields for this instance */ public void initializeInstance() { numNewKeys = TestConfig.tab().intAt(CQUtilPrms.numNewKeys, -1); keyIntervals = (KeyIntervals) (CQUtilBB.getBB().getSharedMap().get(CQUtilBB.KeyIntervals)); Log.getLogWriter() .info("initInstance, keyIntervals read from blackboard = " + keyIntervals.toString()); int numDestroyed = keyIntervals.getNumKeys(KeyIntervals.DESTROY); int numKeyIntervals = keyIntervals.getNumKeys(); totalNumKeys = numKeyIntervals + numNewKeys - numDestroyed; minTaskGranularitySec = TestConfig.tab().longAt(TestHelperPrms.minTaskGranularitySec, -1); minTaskGranularityMS = -1; if (minTaskGranularitySec != -1) { minTaskGranularityMS = minTaskGranularitySec * TestHelper.SEC_MILLI_FACTOR; } queryDepth = TestConfig.tab().intAt(CQUtilPrms.queryDepth, 1); Vector bridgeNames = TestConfig.tab().vecAt(BridgePrms.names, null); isBridgeConfiguration = bridgeNames != null; CQsOn = TestConfig.tab().booleanAt(CQUtilPrms.CQsOn, true); CQTestInstance = new CQTest(); CQTestInstance.initializeInstance(); Log.getLogWriter().info("numKeyIntervals is " + numKeyIntervals); Log.getLogWriter().info("numNewKeys is " + numNewKeys); Log.getLogWriter().info("numDestroyed is " + numDestroyed); Log.getLogWriter().info("totalNumKeys is " + totalNumKeys); }
protected void initializeQueryService() { try { String usingPool = TestConfig.tab().stringAt(CQUtilPrms.QueryServiceUsingPool, "false"); boolean queryServiceUsingPool = Boolean.valueOf(usingPool).booleanValue(); if (queryServiceUsingPool) { Pool pool = PoolHelper.createPool(CQUtilPrms.getQueryServicePoolName()); qService = pool.getQueryService(); Log.getLogWriter() .info("Initializing QueryService using Pool. PoolName: " + pool.getName()); } else { qService = CacheHelper.getCache().getQueryService(); Log.getLogWriter().info("Initializing QueryService using Cache."); } } catch (Exception e) { throw new TestException(TestHelper.getStackTrace(e)); } }
/** * Return a List of all other vms except for one along with a parallel stop mode list, and also * return the one vm not in the list. * * @return [0] (List<ClientVmInfo>)A List of ClientVmInfo instances; this includes all vms except * the current vm and except for one other vm. [1] (List<String>) A parallel List to [0] * containing stop modes. [2] (ClientVMInfo) The ClientVmInfo instance of the one vm excluded * from [0] (other than this vm) [3] (String) The stop mode for [2] [4] (List<ClientVmInfo>) A * List of ClientVmInfo instances for all vms except this one. [5] (List<String>) A parallel * List to [4] of stop modes. */ public static Object[] getOtherVMsDivided() { Vector<Integer> otherVmIDs = ClientVmMgr.getOtherClientVmids(); List<ClientVmInfo> allOtherVMs = new ArrayList(); List<String> stopModeList = new ArrayList(); for (int i = 0; i < otherVmIDs.size(); i++) { ClientVmInfo info = new ClientVmInfo(otherVmIDs.get(i)); allOtherVMs.add(info); stopModeList.add(TestConfig.tab().stringAt(StopStartPrms.stopModes)); } List<ClientVmInfo> allOtherVMsExceptOne = allOtherVMs.subList(0, allOtherVMs.size() - 1); List<String> stopModesExceptOne = stopModeList.subList(0, stopModeList.size() - 1); ClientVmInfo remainingVM = allOtherVMs.get(allOtherVMs.size() - 1); String remainingStopMode = stopModeList.get(stopModeList.size() - 1); return new Object[] { allOtherVMsExceptOne, stopModesExceptOne, remainingVM, remainingStopMode, allOtherVMs, stopModeList }; }
/** * Verify the contents of the region, taking into account the keys that were destroyed, * invalidated, etc (as specified in keyIntervals) Throw an error of any problems are detected. * This must be called repeatedly by the same thread until StopSchedulingTaskOnClientOrder is * thrown. */ public void verifyRegionContents() { final long LOG_INTERVAL_MILLIS = 10000; // we already completed this check once; we can't do it again without reinitializing the // verify state variables if (verifyRegionContentsCompleted) { throw new TestException( "Test configuration problem; already verified region contents, " + "cannot call this task again without resetting batch variables"); } // iterate keys long lastLogTime = System.currentTimeMillis(); long minTaskGranularitySec = TestConfig.tab().longAt(TestHelperPrms.minTaskGranularitySec); long minTaskGranularityMS = minTaskGranularitySec * TestHelper.SEC_MILLI_FACTOR; long startTime = System.currentTimeMillis(); long size = aRegion.size(); boolean first = true; int numKeysToCheck = keyIntervals.getNumKeys() + numNewKeys; while (verifyRegionContentsIndex < numKeysToCheck) { verifyRegionContentsIndex++; if (first) { Log.getLogWriter() .info( "In verifyRegionContents, region has " + size + " keys; starting verify at verifyRegionContentsIndex " + verifyRegionContentsIndex + "; verifying key names with indexes through (and including) " + numKeysToCheck); first = false; } // check region size the first time through the loop to avoid it being called // multiple times when this is batched if (verifyRegionContentsIndex == 1) { if (totalNumKeys != size) { String tmpStr = "Expected region size to be " + totalNumKeys + ", but it is size " + size; Log.getLogWriter().info(tmpStr); verifyRegionContentsErrStr.append(tmpStr + "\n"); } } Object key = NameFactory.getObjectNameForCounter(verifyRegionContentsIndex); try { if (((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.NONE)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.NONE))) || ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.GET)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.GET)))) { // this key was untouched after its creation checkContainsKey(key, true, "key was untouched"); checkContainsValueForKey(key, true, "key was untouched"); Object value = aRegion.get(key); checkValue(key, value); } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.INVALIDATE)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.INVALIDATE))) { checkContainsKey(key, true, "key was invalidated"); checkContainsValueForKey(key, false, "key was invalidated"); } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.LOCAL_INVALIDATE)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.LOCAL_INVALIDATE))) { // this key was locally invalidated checkContainsKey(key, true, "key was locally invalidated"); checkContainsValueForKey(key, true, "key was locally invalidated"); Object value = aRegion.get(key); checkValue(key, value); } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.DESTROY)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.DESTROY))) { // this key was destroyed checkContainsKey(key, false, "key was destroyed"); checkContainsValueForKey(key, false, "key was destroyed"); } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.LOCAL_DESTROY)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.LOCAL_DESTROY))) { // this key was locally destroyed checkContainsKey(key, true, "key was locally destroyed"); checkContainsValueForKey(key, true, "key was locally destroyed"); Object value = aRegion.get(key); checkValue(key, value); } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.UPDATE_EXISTING_KEY)) && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.UPDATE_EXISTING_KEY))) { // this key was updated checkContainsKey(key, true, "key was updated"); checkContainsValueForKey(key, true, "key was updated"); Object value = aRegion.get(key); checkUpdatedValue(key, value); } else if (verifyRegionContentsIndex > keyIntervals.getNumKeys()) { // key was newly added checkContainsKey(key, true, "key was new"); checkContainsValueForKey(key, true, "key was new"); Object value = aRegion.get(key); checkValue(key, value); } } catch (TestException e) { Log.getLogWriter().info(TestHelper.getStackTrace(e)); verifyRegionContentsErrStr.append(e.getMessage() + "\n"); } if (System.currentTimeMillis() - lastLogTime > LOG_INTERVAL_MILLIS) { Log.getLogWriter() .info("Verified key " + verifyRegionContentsIndex + " out of " + totalNumKeys); lastLogTime = System.currentTimeMillis(); } if (System.currentTimeMillis() - startTime >= minTaskGranularityMS) { Log.getLogWriter() .info( "In HydraTask_verifyRegionContents, returning before completing verify " + "because of task granularity (this task must be batched to complete); last key verified is " + key); return; // task is batched; we are done with this batch } } verifyRegionContentsCompleted = true; if (verifyRegionContentsErrStr.length() > 0) { throw new TestException(verifyRegionContentsErrStr.toString()); } String aStr = "In HydraTask_verifyRegionContents, verified " + verifyRegionContentsIndex + " keys/values"; Log.getLogWriter().info(aStr); throw new StopSchedulingTaskOnClientOrder(aStr); }
/** * Invokes AdminDistributedSystem.shutDownAllMembers() which disconnects all members but leaves * the vms up (because hydra threads remain) including the possibility of this vm being * disconnected, then this actually stops those vms (except this vm if it was targeted in the * shutDownAllMembers...this vm will remain up but disconnect). Stopped vms are stopped with * ON_DEMAND restart. This returns when the vms disconnected by shutDownAllMembers() (other than * this one) are all stopped . * * @param adminDS The admin distributed system instance to use to call shutdownAllMembers. * @param stopModes The stop modes to choose from. * @return An Array [0] List of {@link ClientVmInfo} instances describing the VMs that were * stopped. [1] Set, the return from shutdownAllMembers() * @throws AdminException if the shutDownAllMembers call throws this exception. */ public static Object[] shutDownAllMembers( AdminDistributedSystem adminDS, List<String> stopModes) { if (adminDS == null) { throw new HydraRuntimeException("AdminDistributedSystem cannot be null"); } // Invoke shutDownAllMembers Log.getLogWriter().info("AdminDS " + adminDS + " is shutting down all members..."); Set<DistributedMember> memberSet; try { long startTime = System.currentTimeMillis(); memberSet = adminDS.shutDownAllMembers(); long duration = System.currentTimeMillis() - startTime; Log.getLogWriter() .info( "AdminDS " + adminDS + " shut down (disconnected) the following members " + "(vms remain up): " + memberSet + "; shutDownAll duration " + duration + "ms"); } catch (AdminException e1) { throw new TestException(TestHelper.getStackTrace(e1)); } // Now actually stop the vms. // First get the ClientVmInfos for the members that shutDownAllMembers // disconnected. List<ClientVmInfo> allClientInfos = new ArrayList(); // all members that were shutdown List<ClientVmInfo> allOtherClientInfos = new ArrayList(); // all members that were shutdown except this member ClientVmInfo thisClientInfo = null; // this member, or will remain null if this member was not shutdown List<String> stopModesToUse = new ArrayList(); for (DistributedMember aMember : memberSet) { Integer vmId = null; try { vmId = new Integer(RemoteTestModule.Master.getVmid(aMember.getHost(), aMember.getProcessId())); } catch (java.rmi.RemoteException e) { throw new HydraRuntimeException("Unable to get vmID for " + aMember + ": " + e); } ClientVmInfo infoFromBB = (ClientVmInfo) StopStartBB.getBB().getSharedMap().get("StopStartVMInfo_for_vmid_" + vmId); String clientName = null; if (infoFromBB != null) { clientName = infoFromBB.getClientName(); } ClientVmInfo info = new ClientVmInfo(vmId, clientName, null); allClientInfos.add(info); if (vmId == RemoteTestModule.getMyVmid()) { // shutdownAll disconnected this vm thisClientInfo = info; } else { // aMember is not the current vm allOtherClientInfos.add(info); } stopModesToUse.add( stopModes.get(TestConfig.tab().getRandGen().nextInt(0, stopModes.size() - 1))); } // now actually stop the vms; if this vm is included, do it last Object[] returnArr = new Object[2]; if (thisClientInfo == null) { // shutDownAllMembers did not disconnect this vm // we can just stop all of them now and this vm lives on StopStartVMs.stopVMs(allClientInfos, stopModesToUse); // restart is ON_DEMAND returnArr[0] = allClientInfos; } else { // this vm was disconnected by shutDownAllMembers // first shutdown all other members except this one StopStartVMs.stopVMs(allOtherClientInfos, stopModesToUse.subList(0, stopModesToUse.size())); returnArr[0] = allOtherClientInfos; } returnArr[1] = memberSet; return returnArr; }
public static int getMaxExecutions() { Long key = maxExecutions; int val = TestConfig.tasktab().intAt(key, TestConfig.tab().intAt(key, 10)); return val; }