test/jdk/jdk/jfr/api/consumer/streaming/TestRepositoryMigration.java
branchJEP-349-branch
changeset 57984 269bbe414580
parent 57754 5693904ecbde
child 58076 ca625d28c580
equal deleted inserted replaced
57983:a57907813a83 57984:269bbe414580
    26         int id;
    26         int id;
    27     }
    27     }
    28 
    28 
    29     public static void main(String... args) throws Exception {
    29     public static void main(String... args) throws Exception {
    30         Path newRepository = Paths.get("new-repository");
    30         Path newRepository = Paths.get("new-repository");
    31         CountDownLatch events = new CountDownLatch(2);
    31         CountDownLatch event1 = new CountDownLatch(1);
       
    32         CountDownLatch event2 = new CountDownLatch(1);
       
    33 
    32         try (EventStream es = EventStream.openRepository()) {
    34         try (EventStream es = EventStream.openRepository()) {
    33             es.setStartTime(Instant.EPOCH);
    35             es.setStartTime(Instant.EPOCH);
    34             es.onEvent(e -> {
    36             es.onEvent(e -> {
    35                 System.out.println(e);
    37                 System.out.println(e);
    36                 if (e.getInt("id") == 1) {
    38                 if (e.getInt("id") == 1) {
    37                     events.countDown();
    39                     event1.countDown();
    38                 }
    40                 }
    39                 if (e.getInt("id") == 2) {
    41                 if (e.getInt("id") == 2) {
    40                     events.countDown();
    42                     event2.countDown();
    41                 }
    43                 }
    42             });
    44             });
    43             es.startAsync();
    45             es.startAsync();
    44             try (Recording r = new Recording()) {
    46             try (Recording r = new Recording()) {
    45                 r.setFlushInterval(Duration.ofSeconds(1));
    47                 r.setFlushInterval(Duration.ofSeconds(1));
    46                 r.start();
    48                 r.start();
    47                 // Chunk in default repository
    49                 // Chunk in default repository
    48                 MigrationEvent e1 = new MigrationEvent();
    50                 MigrationEvent e1 = new MigrationEvent();
    49                 e1.id = 1;
    51                 e1.id = 1;
    50                 e1.commit();
    52                 e1.commit();
    51                JcmdHelper.jcmd("JFR.configure", "repositorypath=" + newRepository.toAbsolutePath());
    53                 event1.await();
       
    54                 JcmdHelper.jcmd("JFR.configure", "repositorypath=" + newRepository.toAbsolutePath());
    52                 // Chunk in new repository
    55                 // Chunk in new repository
    53                 MigrationEvent e2 = new MigrationEvent();
    56                 MigrationEvent e2 = new MigrationEvent();
    54                 e2.id = 2;
    57                 e2.id = 2;
    55                 e2.commit();
    58                 e2.commit();
    56                 r.stop();
    59                 r.stop();
    57                 events.await();
    60                 event2.await();
    58                 // Verify that it happened in new repository
    61                 // Verify that it happened in new repository
    59                 if (!Files.exists(newRepository)) {
    62                 if (!Files.exists(newRepository)) {
    60                     throw new AssertionError("Could not find repository " + newRepository);
    63                     throw new AssertionError("Could not find repository " + newRepository);
    61                 }
    64                 }
    62                 System.out.println("Listing contents in new repository:");
    65                 System.out.println("Listing contents in new repository:");
    63                 boolean empty= true;
    66                 boolean empty = true;
    64                 for (Path p: Files.newDirectoryStream(newRepository)) {
    67                 for (Path p : Files.newDirectoryStream(newRepository)) {
    65                     System.out.println(p.toAbsolutePath());
    68                     System.out.println(p.toAbsolutePath());
    66                     empty = false;
    69                     empty = false;
    67                 }
    70                 }
    68                 System.out.println();
    71                 System.out.println();
    69                 if (empty) {
    72                 if (empty) {