test/jdk/jdk/jfr/api/consumer/streaming/TestJVMCrash.java
changeset 59246 fcad92f425c5
parent 59226 a0f39cc47387
equal deleted inserted replaced
59245:de882051f7a5 59246:fcad92f425c5
    40  *
    40  *
    41  * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMCrash
    41  * @run main/othervm jdk.jfr.api.consumer.streaming.TestJVMCrash
    42  */
    42  */
    43 public class TestJVMCrash {
    43 public class TestJVMCrash {
    44 
    44 
    45     public static void main(String... args) throws Exception {
    45     public static void main(String... args) throws Exception  {
    46         int id = 1;
    46         int id = 1;
    47         while (true) {
    47         while (true) {
    48             TestProcess process = new TestProcess("crash-application-" + id++);
    48             try (TestProcess process = new TestProcess("crash-application-" + id++))  {
    49             AtomicInteger eventCounter = new AtomicInteger();
    49                 AtomicInteger eventCounter = new AtomicInteger();
    50             try (EventStream es = EventStream.openRepository(process.getRepository())) {
    50                 try (EventStream es = EventStream.openRepository(process.getRepository())) {
    51                 // Start from first event in repository
    51                     // Start from first event in repository
    52                 es.setStartTime(Instant.EPOCH);
    52                     es.setStartTime(Instant.EPOCH);
    53                 es.onEvent(e -> {
    53                     es.onEvent(e -> {
    54                     if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) {
    54                         if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) {
    55                         process.crash();
    55                             process.crash();
       
    56                         }
       
    57                     });
       
    58                     es.startAsync();
       
    59                     // If crash corrupts chunk in repository, retry in 30 seconds
       
    60                     es.awaitTermination(Duration.ofSeconds(30));
       
    61                     if (eventCounter.get() == TestProcess.NUMBER_OF_EVENTS) {
       
    62                         return;
    56                     }
    63                     }
    57                 });
    64                     System.out.println("Incorrect event count. Retrying...");
    58                 es.startAsync();
       
    59                 // If crash corrupts chunk in repository, retry in 30 seconds
       
    60                 es.awaitTermination(Duration.ofSeconds(30));
       
    61                 if (eventCounter.get() == TestProcess.NUMBER_OF_EVENTS) {
       
    62                     return;
       
    63                 }
    65                 }
    64                 System.out.println("Incorrect event count. Retrying...");
       
    65             }
    66             }
    66         }
    67         }
    67     }
    68     }
    68 }
    69 }