|
7 | 7 |
|
8 | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; |
9 | 9 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 10 | +import static org.junit.jupiter.api.Assertions.fail; |
10 | 11 | import static org.mockito.ArgumentMatchers.any; |
11 | 12 | import static org.mockito.ArgumentMatchers.anyString; |
12 | 13 | import static org.mockito.Mockito.mock; |
13 | 14 | import static org.mockito.Mockito.when; |
14 | 15 |
|
15 | 16 | import java.lang.management.ManagementFactory; |
| 17 | +import java.nio.file.Files; |
| 18 | +import java.nio.file.Path; |
16 | 19 | import javax.management.MBeanServer; |
17 | 20 | import javax.management.MBeanServerConnection; |
18 | 21 | import javax.management.ObjectName; |
@@ -73,6 +76,36 @@ void startRecordingParsesIdCorrectly() throws Exception { |
73 | 76 | assertEquals(id, 99); |
74 | 77 | } |
75 | 78 |
|
| 79 | + @Test |
| 80 | + void endToEndTest() throws Exception { |
| 81 | + |
| 82 | + MBeanServerConnection mBeanServer = ManagementFactory.getPlatformMBeanServer(); |
| 83 | + FlightRecorderConnection flightRecorderConnection = |
| 84 | + FlightRecorderDiagnosticCommandConnection.connect(mBeanServer); |
| 85 | + RecordingOptions recordingOptions = |
| 86 | + new RecordingOptions.Builder().disk("true").duration("5s").build(); |
| 87 | + RecordingConfiguration recordingConfiguration = RecordingConfiguration.PROFILE_CONFIGURATION; |
| 88 | + Path tempFile = Files.createTempFile("recording", ".jfr"); |
| 89 | + |
| 90 | + try (Recording recording = |
| 91 | + flightRecorderConnection.newRecording(recordingOptions, recordingConfiguration)) { |
| 92 | + |
| 93 | + recording.start(); |
| 94 | + try { |
| 95 | + Thread.sleep(1000); |
| 96 | + } catch (InterruptedException e) { |
| 97 | + Thread.currentThread().interrupt(); |
| 98 | + } |
| 99 | + recording.dump(tempFile.toString()); |
| 100 | + recording.stop(); |
| 101 | + } finally { |
| 102 | + if (!Files.exists(tempFile)) { |
| 103 | + fail("Recording file not found"); |
| 104 | + } |
| 105 | + Files.deleteIfExists(tempFile); |
| 106 | + } |
| 107 | + } |
| 108 | + |
76 | 109 | MBeanServerConnection mockMbeanServer( |
77 | 110 | ObjectName objectName, String vmCheckCommercialFeaturesResponse) throws Exception { |
78 | 111 | MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class); |
|
0 commit comments