# HG changeset patch # User egahlin # Date 1571671425 -7200 # Node ID 038d13489b6cb8bf745fe090c742496ca644bbd1 # Parent 737134732b4af1cb20f64e528c6c8ff5a193be85 Harden TestChunkGap.java diff -r 737134732b4a -r 038d13489b6c test/jdk/jdk/jfr/api/consumer/streaming/TestChunkGap.java --- a/test/jdk/jdk/jfr/api/consumer/streaming/TestChunkGap.java Mon Oct 21 16:29:38 2019 +0200 +++ b/test/jdk/jdk/jfr/api/consumer/streaming/TestChunkGap.java Mon Oct 21 17:23:45 2019 +0200 @@ -27,6 +27,7 @@ import java.time.Instant; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; import jdk.jfr.Event; import jdk.jfr.Recording; @@ -52,32 +53,34 @@ static class EndEvent extends Event { } - static long count; + private final static AtomicInteger count = new AtomicInteger(0); public static void main(String... args) throws Exception { CountDownLatch gap = new CountDownLatch(1); + CountDownLatch receivedEvent = new CountDownLatch(1); + try (EventStream s = EventStream.openRepository()) { try (Recording r1 = new Recording()) { s.setStartTime(Instant.EPOCH); s.onEvent(e -> { System.out.println(e); + receivedEvent.countDown(); try { gap.await(); } catch (InterruptedException e1) { e1.printStackTrace(); } - count++; + count.incrementAndGet(); if (e.getEventType().getName().equals(EndEvent.class.getName())) { s.close(); } }); s.startAsync(); - - r1.enable(StartEvent.class); r1.start(); StartEvent event1 = new StartEvent(); event1.commit(); + receivedEvent.await(); r1.stop(); // create chunk that is removed @@ -97,7 +100,7 @@ r3.stop(); s.awaitTermination(); - if (count != 2) { + if (count.get() != 2) { throw new AssertionError("Expected 2 event, but got " + count); } }