/** * Check event counters in the ControllerBB shared map. For example, if baseKey is * ControllerBB.NumForcedDiscEventsKey and vmList is a list containing vmId 2, and expectedCount * is 1, then the event count of key with base NumForcedDiscEvents plus vmId 2 is expected to be * 1, and any other key found in the map that is prefixed by baseKey should have value be 0. * Throws an exception if the conditions are not satisfied. * * @param baseKey The base string of the key to check (the prefix to the vm id) * @param vmList The vms (ClientVmInfo) for the baseKey should have a value of expectedCount. * @param expectedCount The expected value of any baseKeys that refer to the given vmIds, * otherwise the expectedCount is 0. */ public static void checkEventCounters(String baseKey, List vmList, int expectedCount) { Map aMap = ControllerBB.getBB().getSharedMap().getMap(); Iterator it = aMap.keySet().iterator(); while (it.hasNext()) { String key = (String) (it.next()); if (key.startsWith(baseKey)) { // found a key prefixed by baseKey int value = ((Integer) (aMap.get(key))).intValue(); // value for the key boolean foundInVmIdList = false; for (int i = 0; i < vmList.size(); i++) { int vmId = ((Integer) ((ClientVmInfo) (vmList.get(i))).getVmid()).intValue(); if (key.endsWith("_" + vmId)) { // found a baseKey with a vmid in the vmList foundInVmIdList = true; if (value != expectedCount) { throw new TestException( "Expected value for BB key " + key + " to be " + expectedCount + " but it is " + value); } } } if (!foundInVmIdList) { // this key's value should be 0 if (value != 0) { throw new TestException( "Expected value for BB key " + key + " to be 0 but it is " + value); } } } } }
protected void doAfterCreate(EntryEvent event) { if (ControllerBB.isPlayDeadEnabled()) { SBUtil.playDead(); } if (ControllerBB.isSlowListenerEnabled()) { // slow logCall("afterCreate", event); Log.getLogWriter().info("Sleeping while slow listeners are enabled..."); do { MasterController.sleepForMs(5000); } while (ControllerBB.isSlowListenerEnabled()); Log.getLogWriter().info("Done being slow, returning from ForcedDiscListener.afterCreate"); } else if (ControllerBB.isSicknessEnabled()) { // sick logCall("afterCreate", event); SBUtil.beSick(); } }
/** Signal that the membershipFailure is complete. */ public static void signalMembershipFailureComplete() { Log.getLogWriter() .info( "ControllerBB: signaling membership failure complete for vmID " + RemoteTestModule.getMyVmid()); String key = ControllerBB.MembershipFailureCompleteKey + RemoteTestModule.getMyVmid(); ControllerBB.getBB().getSharedMap().put(key, new Long(System.currentTimeMillis())); }
/** Get the value of the shared map counter for this vm. */ public static int getMapCounter(String keyBase) { String key = keyBase + RemoteTestModule.getMyVmid(); Object value = ControllerBB.getBB().getSharedMap().get(key); if (value == null) { return 0; } else { int intVal = ((Integer) value).intValue(); return intVal; } }
/** * Atomically increment a counter in the ControllerBB sharedMap. * * @param keyBase A string from ControllerBB that prefixes a vm id to use as a key in the * ControllerBB shared map. The VM id used is the current vm's id. */ public static void incMapCounter(String keyBase) { String key = keyBase + RemoteTestModule.getMyVmid(); Log.getLogWriter().info("Incrementing sharedMap counter " + key); SharedLock slock = ControllerBB.getBB().getSharedLock(); slock.lock(); try { int newValue = 0; Object value = ControllerBB.getBB().getSharedMap().get(key); if (value == null) { newValue = 1; } else { newValue = ((Integer) value).intValue() + 1; } ControllerBB.getBB().getSharedMap().put(key, new Integer(newValue)); Log.getLogWriter().info("Incremented sharedMap counter, count is now " + newValue); } finally { slock.unlock(); } }
/** Wait for the given vm to restart. */ public static void waitForRestartedVm(int vmID) { Log.getLogWriter().info("Waiting for vmID " + vmID + " to restart"); String key = ControllerBB.InitIsCompleteKey + vmID; while (true) { if (ControllerBB.getBB().getSharedMap().containsKey(key)) { Log.getLogWriter().info("Done Waiting for vmID " + vmID + " to restart"); return; } else { MasterController.sleepForMs(2000); } checkForError(); } }
/** Wait for the given vmid to recognize a severe alert. */ public static void waitForSevereAlert(int vmID) { Log.getLogWriter().info("Waiting for vmID " + vmID + " to recognize a severe alert"); String key = ControllerBB.SevereAlertKey + vmID; while (true) { if (ControllerBB.getBB().getSharedMap().containsKey(key)) { Log.getLogWriter().info("Done waiting for vmID " + vmID + " to recognize a severe alert"); return; } else { MasterController.sleepForMs(2000); } checkForError(); } }
/** Wait for the given vmid to become dead. */ public static void waitForIsDead(int vmID) { Log.getLogWriter().info("Waiting for vmID " + vmID + " to become dead"); String key = ControllerBB.IsDeadKey + vmID; while (true) { if (ControllerBB.getBB().getSharedMap().containsKey(key)) { Log.getLogWriter().info("Done waiting for vmID " + vmID + " to become dead"); return; } else { MasterController.sleepForMs(2000); } checkForError(); } }
/** Wait for membership failure to complete. */ public static void waitMembershipFailureComplete(int vmID) { Log.getLogWriter().info("Waiting for vmID " + vmID + " to complete membership failure"); String key = ControllerBB.MembershipFailureCompleteKey + vmID; while (true) { if (ControllerBB.getBB().getSharedMap().containsKey(key)) { Log.getLogWriter() .info("Done waiting for vmID " + vmID + " to complete membership failure"); return; } else { MasterController.sleepForMs(2000); } checkForError(); } }
/** Return whether sickness is enabled for the given vm. */ public static boolean isSicknessEnabled(int vmID) { String key = ControllerBB.EnableSickKey + vmID; return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Return whether the given vm has received a severe alert. */ public static boolean receivedSevereAlert(int vmID) { String key = ControllerBB.SevereAlertKey + vmID; return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Signal that a severe alert occurred for the given vm. */ public static void signalSevereAlert(int vmID) { String key = ControllerBB.SevereAlertKey + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Signal that the given vm is dead. */ public static void signalIsDead(int vmID) { String key = ControllerBB.IsDeadKey + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Return whether this vm is ready for initialization (typically after disconnecting). */ public static boolean isReadyForInit(int vmID) { String key = ControllerBB.ReadyForInitKey + vmID; return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Clear all blackboard signals. */ public static void reset(int vmID) { ControllerBB.getBB().getSharedMap().remove(ControllerBB.ErrorKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.EnableSlowListenerKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.EnableSickKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.EnableDeadKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.ReadyForInitKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.InitIsCompleteKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.MembershipFailureBegunKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.MembershipFailureCompleteKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.SevereAlertKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.IsSickKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.IsDeadKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.NumForcedDiscEventsKey + vmID); ControllerBB.getBB().getSharedMap().remove(ControllerBB.VmRestarted + vmID); Log.getLogWriter().info("ControllerBB: reset vmID " + vmID); }
/** Check if an error has been recorded in the blackboard. */ public static void checkForError() { Object error = ControllerBB.getBB().getSharedMap().get(ControllerBB.ErrorKey); if (error != null) { throw new TestException(error.toString()); } }
/** Signal that the given vm has restarted. */ public static void signalVmRestarted(int vmID) { Log.getLogWriter().info("ControllerBB: signaling init is complete for vmID " + vmID); String key = ControllerBB.VmRestarted + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Enable sickness for the given vmid */ public static void enableSickness(int vmID) { Log.getLogWriter().info("ControllerBB: enabling sickness for vmID " + vmID); Object key = ControllerBB.EnableSickKey + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Return whether membership failure is complete for this vm. */ public static boolean isMembershipFailureComplete() { String key = ControllerBB.MembershipFailureCompleteKey + RemoteTestModule.getMyVmid(); return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Return the currentTimeMillis value of when membership failure completed */ public static long getMembershipFailureCompletionTime() { String key = ControllerBB.MembershipFailureCompleteKey + RemoteTestModule.getMyVmid(); return ((Long) (ControllerBB.getBB().getSharedMap().get(key))).longValue(); }
/** Enable becoming dead for the given vmid */ public static void enablePlayDead(int vmID) { Log.getLogWriter().info("ControllerBB: enabling play dead for vmID " + vmID); Object key = ControllerBB.EnableDeadKey + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Enable slow listeners for the given vmid */ public static void enableSlowListener(int vmID) { Log.getLogWriter().info("ControllerBB: enabling slow listeners for vmID " + vmID); Object key = ControllerBB.EnableSlowListenerKey + vmID; ControllerBB.getBB().getSharedMap().put(key, ""); }
/** Return the vmid for the given pid, assuming this was recorded in the bb during init tasks. */ public static int getVmIdForPid(int pid) { int vmid = ((Integer) (ControllerBB.getBB().getSharedMap().get("" + pid))).intValue(); return vmid; }
/** Return whether slow listeners are enabled for the given vm. */ public static boolean isSlowListenerEnabled(int vmID) { String key = ControllerBB.EnableSlowListenerKey + vmID; return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Return whether the current vm is enabled for being dead. */ public static boolean isPlayDeadEnabled() { String key = ControllerBB.EnableDeadKey + RemoteTestModule.getMyVmid(); return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Signal that the given vm is ready for intialization. */ public static void signalReadyForInit(int vmID) { Log.getLogWriter().info("ControllerBB: ready for init for vmID " + vmID); ControllerBB.getBB().getSharedMap().put(ControllerBB.ReadyForInitKey + vmID, ""); }
/** Return whether the given vm is enabled for being dead. */ public static boolean isPlayDeadEnabled(int vmID) { String key = ControllerBB.EnableDeadKey + vmID; return ControllerBB.getBB().getSharedMap().containsKey(key); }
/** Return whether slow listeners are enabled for the current vm. */ public static boolean isSlowListenerEnabled() { String key = ControllerBB.EnableSlowListenerKey + RemoteTestModule.getMyVmid(); return ControllerBB.getBB().getSharedMap().containsKey(key); }