Search in sources :

Example 1 with Blitzer

use of org.jmock.lib.concurrent.Blitzer in project storm by apache.

the class RankingsTest method updatingWithNewRankablesShouldBeThreadSafe.

@Test
public void updatingWithNewRankablesShouldBeThreadSafe() throws InterruptedException {
    // given
    final List<Rankable> entries = ImmutableList.of(A, B, C, D);
    final Rankings rankings = new Rankings(entries.size());
    // We are capturing exceptions thrown in Blitzer's child threads into this data structure so that we can properly
    // pass/fail this test.  The reason is that Blitzer doesn't report exceptions, which is a known bug in Blitzer
    // (JMOCK-263).  See https://github.com/jmock-developers/jmock-library/issues/22 for more information.
    final List<Exception> exceptions = Lists.newArrayList();
    Blitzer blitzer = new Blitzer(1000);
    // when
    blitzer.blitz(new Runnable() {

        public void run() {
            for (Rankable r : entries) {
                try {
                    rankings.updateWith(r);
                } catch (RuntimeException e) {
                    synchronized (exceptions) {
                        exceptions.add(e);
                    }
                }
            }
        }
    });
    blitzer.shutdown();
    //
    if (!exceptions.isEmpty()) {
        for (Exception e : exceptions) {
            System.err.println(Throwables.getStackTraceAsString(e));
        }
    }
    assertThat(exceptions).isEmpty();
}
Also used : Blitzer(org.jmock.lib.concurrent.Blitzer) Test(org.testng.annotations.Test)

Aggregations

Blitzer (org.jmock.lib.concurrent.Blitzer)1 Test (org.testng.annotations.Test)1