new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSessionMigration.java
@Test
  @DisplayName("Stop the primary server, verify that a new primary server is picked and HTTP session state is migrated")
  @Slow
  @MustNotRunInParallel
  public void testSessionMigration() {
    final String primaryServerAttr = "primary";
    final String secondaryServerAttr = "secondary";
    final String sessionCreateTimeAttr = "sessioncreatetime";
    final String countAttr = "count";
    final String webServiceSetUrl = SESSMIGR_APP_WAR_NAME + "/?setCounter=" + SESSION_STATE;
    final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter";
    String serverName = managedServerPrefix + "1";

    // send a HTTP request to set http session state(count number) and save HTTP session info
    // before shutting down the primary server
    Map<String, String> httpDataInfo =
        getServerAndSessionInfoAndVerify(serverName, webServiceSetUrl, " -D ");
    // get server and session info from web service deployed on the cluster
    String origPrimaryServerName = httpDataInfo.get(primaryServerAttr);
    String origSecondaryServerName = httpDataInfo.get(secondaryServerAttr);
    String origSessionCreateTime = httpDataInfo.get(sessionCreateTimeAttr);
    logger.info("Got the primary server {0}, the secondary server {1} "
        + "and session create time {2} before shutting down the primary server",
            origPrimaryServerName, origSecondaryServerName, origSessionCreateTime);

    // stop the primary server by changing ServerStartPolicy to NEVER and patching domain
    logger.info("Shut down the primary server {0}", origPrimaryServerName);
    shutdownServerUsingServerStartPolicy(origPrimaryServerName);

    // send a HTTP request to get server and session info after shutting down the primary server
    serverName = domainUid + "-" + origSecondaryServerName;
    httpDataInfo =
      getServerAndSessionInfoAndVerify(serverName, webServiceGetUrl, " -b ");
    // get server and session info from web service deployed on the cluster
    String primaryServerName = httpDataInfo.get(primaryServerAttr);
    String sessionCreateTime = httpDataInfo.get(sessionCreateTimeAttr);
    String countStr = httpDataInfo.get(countAttr);
    int count = Optional.ofNullable(countStr).map(Ints::tryParse).orElse(0);
    logger.info("After patching the domain, the primary server changes to {0} "
        + ", session create time {1} and session state {2}",
            primaryServerName, sessionCreateTime, countStr);

    // verify that a new primary server is picked and HTTP session state is migrated
    assertAll("Check that WebLogic server and session vars is not null or empty",
        () -> assertNotEquals(origPrimaryServerName, primaryServerName,
            "After the primary server stopped, another server should become the new primary server"),
        () -> assertEquals(origSessionCreateTime, sessionCreateTime,
            "After the primary server stopped, HTTP session state should be migrated to the new primary server"),
        () -> assertEquals(count, SESSION_STATE,
            "After the primary server stopped, HTTP session state should be migrated to the new primary server")
    );

    logger.info("SUCCESS --- testSessionMigration \nThe new primary server is {0}, it was {1}. "
        + "\nThe session state was set to {2}, it is migrated to the new primary server.",
            primaryServerName, origPrimaryServerName, SESSION_STATE);
  }
/**
   * The test sends a HTTP request to set http session state(count number), get the primary and secondary server name,
   * session create time and session state and from the util method and save HTTP session info,
   * then stop the primary server by changing ServerStartPolicy to NEVER and patching domain.
   * Send another HTTP request to get http session state (count number), primary server and
   * session create time. Verify that a new primary server is selected and HTTP session state is migrated.
   */
The test sends a HTTP request to set http session state(count number), get the primary and secondary server name,
session create time and session state and from the util method and save HTTP session info,
then stop the primary server by changing ServerStartPolicy to NEVER and patching domain.
Send another HTTP request to get http session state (count number), primary server and
session create time. Verify that a new primary server is selected and HTTP session state is migrated.
The test sends a HTTP request to set http session state ( count number ) get the primary and secondary server name session create time and session state and from the util method and save HTTP session info then stop the primary server by changing ServerStartPolicy to NEVER and patching domain . Send another HTTP request to get http session state ( count number ) primary server and session create time . Verify that a new primary server is selected and HTTP session state is migrated .
@Test
  @DisplayName("Stop the primary server, verify that a new primary server is picked and HTTP session state is migrated")
  @Slow
  @MustNotRunInParallel
  public void testSessionMigration() {
    final String primaryServerAttr = "primary";
    final String secondaryServerAttr = "secondary";
    final String sessionCreateTimeAttr = "sessioncreatetime";
    final String countAttr = "count";
    final String webServiceSetUrl = SESSMIGR_APP_WAR_NAME + "/?setCounter=" + SESSION_STATE;
    final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter";
    String serverName = managedServerPrefix + "1";
    Map<String, String> httpDataInfo =
        getServerAndSessionInfoAndVerify(serverName, webServiceSetUrl, " -D ");
    String origPrimaryServerName = httpDataInfo.get(primaryServerAttr);
    String origSecondaryServerName = httpDataInfo.get(secondaryServerAttr);
    String origSessionCreateTime = httpDataInfo.get(sessionCreateTimeAttr);
    logger.info("Got the primary server {0}, the secondary server {1} "
        + "and session create time {2} before shutting down the primary server",
            origPrimaryServerName, origSecondaryServerName, origSessionCreateTime);
    logger.info("Shut down the primary server {0}", origPrimaryServerName);
    shutdownServerUsingServerStartPolicy(origPrimaryServerName);
    serverName = domainUid + "-" + origSecondaryServerName;
    httpDataInfo =
      getServerAndSessionInfoAndVerify(serverName, webServiceGetUrl, " -b ");
    String primaryServerName = httpDataInfo.get(primaryServerAttr);
    String sessionCreateTime = httpDataInfo.get(sessionCreateTimeAttr);
    String countStr = httpDataInfo.get(countAttr);
    int count = Optional.ofNullable(countStr).map(Ints::tryParse).orElse(0);
    logger.info("After patching the domain, the primary server changes to {0} "
        + ", session create time {1} and session state {2}",
            primaryServerName, sessionCreateTime, countStr);
    assertAll("Check that WebLogic server and session vars is not null or empty",
        () -> assertNotEquals(origPrimaryServerName, primaryServerName,
            "After the primary server stopped, another server should become the new primary server"),
        () -> assertEquals(origSessionCreateTime, sessionCreateTime,
            "After the primary server stopped, HTTP session state should be migrated to the new primary server"),
        () -> assertEquals(count, SESSION_STATE,
            "After the primary server stopped, HTTP session state should be migrated to the new primary server")
    );
    logger.info("SUCCESS --- testSessionMigration \nThe new primary server is {0}, it was {1}. "
        + "\nThe session state was set to {2}, it is migrated to the new primary server.",
            primaryServerName, origPrimaryServerName, SESSION_STATE);
  }
