[concurrency-interest] Java Concurrency torture tests: need your help

Dr Heinz M. Kabutz heinz at javaspecialists.eu
Wed Nov 7 17:21:05 EST 2012


Here's another one you can add to your test :-)

import org.junit.*;

import static org.junit.Assert.*;

public class InterruptedVisibilityTest {
    public void think() {
        while (true) {
            if (checkInterruptedStatus()) break;
        }
        System.out.println("We're done thinking");
    }

    private boolean checkInterruptedStatus() {
        return Thread.currentThread().isInterrupted();
    }

    @Test
    public void testInterruptedVisibility() throws InterruptedException {
        final InterruptedVisibilityTest test =
                new InterruptedVisibilityTest();
        Thread thinkerThread = new Thread("Thinker") {
            public void run() {
                test.think();
            }
        };
        thinkerThread.start();
        Thread.sleep(500);
        thinkerThread.interrupt();
        thinkerThread.join(500);
        if (thinkerThread.isAlive()) {
            System.err.println("Thinker did not shut down within 500ms");
            System.err.println("Error in Java Virtual Machine!");
            assertTrue(thinkerThread.isInterrupted());
            System.err.println("Interrupted: " + 
thinkerThread.isInterrupted());
            System.err.println();
            System.err.println("(Let's see if the thread ever dies and 
how long it takes)");
            fail("Thread did not respond to interruption");
        }
    }
}

Regards

Heinz
-- 
Dr Heinz M. Kabutz (PhD CompSci)
Author of "The Java(tm) Specialists' Newsletter"
Sun Java Champion
IEEE Certified Software Development Professional
http://www.javaspecialists.eu
Tel: +30 69 75 595 262
Skype: kabutz 



On 10/19/12 10:32 AM, Aleksey Shipilev wrote:
> Hi guys,
>
> Following up on May discussion on volatile bug [1], I had started the
> project to collect the suite of concurrency tests which are to expose
> concurrency bugs [2], hopefully much more thoroughly than JCK and other
> targeted tests do.
>
> It had been going for a while, and so far it tests only the basic things
> about primitives, arrays, making the infamous singleton tests, etc. etc.
> My plan is hook up this suite for OpenJDK nightly testing, so don't
> forget make a pull requests for your changes ;)
>
> Here's the call for action! I would appreciate your contributions,
> including but not limited to:
>
>   a) reviewing the test correctness. Doug had been lightly supervising
> this before, but "given enough eyeballs all bugs are shallow". Please
> reference the exact github revision when referencing the test.
>
>   b) running the suite on interesting hardware. Even though the tests
> are scarce, I would be happy to see the results from J9/PPC and various
> ARM implementations. There are couple of negative tests against legal
> races (i.e. UnsafeDCLSingletonTest), it will be comforting to see they
> fail expectedly on non-x86 hardware. If you do run the tests, please zip
> up the results/ folder and post it somewhere.
>
>   c) brainstorming the coverage area: what areas are missing (there are
> lots!), and what should be covered in the first place.
>
>   d) proposing basic testcases and/or pointing out known regression
> tests assorted over the Internet which should be included into the suite.
>
>   e) raising the general suggestions about usability, reliability,
> methodology, etc.
>
> Will appreciate your help!
>
> Thanks,
> Aleksey.
>
> [1] http://cs.oswego.edu/pipermail/concurrency-interest/2012-May/009440.html
> [2] https://github.com/shipilev/java-concurrency-torture
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>   


More information about the Concurrency-interest mailing list