new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/TestUtils.java
public static boolean callWebAppAndCheckForServerNameInResponse(
      String curlCmd,
      List<String> managedServerNames,
      int maxIterations) {
    LoggingFacade logger = getLogger();
    // first map all server names with false
    HashMap<String, Boolean> managedServers = new HashMap<>();
    managedServerNames.forEach(managedServerName ->
        managedServers.put(managedServerName, false)
    );

    logger.info("Calling webapp at most {0} times using command: {1}", maxIterations, curlCmd);

    // check the response contains managed server name
    ExecResult result = null;
    for (int i = 0; i < maxIterations; i++) {

      if (managedServers.containsValue(false)) {
        try {
          // sometimes the pod is not ready even the condition check is ready, sleep a little bit
          Thread.sleep(1000);
        } catch (InterruptedException ignore) {
          // ignore
        }

        try {
          result = ExecCommand.exec(curlCmd, true);

          String response = result.stdout().trim();
          logger.info("Response for iteration {0}: exitValue {1}, stdout {2}, stderr {3}",
              i, result.exitValue(), response, result.stderr());
          managedServers.keySet().forEach(key -> {
            if (response.contains(key)) {
              managedServers.put(key, true);
            }
          });
        } catch (Exception e) {
          logger.info("Got exception while running command: {0}", curlCmd);
          logger.info(e.toString());
          if (result != null) {
            logger.info("result.stdout: \n{0}", result.stdout());
            logger.info("result.stderr: \n{0}", result.stderr());
          }
          return false;
        }
      } else {
        return true;
      }
    }

    // after the max iterations, if hit here, then the sample app can not be accessed from at least one server
    // log the sample app accessibility information and return false
    managedServers.forEach((key, value) -> {
      if (value) {
        logger.info("The sample app can be accessed from the server {0}", key);
      } else {
        logger.info("FAILURE: The sample app can not be accessed from the server {0}", key);
      }
    });

    return false;
  }
/**
   * Call the curl command and check the app can be reached from all managed servers.
   *
   * @param curlCmd curl command to call the sample app
   * @param managedServerNames managed server names that the sample app response should return
   * @param maxIterations max iterations to call the curl command
   * @return true if the web app can hit all managed servers, false otherwise
   */
Call the curl command and check the app can be reached from all managed servers.
@param curlCmd curl command to call the sample app
@param managedServerNames managed server names that the sample app response should return
@param maxIterations max iterations to call the curl command
@return true if the web app can hit all managed servers, false otherwise
Call the curl command and check the app can be reached from all managed servers . @param curlCmd curl command to call the sample app @param managedServerNames managed server names that the sample app response should return @param maxIterations max iterations to call the curl command @return true if the web app can hit all managed servers false otherwise
public static boolean callWebAppAndCheckForServerNameInResponse(
      String curlCmd,
      List<String> managedServerNames,
      int maxIterations) {
    LoggingFacade logger = getLogger();
    HashMap<String, Boolean> managedServers = new HashMap<>();
    managedServerNames.forEach(managedServerName ->
        managedServers.put(managedServerName, false)
    );
    logger.info("Calling webapp at most {0} times using command: {1}", maxIterations, curlCmd);
    ExecResult result = null;
    for (int i = 0; i < maxIterations; i++) {
      if (managedServers.containsValue(false)) {
        try {
          Thread.sleep(1000);
        } catch (InterruptedException ignore) {
        }
        try {
          result = ExecCommand.exec(curlCmd, true);
          String response = result.stdout().trim();
          logger.info("Response for iteration {0}: exitValue {1}, stdout {2}, stderr {3}",
              i, result.exitValue(), response, result.stderr());
          managedServers.keySet().forEach(key -> {
            if (response.contains(key)) {
              managedServers.put(key, true);
            }
          });
        } catch (Exception e) {
          logger.info("Got exception while running command: {0}", curlCmd);
          logger.info(e.toString());
          if (result != null) {
            logger.info("result.stdout: \n{0}", result.stdout());
            logger.info("result.stderr: \n{0}", result.stderr());
          }
          return false;
        }
      } else {
        return true;
      }
    }
    managedServers.forEach((key, value) -> {
      if (value) {
        logger.info("The sample app can be accessed from the server {0}", key);
      } else {
        logger.info("FAILURE: The sample app can not be accessed from the server {0}", key);
      }
    });
    return false;
  }
public static boolean callWebAppAndCheckForServerNameInResponse ( String curlCmd , List < String > managedServerNames , int maxIterations ) { LoggingFacade logger = getLogger ( ) ; HashMap < String , Boolean > managedServers = new HashMap < > ( ) ; managedServerNames . forEach ( managedServerName -> managedServers . put ( managedServerName , false ) ) ; logger . info ( "Calling webapp at most {0} times using command: {1}" , maxIterations , curlCmd ) ; ExecResult result = null ; for ( int i = 0 ; i < maxIterations ; i ++ ) { if ( managedServers . containsValue ( false ) ) { try { Thread . sleep ( 1000 ) ; } catch ( InterruptedException ignore ) { } try { result = ExecCommand . exec ( curlCmd , true ) ; String response = result . stdout ( ) . trim ( ) ; logger . info ( "Response for iteration {0}: exitValue {1}, stdout {2}, stderr {3}" , i , result . exitValue ( ) , response , result . stderr ( ) ) ; managedServers . keySet ( ) . forEach ( key -> { if ( response . contains ( key ) ) { managedServers . put ( key , true ) ; } } ) ; } catch ( Exception e ) { logger . info ( "Got exception while running command: {0}" , curlCmd ) ; logger . info ( e . toString ( ) ) ; if ( result != null ) { logger . info ( "result.stdout: \n{0}" , result . stdout ( ) ) ; logger . info ( "result.stderr: \n{0}" , result . stderr ( ) ) ; } return false ; } } else { return true ; } } managedServers . forEach ( ( key , value ) -> { if ( value ) { logger . info ( "The sample app can be accessed from the server {0}" , key ) ; } else { logger . info ( "FAILURE: The sample app can not be accessed from the server {0}" , key ) ; } } ) ; return false ; }
Call the curl command and check the app can be reached from all managed servers.
Call the curl command and check the app can be reached from all managed servers .
// first map all server names with false // check the response contains managed server name // sometimes the pod is not ready even the condition check is ready, sleep a little bit // ignore // after the max iterations, if hit here, then the sample app can not be accessed from at least one server // log the sample app accessibility information and return false