changeset 57105:eb3e2a5c2bcd

8233870: JFR TestSetEndTime.java times out - onClose() is never called Reviewed-by: mgronlun
author egahlin
date Tue, 26 Nov 2019 17:00:57 +0100
parents 9170826a3d76
children f9905e7c96aa 3b1afeb49a20
files src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java
diffstat 3 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java	Tue Nov 26 15:21:37 2019 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkHeader.java	Tue Nov 26 17:00:57 2019 +0100
@@ -292,4 +292,8 @@
     static long headerSize() {
         return HEADER_SIZE;
     }
+
+    public long getLastNanos() {
+        return getStartNanos() + getDurationNanos();
+    }
 }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java	Tue Nov 26 15:21:37 2019 +0000
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/ChunkParser.java	Tue Nov 26 17:00:57 2019 +0100
@@ -202,7 +202,7 @@
             long lastValid = absoluteChunkEnd;
             long metadataPoistion = chunkHeader.getMetataPosition();
             long contantPosition = chunkHeader.getConstantPoolPosition();
-            chunkFinished = awaitUpdatedHeader(absoluteChunkEnd);
+            chunkFinished = awaitUpdatedHeader(absoluteChunkEnd, configuration.filterEnd);
             if (chunkFinished) {
                 Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "At chunk end");
                 return null;
@@ -279,11 +279,14 @@
         }
     }
 
-    private boolean awaitUpdatedHeader(long absoluteChunkEnd) throws IOException {
+    private boolean awaitUpdatedHeader(long absoluteChunkEnd, long filterEnd) throws IOException {
         if (Logger.shouldLog(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO)) {
             Logger.log(LogTag.JFR_SYSTEM_PARSER, LogLevel.INFO, "Waiting for more data (streaming). Read so far: " + chunkHeader.getChunkSize() + " bytes");
         }
         while (true) {
+            if (chunkHeader.getLastNanos() > filterEnd)  {
+              return true;
+            }
             chunkHeader.refresh();
             if (absoluteChunkEnd != chunkHeader.getEnd()) {
                 return false;
--- a/test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java	Tue Nov 26 15:21:37 2019 +0000
+++ b/test/jdk/jdk/jfr/api/consumer/recordingstream/TestSetEndTime.java	Tue Nov 26 17:00:57 2019 +0100
@@ -63,6 +63,14 @@
     public static void main(String... args) throws Exception {
         testEventStream();
         testRecordingStream();
+        testEmptyStream();
+    }
+
+    private static void testEmptyStream() {
+        try (RecordingStream rs = new RecordingStream()) {
+            rs.setEndTime(Instant.now().plusMillis(1100));
+            rs.start();
+        }
     }
 
     private static void testRecordingStream() throws Exception {
@@ -89,10 +97,10 @@
                 }
                 closed.await();
                 System.out.println("Found events: " + count.get());
-                if (count.get() < 50) {
+                if (count.get() > 0 && count.get() < 50) {
                     return;
                 }
-                System.out.println("Found 50 events. Retrying");
+                System.out.println("Retrying");
                 System.out.println();
             }
         }