@ Test @ DisplayName ( "Stop the primary server, verify that a new primary server is picked and HTTP session state is migrated" ) @ Slow @ MustNotRunInParallel public void testSessionMigration ( ) { final String primaryServerAttr = "primary" ; final String secondaryServerAttr = "secondary" ; final String sessionCreateTimeAttr = "sessioncreatetime" ; final String countAttr = "count" ; final String webServiceSetUrl = SESSMIGR_APP_WAR_NAME + "/?setCounter=" + SESSION_STATE ; final String webServiceGetUrl = SESSMIGR_APP_WAR_NAME + "/?getCounter" ; String serverName = managedServerPrefix + "1" ; Map < String , String > httpDataInfo = getServerAndSessionInfoAndVerify ( serverName , webServiceSetUrl , " -D " ) ; String origPrimaryServerName = httpDataInfo . get ( primaryServerAttr ) ; String origSecondaryServerName = httpDataInfo . get ( secondaryServerAttr ) ; String origSessionCreateTime = httpDataInfo . get ( sessionCreateTimeAttr ) ; logger . info ( "Got the primary server {0}, the secondary server {1} " + "and session create time {2} before shutting down the primary server" , origPrimaryServerName , origSecondaryServerName , origSessionCreateTime ) ; logger . info ( "Shut down the primary server {0}" , origPrimaryServerName ) ; shutdownServerUsingServerStartPolicy ( origPrimaryServerName ) ; serverName = domainUid + "-" + origSecondaryServerName ; httpDataInfo = getServerAndSessionInfoAndVerify ( serverName , webServiceGetUrl , " -b " ) ; String primaryServerName = httpDataInfo . get ( primaryServerAttr ) ; String sessionCreateTime = httpDataInfo . get ( sessionCreateTimeAttr ) ; String countStr = httpDataInfo . get ( countAttr ) ; int count = Optional . ofNullable ( countStr ) . map ( Ints :: tryParse ) . orElse ( 0 ) ; logger . info ( "After patching the domain, the primary server changes to {0} " + ", session create time {1} and session state {2}" , primaryServerName , sessionCreateTime , countStr ) ; assertAll ( "Check that WebLogic server and session vars is not null or empty" , ( ) -> assertNotEquals ( origPrimaryServerName , primaryServerName , "After the primary server stopped, another server should become the new primary server" ) , ( ) -> assertEquals ( origSessionCreateTime , sessionCreateTime , "After the primary server stopped, HTTP session state should be migrated to the new primary server" ) , ( ) -> assertEquals ( count , SESSION_STATE , "After the primary server stopped, HTTP session state should be migrated to the new primary server" ) ) ; logger . info ( "SUCCESS --- testSessionMigration \nThe new primary server is {0}, it was {1}. " + "\nThe session state was set to {2}, it is migrated to the new primary server." , primaryServerName , origPrimaryServerName , SESSION_STATE ) ; }
The test sends a HTTP request to set http session state(count number), get the primary and secondary server name,
 session create time and session state and from the util method and save HTTP session info,
 then stop the primary server by changing ServerStartPolicy to NEVER and patching domain.
The test sends a HTTP request to set http session state ( count number ) get the primary and secondary server name session create time and session state and from the util method and save HTTP session info then stop the primary server by changing ServerStartPolicy to NEVER and patching domain .
// send a HTTP request to set http session state(count number) and save HTTP session info // before shutting down the primary server // get server and session info from web service deployed on the cluster // stop the primary server by changing ServerStartPolicy to NEVER and patching domain // send a HTTP request to get server and session info after shutting down the primary server // get server and session info from web service deployed on the cluster // verify that a new primary server is picked and HTTP session state is migrated