31 import java.util.concurrent.atomic.AtomicInteger; |
31 import java.util.concurrent.atomic.AtomicInteger; |
32 |
32 |
33 import jdk.jfr.consumer.EventStream; |
33 import jdk.jfr.consumer.EventStream; |
34 import jdk.test.lib.dcmd.CommandExecutor; |
34 import jdk.test.lib.dcmd.CommandExecutor; |
35 import jdk.test.lib.dcmd.PidJcmdExecutor; |
35 import jdk.test.lib.dcmd.PidJcmdExecutor; |
36 import jdk.test.lib.process.OutputAnalyzer; |
|
37 |
36 |
38 /** |
37 /** |
39 * @test |
38 * @test |
40 * @summary Verifies that a out-of-process stream is closed when the repository |
39 * @summary Verifies that a out-of-process stream is closed when the repository |
41 * is changed. |
40 * is changed. |
45 * @modules jdk.jfr jdk.attach java.base/jdk.internal.misc |
44 * @modules jdk.jfr jdk.attach java.base/jdk.internal.misc |
46 * @run main/othervm jdk.jfr.api.consumer.streaming.TestOutOfProcessMigration |
45 * @run main/othervm jdk.jfr.api.consumer.streaming.TestOutOfProcessMigration |
47 */ |
46 */ |
48 public class TestOutOfProcessMigration { |
47 public class TestOutOfProcessMigration { |
49 public static void main(String... args) throws Exception { |
48 public static void main(String... args) throws Exception { |
50 Path newRepo = Paths.get("new-repository").toAbsolutePath(); |
49 try (TestProcess process = new TestProcess("application")) { |
51 |
50 AtomicInteger eventCounter = new AtomicInteger(); |
52 TestProcess process = new TestProcess("application"); |
51 Path newRepo = Paths.get("new-repository").toAbsolutePath(); |
53 AtomicInteger eventCounter = new AtomicInteger(); |
52 try (EventStream es = EventStream.openRepository(process.getRepository())) { |
54 try (EventStream es = EventStream.openRepository(process.getRepository())) { |
53 // Start from first event in repository |
55 // Start from first event in repository |
54 es.setStartTime(Instant.EPOCH); |
56 es.setStartTime(Instant.EPOCH); |
55 es.onEvent(e -> { |
57 es.onEvent(e -> { |
56 if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) { |
58 if (eventCounter.incrementAndGet() == TestProcess.NUMBER_OF_EVENTS) { |
57 System.out.println("Changing repository to " + newRepo + " ..."); |
59 System.out.println("Changing repository to " + newRepo + " ..."); |
58 CommandExecutor executor = new PidJcmdExecutor(String.valueOf(process.pid())); |
60 CommandExecutor executor = new PidJcmdExecutor(String.valueOf(process.pid())); |
59 // This should close stream |
61 // This should close stream |
60 executor.execute("JFR.configure repositorypath=" + newRepo); |
62 OutputAnalyzer oa = executor.execute("JFR.configure repositorypath=" + newRepo); |
61 } |
63 System.out.println(oa); |
62 }); |
64 } |
63 es.start(); |
65 }); |
64 process.exit(); |
66 es.start(); |
65 // Wait for process to die, so files are cleaned up |
|
66 process.awaitDeath(); |
|
67 } |
67 } |
68 } |
68 } |
69 } |
69 } |
70 } |