/** 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()));
 }
 /**
  * Creates and initializes the singleton instance of CQTest in a client and start the CQs running.
  */
 public static synchronized void HydraTask_initializeClient() {
   if (testInstance == null) {
     testInstance = new CQKnownKeysTest();
     testInstance.initializeClient(true);
   }
   testInstance.uniqueKeyIndex.set(new Integer(RemoteTestModule.getCurrentThread().getThreadId()));
 }
  /**
   * 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};
  }
 /** 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;
   }
 }
 /** Creates and initializes a data store PR in a bridge server. */
 public static synchronized void HydraTask_initializeBridgeServer() {
   if (testInstance == null) {
     testInstance = new CQKnownKeysTest();
     testInstance.initializeRegion("serverRegion");
     testInstance.initializeInstance();
     BridgeHelper.startBridgeServer("bridge");
     testInstance.isBridgeClient = false;
   }
   testInstance.uniqueKeyIndex.set(new Integer(RemoteTestModule.getCurrentThread().getThreadId()));
 }
 /**
  * Create a region with the given region description name.
  *
  * @param regDescriptName The name of a region description.
  */
 protected void initializeRegion(String regDescriptName) {
   CacheHelper.createCache("cache1");
   String key = VmIDStr + RemoteTestModule.getMyVmid();
   String xmlFile = key + ".xml";
   try {
     CacheHelper.generateCacheXmlFile("cache1", regDescriptName, xmlFile);
   } catch (HydraRuntimeException e) {
     if (e.toString().indexOf("Cache XML file was already created") >= 0) {
       // this can occur when reinitializing after a stop-start because
       // the cache xml file is written during the first init tasks
     } else {
       throw new TestException(TestHelper.getStackTrace(e));
     }
   }
   aRegion = RegionHelper.createRegion(regDescriptName);
 }
 /**
  * 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();
   }
 }
  /**
   * 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};
  }
 /** 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);
 }
 /** Wait for the current vm to recognize a severe alert. */
 public static void waitForSevereAlert() {
   waitForSevereAlert(RemoteTestModule.getMyVmid());
 }
 /** Signal that this vm is ready for intialization. */
 public static void signalReadyForInit() {
   signalReadyForInit(RemoteTestModule.getMyVmid());
 }
 /** Signal that a severe alert occurred in the current vm. */
 public static void signalSevereAlert() {
   signalSevereAlert(RemoteTestModule.getMyVmid());
 }
 /** Return whether the current vm has received a severe alert. */
 public static boolean receivedSevereAlert() {
   return receivedSevereAlert(RemoteTestModule.getMyVmid());
 }
 /** Wait for the current vm to complete initialization */
 public static void waitForInitialization() {
   waitForInitialization(RemoteTestModule.getMyVmid());
 }
 /** Wait for the current vm to become dead. */
 public static void waitForIsDead() {
   waitForIsDead(RemoteTestModule.getMyVmid());
 }
  /**
   * 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;
  }
 /** 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);
 }
 /** Wait for membership failure to complete. */
 public static void waitMembershipFailureComplete() {
   waitMembershipFailureComplete(RemoteTestModule.getMyVmid());
 }
 /** Return whether this vm is ready for initialization. */
 public static boolean isReadyForInit() {
   return isReadyForInit(RemoteTestModule.getMyVmid());
 }
 /** 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();
 }
 /** Returns true if a NICE_KILL is in progress in this VM, false otherwise */
 public static boolean niceKillInProgress() {
   Object niceKill =
       StopStartBB.getBB().getSharedMap().get(NiceKillInProgress + RemoteTestModule.getMyVmid());
   boolean niceKillInProgress = (niceKill != null) && (((Boolean) niceKill).booleanValue());
   return niceKillInProgress;
 }
 /** Enable slow listeners for the current vm */
 public static void enableSlowListener() {
   enableSlowListener(RemoteTestModule.getMyVmid());
 }
 /** Signal that the current vm is dead. */
 public static void signalIsDead() {
   signalIsDead(RemoteTestModule.getMyVmid());
 }
 /** Enable becoming dead for the current vm */
 public static void enablePlayDead() {
   enablePlayDead(RemoteTestModule.getMyVmid());
 }
 /** Signal that initialization for this VM is complete. */
 public static void signalInitIsComplete() {
   signalInitIsComplete(RemoteTestModule.getMyVmid());
 }
 /** Enable sickness for the current vm */
 public static void enableSickness() {
   enableSickness(RemoteTestModule.getMyVmid());
 }
 /**
  * An init task to write ClientVmInfo instances to the blackboard, for use later in choosing vms
  * to stop/start. This is only necessary if getOtherVMs(numToTarget, clientMatchStr) is used.
  */
 public static void StopStart_initTask() {
   int myVMid = RemoteTestModule.getMyVmid();
   ClientVmInfo myInfo =
       new ClientVmInfo(new Integer(myVMid), RemoteTestModule.getMyClientName(), null);
   StopStartBB.getBB().getSharedMap().put(VmInfoKey + myVMid, myInfo);
 }