test/jdk/jdk/jfr/api/consumer/recordingstream/TestRemove.java
branchJEP-349-branch
changeset 58271 e47423f1318b
parent 58076 ca625d28c580
equal deleted inserted replaced
58259:b6efcf2217f1 58271:e47423f1318b
    54         testRemoveOnClose();
    54         testRemoveOnClose();
    55         testRemoveOnEvent();
    55         testRemoveOnEvent();
    56     }
    56     }
    57 
    57 
    58     private static void testRemoveNull() {
    58     private static void testRemoveNull() {
       
    59         log("Entering testRemoveNull()");
    59         try (RecordingStream rs = new RecordingStream()) {
    60         try (RecordingStream rs = new RecordingStream()) {
    60            try {
    61            try {
    61                rs.remove(null);
    62                rs.remove(null);
    62                throw new AssertionError("Expected NullPointerException from remove(null");
    63                throw new AssertionError("Expected NullPointerException from remove(null");
    63            } catch (NullPointerException npe) {
    64            } catch (NullPointerException npe) {
    64                // OK; as expected
    65                // OK; as expected
    65            }
    66            }
    66         }
    67         }
       
    68         log("Leaving testRemoveNull()");
    67      }
    69      }
    68 
    70 
    69     private static void testRemoveOnEvent() throws Exception {
    71     private static void testRemoveOnEvent() throws Exception {
       
    72         log("Entering testRemoveOnEvent()");
    70         try (RecordingStream rs = new RecordingStream()) {
    73         try (RecordingStream rs = new RecordingStream()) {
    71             AtomicInteger counter = new AtomicInteger(0);
    74             AtomicInteger counter = new AtomicInteger(0);
    72             CountDownLatch events = new CountDownLatch(2);
    75             CountDownLatch events = new CountDownLatch(2);
    73             Consumer<RecordedEvent> c1 = e -> {
    76             Consumer<RecordedEvent> c1 = e -> {
    74                 counter.incrementAndGet();
    77                 counter.incrementAndGet();
    89             events.await();
    92             events.await();
    90             if (counter.get() > 0) {
    93             if (counter.get() > 0) {
    91                 throw new AssertionError("OnEvent handler not removed!");
    94                 throw new AssertionError("OnEvent handler not removed!");
    92             }
    95             }
    93         }
    96         }
       
    97         log("Leaving testRemoveOnEvent()");
    94     }
    98     }
    95 
    99 
    96     private static void testRemoveOnClose() {
   100     private static void testRemoveOnClose() {
       
   101         log("Entering testRemoveOnClose()");
    97         try (RecordingStream rs = new RecordingStream()) {
   102         try (RecordingStream rs = new RecordingStream()) {
    98             AtomicBoolean onClose = new AtomicBoolean(false);
   103             AtomicBoolean onClose = new AtomicBoolean(false);
    99             Runnable r = () -> {
   104             Runnable r = () -> {
   100                 onClose.set(true);
   105                 onClose.set(true);
   101             };
   106             };
   104             rs.close();
   109             rs.close();
   105             if (onClose.get()) {
   110             if (onClose.get()) {
   106                 throw new AssertionError("onClose handler not removed!");
   111                 throw new AssertionError("onClose handler not removed!");
   107             }
   112             }
   108         }
   113         }
       
   114         log("Leaving testRemoveOnClose()");
   109     }
   115     }
   110 
   116 
   111     private static void testRemoveOnFlush() throws Exception {
   117     private static void testRemoveOnFlush() throws Exception {
       
   118         log("Entering testRemoveOnFlush()");
   112         try (RecordingStream rs = new RecordingStream()) {
   119         try (RecordingStream rs = new RecordingStream()) {
   113             AtomicInteger flushCount = new AtomicInteger(2);
   120             AtomicInteger flushCount = new AtomicInteger(2);
   114             AtomicBoolean removeExecuted = new AtomicBoolean(false);
   121             AtomicBoolean removeExecuted = new AtomicBoolean(false);
   115             Runnable onFlush1 = () -> {
   122             Runnable onFlush1 = () -> {
   116                 removeExecuted.set(true);
   123                 removeExecuted.set(true);
   131 
   138 
   132             if (removeExecuted.get()) {
   139             if (removeExecuted.get()) {
   133                 throw new AssertionError("onFlush handler not removed!");
   140                 throw new AssertionError("onFlush handler not removed!");
   134             }
   141             }
   135         }
   142         }
       
   143         log("Leaving testRemoveOnFlush()");
       
   144     }
       
   145 
       
   146     private static void log(String msg) {
       
   147         System.out.println(msg);
   136     }
   148     }
   137 }
   149 }