jtulach@108: package org.apidesign.deadlock.logs; jtulach@108: jtulach@108: import java.util.logging.Handler; jtulach@108: import java.util.logging.Level; jtulach@108: import java.util.logging.LogRecord; jtulach@108: import java.util.logging.Logger; jtulach@108: import org.junit.After; jtulach@108: import org.junit.AfterClass; jtulach@108: import org.junit.Before; jtulach@108: import org.junit.BeforeClass; jtulach@108: import org.junit.Test; jtulach@108: import org.netbeans.junit.NbTestCase; jtulach@108: import static org.junit.Assert.*; jtulach@108: jtulach@108: // BEGIN: test.parallel.test.sorted jtulach@108: public class ParallelSortedTest extends NbTestCase { jtulach@108: public ParallelSortedTest(String testName) { jtulach@108: super(testName); jtulach@108: } jtulach@108: jtulach@108: @Override jtulach@108: protected Level logLevel() { jtulach@108: return Level.WARNING; jtulach@108: } jtulach@108: jtulach@108: public void testMain() throws Exception { jtulach@108: Logger.global.addHandler(new BlockingHandler()); jtulach@210: Parallel.main(null); jtulach@108: fail("Ok, just print the logged output"); jtulach@108: } jtulach@108: jtulach@108: private static final class BlockingHandler extends Handler { jtulach@108: jtulach@108: boolean runSecond; jtulach@108: jtulach@108: public synchronized void publish(LogRecord record) { jtulach@108: if (!record.getMessage().startsWith("cnt")) { jtulach@108: return; jtulach@108: } jtulach@154: boolean snd = Thread.currentThread().getName().equals("2nd"); jtulach@154: if (runSecond == snd) { jtulach@108: notify(); jtulach@108: runSecond = !runSecond; jtulach@108: } jtulach@108: try { jtulach@108: wait(500); jtulach@108: } catch (InterruptedException ex) { jtulach@108: } jtulach@108: } jtulach@108: jtulach@108: public void flush() { jtulach@108: } jtulach@108: jtulach@108: public void close() { jtulach@108: } jtulach@108: } jtulach@108: } jtulach@108: // END: test.parallel.test.sorted