jdk/test/java/lang/ProcessHandle/OnExitTest.java
changeset 45717 83b617bc344a
parent 45565 337fbe6632c2
equal deleted inserted replaced
45716:4e40b6e09064 45717:83b617bc344a
    40 
    40 
    41 /*
    41 /*
    42  * @test
    42  * @test
    43  * @key intermittent
    43  * @key intermittent
    44  * @library /test/lib
    44  * @library /test/lib
    45  * @modules java.base/jdk.internal.misc
       
    46  *          jdk.management
       
    47  * @build jdk.test.lib.Utils
    45  * @build jdk.test.lib.Utils
    48  *        jdk.test.lib.Asserts
       
    49  *        jdk.test.lib.JDKToolFinder
       
    50  *        jdk.test.lib.JDKToolLauncher
       
    51  *        jdk.test.lib.Platform
       
    52  *        jdk.test.lib.process.*
       
    53  * @run testng OnExitTest
    46  * @run testng OnExitTest
    54  * @summary Functions of Process.onExit and ProcessHandle.onExit
    47  * @summary Functions of Process.onExit and ProcessHandle.onExit
    55  * @author Roger Riggs
    48  * @author Roger Riggs
    56  */
    49  */
    57 
    50 
   249                 } catch (InterruptedException ie) {
   242                 } catch (InterruptedException ie) {
   250                     Assert.fail("interrupted", ie);
   243                     Assert.fail("interrupted", ie);
   251                 }
   244                 }
   252                 Assert.assertNull(line, "waitpid didn't wait");
   245                 Assert.assertNull(line, "waitpid didn't wait");
   253 
   246 
       
   247                 A.toHandle().onExit().thenAccept(p -> {
       
   248                     System.out.printf(" A.toHandle().onExit().A info: %s, now: %s%n",
       
   249                             p.info(), Instant.now());
       
   250                 });
       
   251 
       
   252                 A.onExit().thenAccept(p -> {
       
   253                     System.out.printf(" A.onExit().A info: %s, now: %s%n",
       
   254                             p.info(), Instant.now());
       
   255                 });
       
   256 
       
   257                 ProcessHandle.Info A_info = A.info();
       
   258 
   254                 A.sendAction("exit", 0L);
   259                 A.sendAction("exit", 0L);
   255 
   260 
   256                 // Look for B to report that A has exited
   261                 // Look for B to report that A has exited
   257                 do {
   262                 do {
       
   263                     Instant start = Instant.now();
       
   264                     while (blines.isEmpty() && A.isAlive()) {
       
   265                         A_info = A.info(); // Spin
       
   266                     }
       
   267                     Instant end = Instant.now();
       
   268                     System.out.printf(" a.isAlive: %s, a.info: %s, @%s%n", A.isAlive(), A.info(),
       
   269                             Duration.between(start, end));
       
   270 
   258                     split = getSplitLine(blines);
   271                     split = getSplitLine(blines);
   259                 } while (!"waitpid".equals(split[1]));
   272                 } while (!"waitpid".equals(split[1]));
   260 
   273 
   261                 Assert.assertEquals(split[2], "false",  "Process A should not be alive");
   274                 Assert.assertEquals(split[2], "false",  "Process A should not be alive");
   262 
   275