new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItDomainInPV.java
@Test
  @Order(2)
  @DisplayName("Test liveness probe of Pod")
  public void testLivenessProbe() {
    Assumptions.assumeTrue(previousTestSuccessful);
    String serverName = wdtDomainUid + "-" + wdtManagedServerNameBase + "1";
    // create file to kill server process
    File killServerScript = assertDoesNotThrow(() ->
            createScriptToKillServer(),
        "Failed to create script to kill server");
    logger.info("File/script created to kill server {0}", killServerScript);

    checkPodReady(serverName, wdtDomainUid, wdtDomainNamespace);

    // copy script to pod
    String destLocation = "/u01/killserver.sh";
    assertDoesNotThrow(() -> copyFileToPod(wdtDomainNamespace, serverName, "weblogic-server",
        killServerScript.toPath(), Paths.get(destLocation)),
        String.format("Failed to copy file %s to pod %s in namespace %s",
            killServerScript, serverName, wdtDomainNamespace));
    logger.info("File copied to Pod {0} in namespace {1}", serverName, wdtDomainNamespace);

    // get the restart count of the container in pod before liveness probe restarts
    final int beforeRestartCount =
        assertDoesNotThrow(() -> getContainerRestartCount(wdtDomainNamespace, null, serverName, null),
            String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
                serverName, wdtDomainNamespace));
    logger.info("Restart count before liveness probe {0}", beforeRestartCount);
    // change file permissions
    ExecResult execResult = assertDoesNotThrow(() -> execCommand(wdtDomainNamespace, serverName, null,
        true, "/bin/sh", "-c", "chmod +x " + destLocation),
        String.format("Failed to change permissions for file %s in pod %s", destLocation, serverName));
    assertTrue(execResult.exitValue() == 0,
        String.format("Failed to change file %s permissions, stderr %s stdout %s", destLocation,
            execResult.stderr(), execResult.stdout()));
    logger.info("File permissions changed inside pod");
    /* First, kill the mgd server process in the container three times to cause the node manager to
     * mark the server 'failed not restartable'. This in turn is detected by the liveness probe, which
     * initiates a container restart.
     */
    for (int i = 0; i < 3; i++) {
      execResult = assertDoesNotThrow(() -> execCommand(wdtDomainNamespace, serverName, null,
          true, "/bin/sh", "-c", destLocation + " " + serverName),
          String.format("Failed to execute script %s in pod %s namespace %s", destLocation,
              serverName, wdtDomainNamespace));
      logger.info("Command executed to kill server inside pod, exit value {0}, stdout {1}, stderr {2}",
          execResult.exitValue(), execResult.stdout(), execResult.stderr());

      try {
        Thread.sleep(2 * 1000);
      } catch (InterruptedException ie) {
        // ignore
      }
    }
    // check pod is ready
    checkPodReady(serverName, wdtDomainUid, wdtDomainNamespace);

    // get the restart count of the container in pod after liveness probe restarts
    int afterRestartCount = assertDoesNotThrow(() ->
            getContainerRestartCount(wdtDomainNamespace, null, serverName, null),
        String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
            serverName, wdtDomainNamespace));
    assertTrue(afterRestartCount - beforeRestartCount == 1,
        String.format("Liveness probe did not start the container in pod {0} in namespace {1}",
            serverName, wdtDomainNamespace));

    //access application in managed servers through NGINX load balancer
    assertThat(callWebAppAndCheckForServerNameInResponse(wdtCurlRequest, wdtDomainManagedServers, 20))
        .as("Verify NGINX can access the test web app from all managed servers in the domain")
        .withFailMessage("NGINX can not access the test web app from one or more of the managed servers")
        .isTrue();

  }
/**
   * Verify liveness probe by killing managed server process 3 times to kick
   * pod container auto-restart.
   */
