|
29 | 29 | import java.nio.file.Path;
|
30 | 30 | import java.time.Duration;
|
31 | 31 | import java.time.Instant;
|
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.List; |
32 | 34 | import java.util.Set;
|
| 35 | +import java.util.concurrent.CopyOnWriteArrayList; |
33 | 36 | import java.util.concurrent.atomic.AtomicInteger;
|
34 | 37 |
|
| 38 | +import jdk.jfr.AnnotationElement; |
35 | 39 | import jdk.jfr.Enabled;
|
36 | 40 | import jdk.jfr.Event;
|
| 41 | +import jdk.jfr.EventFactory; |
| 42 | +import jdk.jfr.Name; |
37 | 43 | import jdk.jfr.Recording;
|
38 | 44 | import jdk.jfr.SettingControl;
|
39 | 45 | import jdk.jfr.SettingDefinition;
|
@@ -132,6 +138,7 @@ public static void main(String[] args) throws Exception {
|
132 | 138 | testThrottleThresholded();
|
133 | 139 | testThrottleNormalRate();
|
134 | 140 | testThrottleUserdefined();
|
| 141 | + testThrottleDynamic(); |
135 | 142 | }
|
136 | 143 |
|
137 | 144 | private static void testUnthrottled() throws Exception {
|
@@ -232,6 +239,40 @@ private static void testThrottleUserdefined(String test, String throttle, boolea
|
232 | 239 | }
|
233 | 240 | }
|
234 | 241 |
|
| 242 | + private static void testThrottleDynamic() throws Exception { |
| 243 | + List<AnnotationElement> offAnnotations = new ArrayList<>(); |
| 244 | + offAnnotations.add(new AnnotationElement(Name.class, "DynamicZero")); |
| 245 | + offAnnotations.add(new AnnotationElement(Throttle.class, "0/s")); |
| 246 | + EventFactory offFactory = EventFactory.create(offAnnotations, List.of()); |
| 247 | + |
| 248 | + List<AnnotationElement> highRateAnnotations = new ArrayList<>(); |
| 249 | + highRateAnnotations.add(new AnnotationElement(Name.class, "DynamicHighRate")); |
| 250 | + highRateAnnotations.add(new AnnotationElement(Throttle.class, "1000/s")); |
| 251 | + EventFactory highRateFactory = EventFactory.create(highRateAnnotations, List.of()); |
| 252 | + |
| 253 | + List<RecordedEvent> events = new CopyOnWriteArrayList<>(); |
| 254 | + try (RecordingStream r = new RecordingStream()) { |
| 255 | + r.enable("DynamicZero"); |
| 256 | + r.enable("DynamicHighRate"); |
| 257 | + r.onEvent(events::add); |
| 258 | + r.startAsync(); |
| 259 | + Event offEvent = offFactory.newEvent(); |
| 260 | + offEvent.commit(); |
| 261 | + Event highRateEvent = highRateFactory.newEvent(); |
| 262 | + highRateEvent.begin(); |
| 263 | + highRateEvent.commit(); |
| 264 | + r.stop(); |
| 265 | + if (events.size() != 1) { |
| 266 | + System.out.println(events); |
| 267 | + throw new Exception("Expected one dynamic event"); |
| 268 | + } |
| 269 | + if (!events.get(0).getEventType().getName().equals("DynamicHighRate")) { |
| 270 | + System.out.println(events); |
| 271 | + throw new Exception("Expected DynamicHighRate"); |
| 272 | + } |
| 273 | + } |
| 274 | + } |
| 275 | + |
235 | 276 | @SuppressWarnings("unchecked")
|
236 | 277 | private static void testEvent(Class<? extends Event> eventClass, boolean shouldCommit) throws Exception {
|
237 | 278 | try (Recording r = new Recording()) {
|
@@ -272,6 +313,8 @@ private static void testEvent(Class<? extends Event> eventClass, boolean shouldC
|
272 | 313 | }
|
273 | 314 | if (shouldCommit) {
|
274 | 315 | assertEvents(r, eventClass.getName(), 17 + 50 + 11);
|
| 316 | + } else { |
| 317 | + assertEvents(r, eventClass.getName(), 0); |
275 | 318 | }
|
276 | 319 | }
|
277 | 320 | }
|
|
0 commit comments