test/hotspot/jtreg/containers/docker/TestJcmdWithSideCar.java
changeset 58550 e98509cb3867
parent 57954 fd09c637dedb
child 58679 9c3209ff7550
equal deleted inserted replaced
58549:9d9317fad3fe 58550:e98509cb3867
    54 
    54 
    55 
    55 
    56 public class TestJcmdWithSideCar {
    56 public class TestJcmdWithSideCar {
    57     private static final String IMAGE_NAME = Common.imageName("jfr-jcmd");
    57     private static final String IMAGE_NAME = Common.imageName("jfr-jcmd");
    58     private static final int TIME_TO_RUN_MAIN_PROCESS = (int) (30 * Utils.TIMEOUT_FACTOR); // seconds
    58     private static final int TIME_TO_RUN_MAIN_PROCESS = (int) (30 * Utils.TIMEOUT_FACTOR); // seconds
    59     private static final long TIME_TO_WAIT_FOR_MAIN_METHOD_START = 5 * 1000; // milliseconds
    59     private static final long TIME_TO_WAIT_FOR_MAIN_METHOD_START = 50 * 1000; // milliseconds
    60     private static final String MAIN_CONTAINER_NAME = "test-container-main";
    60     private static final String MAIN_CONTAINER_NAME = "test-container-main";
    61 
    61 
    62     public static void main(String[] args) throws Exception {
    62     public static void main(String[] args) throws Exception {
    63         if (!DockerTestUtils.canTestDocker()) {
    63         if (!DockerTestUtils.canTestDocker()) {
    64             return;
    64             return;
   196                 .addDockerOpts("--name", MAIN_CONTAINER_NAME)
   196                 .addDockerOpts("--name", MAIN_CONTAINER_NAME)
   197                 .addDockerOpts("--volume", "/tmp")
   197                 .addDockerOpts("--volume", "/tmp")
   198                 .addDockerOpts("--volume", Paths.get(".").toAbsolutePath() + ":/workdir/")
   198                 .addDockerOpts("--volume", Paths.get(".").toAbsolutePath() + ":/workdir/")
   199                 .addJavaOpts("-XX:+UsePerfData")
   199                 .addJavaOpts("-XX:+UsePerfData")
   200                 .addClassOptions("" + TIME_TO_RUN_MAIN_PROCESS);
   200                 .addClassOptions("" + TIME_TO_RUN_MAIN_PROCESS);
       
   201             // avoid large Xmx
       
   202             opts.appendTestJavaOptions = false;
   201 
   203 
   202             List<String> cmd = DockerTestUtils.buildJavaCommand(opts);
   204             List<String> cmd = DockerTestUtils.buildJavaCommand(opts);
   203             ProcessBuilder pb = new ProcessBuilder(cmd);
   205             ProcessBuilder pb = new ProcessBuilder(cmd);
   204             p = ProcessTools.startProcess("main-container-process",
   206             p = ProcessTools.startProcess("main-container-process",
   205                                           pb,
   207                                           pb,
   230         public void waitFor(long timeout) throws Exception {
   232         public void waitFor(long timeout) throws Exception {
   231             p.waitFor(timeout, TimeUnit.MILLISECONDS);
   233             p.waitFor(timeout, TimeUnit.MILLISECONDS);
   232         }
   234         }
   233 
   235 
   234         public void waitForAndCheck(long timeout) throws Exception {
   236         public void waitForAndCheck(long timeout) throws Exception {
   235             waitFor(timeout);
   237             int exitValue = -1;
   236             if (p.exitValue() != 0) {
   238             int retryCount = 3;
   237                 throw new RuntimeException("DockerThread stopped unexpectedly");
   239 
       
   240             do {
       
   241                 waitFor(timeout);
       
   242                 try {
       
   243                     exitValue = p.exitValue();
       
   244                 } catch(IllegalThreadStateException ex) {
       
   245                     System.out.println("IllegalThreadStateException occured when calling exitValue()");
       
   246                     retryCount--;
       
   247                 }
       
   248             } while (exitValue == -1 && retryCount > 0);
       
   249 
       
   250             if (exitValue != 0) {
       
   251                 throw new RuntimeException("DockerThread stopped unexpectedly, non-zero exit value is " + exitValue);
   238             }
   252             }
   239         }
   253         }
   240 
   254 
   241     }
   255     }
   242 
   256