@Test(timeout = 5000) public void testRaceCondition() throws InterruptedException { int parties = 2; final AtomicInteger barrierGenerations = new AtomicInteger(); final CyclicBarrier barrier = new CyclicBarrier(parties, new Runnable() { @Override public void run() { int generation = barrierGenerations.incrementAndGet(); } }); final ArrayBlockingQueue<Throwable> caught = new ArrayBlockingQueue<>(1); final AtomicBoolean running = new AtomicBoolean(true); long endBy = System.currentTimeMillis() + 5000; for (int i = 0; i < parties; i++) { new CyclicBarrierThread(barrier, caught, running, endBy).start(); } assertEquals("Failed to add new SpanSink, concurrent add", caught.poll(5000, TimeUnit.MILLISECONDS).getMessage()); int sinks = ImmutableList.copyOf(SpanSinkRegistry.getSpanSinks()).size(); int totalAdds = barrierGenerations.get() * 2; assertTrue(sinks + " < " + totalAdds + "?", totalAdds > sinks); }
public static Iterable<SpanSink> getSpanSinks() { return spanSinks.get(); }
SpanSinkRegistry { public static Iterable<SpanSink> getSpanSinks() { return spanSinks.get(); } }
SpanSinkRegistry { public static Iterable<SpanSink> getSpanSinks() { return spanSinks.get(); }  }
SpanSinkRegistry { public static Iterable<SpanSink> getSpanSinks() { return spanSinks.get(); }  static void register(SpanSink sink); static Iterable<SpanSink> getSpanSinks(); static void clear(); }
SpanSinkRegistry { public static Iterable<SpanSink> getSpanSinks() { return spanSinks.get(); }  static void register(SpanSink sink); static Iterable<SpanSink> getSpanSinks(); static void clear();  }