Verify liveness probe by killing managed server process 3 times to kick
pod container auto-restart.
Verify liveness probe by killing managed server process 3 times to kick pod container auto - restart .
@Test
  @Order(2)
  @DisplayName("Test liveness probe of Pod")
  public void testLivenessProbe() {
    Assumptions.assumeTrue(previousTestSuccessful);
    String serverName = wdtDomainUid + "-" + wdtManagedServerNameBase + "1";
    File killServerScript = assertDoesNotThrow(() ->
            createScriptToKillServer(),
        "Failed to create script to kill server");
    logger.info("File/script created to kill server {0}", killServerScript);
    checkPodReady(serverName, wdtDomainUid, wdtDomainNamespace);
    String destLocation = "/u01/killserver.sh";
    assertDoesNotThrow(() -> copyFileToPod(wdtDomainNamespace, serverName, "weblogic-server",
        killServerScript.toPath(), Paths.get(destLocation)),
        String.format("Failed to copy file %s to pod %s in namespace %s",
            killServerScript, serverName, wdtDomainNamespace));
    logger.info("File copied to Pod {0} in namespace {1}", serverName, wdtDomainNamespace);
    final int beforeRestartCount =
        assertDoesNotThrow(() -> getContainerRestartCount(wdtDomainNamespace, null, serverName, null),
            String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
                serverName, wdtDomainNamespace));
    logger.info("Restart count before liveness probe {0}", beforeRestartCount);
    ExecResult execResult = assertDoesNotThrow(() -> execCommand(wdtDomainNamespace, serverName, null,
        true, "/bin/sh", "-c", "chmod +x " + destLocation),
        String.format("Failed to change permissions for file %s in pod %s", destLocation, serverName));
    assertTrue(execResult.exitValue() == 0,
        String.format("Failed to change file %s permissions, stderr %s stdout %s", destLocation,
            execResult.stderr(), execResult.stdout()));
    logger.info("File permissions changed inside pod");
    /* First, kill the mgd server process in the container three times to cause the node manager to
     * mark the server 'failed not restartable'. This in turn is detected by the liveness probe, which
     * initiates a container restart.
     */
    for (int i = 0; i < 3; i++) {
      execResult = assertDoesNotThrow(() -> execCommand(wdtDomainNamespace, serverName, null,
          true, "/bin/sh", "-c", destLocation + " " + serverName),
          String.format("Failed to execute script %s in pod %s namespace %s", destLocation,
              serverName, wdtDomainNamespace));
      logger.info("Command executed to kill server inside pod, exit value {0}, stdout {1}, stderr {2}",
          execResult.exitValue(), execResult.stdout(), execResult.stderr());
      try {
        Thread.sleep(2 * 1000);
      } catch (InterruptedException ie) {
      }
    }
    checkPodReady(serverName, wdtDomainUid, wdtDomainNamespace);
    int afterRestartCount = assertDoesNotThrow(() ->
            getContainerRestartCount(wdtDomainNamespace, null, serverName, null),
        String.format("Failed to get the restart count of the container from pod {0} in namespace {1}",
            serverName, wdtDomainNamespace));
    assertTrue(afterRestartCount - beforeRestartCount == 1,
        String.format("Liveness probe did not start the container in pod {0} in namespace {1}",
            serverName, wdtDomainNamespace));
    assertThat(callWebAppAndCheckForServerNameInResponse(wdtCurlRequest, wdtDomainManagedServers, 20))
        .as("Verify NGINX can access the test web app from all managed servers in the domain")
        .withFailMessage("NGINX can not access the test web app from one or more of the managed servers")
        .isTrue();
  }
