Add One More Check To Test Twenty Threads

This is part of JavaUnitTestChallengeSolved. -- DonWells


When I saw that the one put and ten take test had failed, I thought that this test should also have failed. I am thinking that perhaps it has to do with the threads dying after 5 inputs or outputs. So I can just go ahead and change the take threads so that they all stay alive during the whole test.

 public class TwentyThreadsTogether extends Test {
    public BoundedBuffer buffer;
    public PutThread putThreads [];
    public TakeThread takeThreads [];

public void setUp(){ buffer = new BoundedBuffer(); putThreads = new PutThread [10]; takeThreads = new TakeThread [10]; for (int each = 0; each < 10; each++) { putThreads[each] = new PutThread(buffer); takeThreads[each] = new TakeThread(buffer, 50);};}

public void tearDown(){ TakeThread.dumpOutput();}

public void runTest (){ TakeThread.resetOutput(); for (int each = 0; each < 10; each++) { takeThreads[each].start();}; for (int each = 0; each < 10; each++) { putThreads[each].start();}; waitForPutToFinish(); sleepHalfSecond(); should(TakeThread.outputLength() == 50, "output was too short"); should(TakeThread.doesOuputHaveTenOf("a"), "should get ten a"); should(TakeThread.doesOuputHaveTenOf("b"), "should get ten b"); should(TakeThread.doesOuputHaveTenOf("c"), "should get ten c"); should(TakeThread.doesOuputHaveTenOf("d"), "should get ten d"); should(TakeThread.doesOuputHaveTenOf("e"), "should get ten e");}

public void waitForPutToFinish(){ try { for (int each = 0; each < 10; each++) { putThreads[each].join(4000);}} catch (InterruptedException exception) {};}

}
This test fails now.

Interesting thing though. Sometimes it fails in a different way. Every so often it completely deadlocks.

And every so often it will in fact pass.

What I can do for this is ExtendTheJavaTestFrameworkForNondeterminism.


CategoryJava


EditText of this page (last edited June 18, 2004) or FindPage with title or text search