@ Test @ Order ( 2 ) @ DisplayName ( "Test liveness probe of Pod" ) public void testLivenessProbe ( ) { Assumptions . assumeTrue ( previousTestSuccessful ) ; String serverName = wdtDomainUid + "-" + wdtManagedServerNameBase + "1" ; File killServerScript = assertDoesNotThrow ( ( ) -> createScriptToKillServer ( ) , "Failed to create script to kill server" ) ; logger . info ( "File/script created to kill server {0}" , killServerScript ) ; checkPodReady ( serverName , wdtDomainUid , wdtDomainNamespace ) ; String destLocation = "/u01/killserver.sh" ; assertDoesNotThrow ( ( ) -> copyFileToPod ( wdtDomainNamespace , serverName , "weblogic-server" , killServerScript . toPath ( ) , Paths . get ( destLocation ) ) , String . format ( "Failed to copy file %s to pod %s in namespace %s" , killServerScript , serverName , wdtDomainNamespace ) ) ; logger . info ( "File copied to Pod {0} in namespace {1}" , serverName , wdtDomainNamespace ) ; final int beforeRestartCount = assertDoesNotThrow ( ( ) -> getContainerRestartCount ( wdtDomainNamespace , null , serverName , null ) , String . format ( "Failed to get the restart count of the container from pod {0} in namespace {1}" , serverName , wdtDomainNamespace ) ) ; logger . info ( "Restart count before liveness probe {0}" , beforeRestartCount ) ; ExecResult execResult = assertDoesNotThrow ( ( ) -> execCommand ( wdtDomainNamespace , serverName , null , true , "/bin/sh" , "-c" , "chmod +x " + destLocation ) , String . format ( "Failed to change permissions for file %s in pod %s" , destLocation , serverName ) ) ; assertTrue ( execResult . exitValue ( ) == 0 , String . format ( "Failed to change file %s permissions, stderr %s stdout %s" , destLocation , execResult . stderr ( ) , execResult . stdout ( ) ) ) ; logger . info ( "File permissions changed inside pod" ) ; /* First, kill the mgd server process in the container three times to cause the node manager to
     * mark the server 'failed not restartable'. This in turn is detected by the liveness probe, which
     * initiates a container restart.
     */ for ( int i = 0 ; i < 3 ; i ++ ) { execResult = assertDoesNotThrow ( ( ) -> execCommand ( wdtDomainNamespace , serverName , null , true , "/bin/sh" , "-c" , destLocation + " " + serverName ) , String . format ( "Failed to execute script %s in pod %s namespace %s" , destLocation , serverName , wdtDomainNamespace ) ) ; logger . info ( "Command executed to kill server inside pod, exit value {0}, stdout {1}, stderr {2}" , execResult . exitValue ( ) , execResult . stdout ( ) , execResult . stderr ( ) ) ; try { Thread . sleep ( 2 * 1000 ) ; } catch ( InterruptedException ie ) { } } checkPodReady ( serverName , wdtDomainUid , wdtDomainNamespace ) ; int afterRestartCount = assertDoesNotThrow ( ( ) -> getContainerRestartCount ( wdtDomainNamespace , null , serverName , null ) , String . format ( "Failed to get the restart count of the container from pod {0} in namespace {1}" , serverName , wdtDomainNamespace ) ) ; assertTrue ( afterRestartCount - beforeRestartCount == 1 , String . format ( "Liveness probe did not start the container in pod {0} in namespace {1}" , serverName , wdtDomainNamespace ) ) ; assertThat ( callWebAppAndCheckForServerNameInResponse ( wdtCurlRequest , wdtDomainManagedServers , 20 ) ) . as ( "Verify NGINX can access the test web app from all managed servers in the domain" ) . withFailMessage ( "NGINX can not access the test web app from one or more of the managed servers" ) . isTrue ( ) ; }
Verify liveness probe by killing managed server process 3 times to kick
 pod container auto-restart.
Verify liveness probe by killing managed server process 3 times to kick pod container auto - restart .
// create file to kill server process // copy script to pod // get the restart count of the container in pod before liveness probe restarts // change file permissions // ignore // check pod is ready // get the restart count of the container in pod after liveness probe restarts //access application in managed servers through NGINX load balancer