# HG changeset patch # User Jaroslav Tulach # Date 1213430072 -7200 # Node ID a420a1124988403530e89474da69e702b99ac23f # Parent 907f5d8e343c320ae9d520e8cbd615a840ec5c9e Enough of logging, Jesse will anyway advice to delete this part diff -r 907f5d8e343c -r a420a1124988 samples/deadlock/src/org/apidesign/deadlock/LabelProvider.java --- a/samples/deadlock/src/org/apidesign/deadlock/LabelProvider.java Sat Jun 14 09:54:32 2008 +0200 +++ b/samples/deadlock/src/org/apidesign/deadlock/LabelProvider.java Sat Jun 14 09:54:32 2008 +0200 @@ -13,9 +13,11 @@ private HashSet allCreated = new HashSet(); public synchronized JLabel createLabel () { + // BEGIN: deadlock.logs LOG.log(Level.INFO, "Will create JLabel"); JLabel l = new JLabel (); LOG.log(Level.INFO, "Label created {0}", l); + // END: deadlock.logs allCreated.add (l); return l; } diff -r 907f5d8e343c -r a420a1124988 samples/deadlock/src/org/apidesign/deadlock/logs/Parallel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/deadlock/src/org/apidesign/deadlock/logs/Parallel.java Sat Jun 14 09:54:32 2008 +0200 @@ -0,0 +1,25 @@ +package org.apidesign.deadlock.logs; + +import java.util.Random; +import java.util.logging.Level; +import java.util.logging.Logger; + +// BEGIN: test.parallel +class Parael implements Runnable { + public void run() { + Random r = new Random(); + for (int i = 0; i < 10; i++) { + try { + Thread.sleep(r.nextInt(100)); + } catch (InterruptedException ex) {} + Logger.global.log(Level.WARNING, "cnt: {0}", new Integer(i)); + } + } + public static void main(String[] args) throws InterruptedException { + Thread t1 = new Thread(new Parael(), "1st"); + Thread t2 = new Thread(new Parael(), "2nd"); + t1.start(); t2.start(); + t1.join(); t2.join(); + } +} +// END: test.parallel diff -r 907f5d8e343c -r a420a1124988 samples/deadlock/test/org/apidesign/deadlock/logs/ParallelControlFlowTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelControlFlowTest.java Sat Jun 14 09:54:32 2008 +0200 @@ -0,0 +1,69 @@ +package org.apidesign.deadlock.logs; + +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.netbeans.junit.NbTestCase; +import static org.junit.Assert.*; + +public class ParallelControlFlowTest extends NbTestCase { + public ParallelControlFlowTest(String testName) { + super(testName); + } + + @Override + protected Level logLevel() { + return Level.WARNING; + } + +// BEGIN: test.parallel.test.controlflow + public void testMain() throws Exception { + org.netbeans.junit.Log.controlFlow(Logger.global, null, + "THREAD: 1st MSG: cnt: 0" + + "THREAD: 2nd MSG: .*0" + + "THREAD: 1st MSG: ...: 1" + + "THREAD: 2nd MSG: cnt: 1" + + "THREAD: 1st MSG: cnt: 2" + + "THREAD: 2nd MSG: cnt: 2" + + "THREAD: 1st MSG: cnt: 3" + + "THREAD: 2nd MSG: cnt: 3" + + "THREAD: 1st MSG: cnt: 4" + + "THREAD: 2nd MSG: cnt: 4" + + "THREAD: 1st MSG: cnt: 5" + + "THREAD: 2nd MSG: cnt: 5" + + "THREAD: 1st MSG: cnt: 6" + + "THREAD: 2nd MSG: cnt: 6" + + "THREAD: 1st MSG: cnt: 7" + + "THREAD: 2nd MSG: cnt: 7" + + "THREAD: 1st MSG: cnt: 8" + + "THREAD: 2nd MSG: cnt: 8" + + "THREAD: 1st MSG: cnt: 9" + + "THREAD: 2nd MSG: cnt: 9", + 500 + ); + Parael.main(null); + fail("Ok, just print the logged output"); + } +// END: test.parallel.test.controlflow + + + // BEGIN: test.parallel.test.fivetwo + public void testFiveAndThenTwo() throws Exception { + org.netbeans.junit.Log.controlFlow(Logger.global, null, + "THREAD: 1st MSG: cnt: 5" + + "THREAD: 2nd MSG: cnt: 2" + + "THREAD: 1st MSG: cnt: 6", + 5000 + ); + Parael.main(null); + fail("Ok, just print the logged output"); + } + // END: test.parallel.test.fivetwo + +} diff -r 907f5d8e343c -r a420a1124988 samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java Sat Jun 14 09:54:32 2008 +0200 @@ -0,0 +1,57 @@ +package org.apidesign.deadlock.logs; + +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.netbeans.junit.NbTestCase; +import static org.junit.Assert.*; + +// BEGIN: test.parallel.test.sorted +public class ParallelSortedTest extends NbTestCase { + public ParallelSortedTest(String testName) { + super(testName); + } + + @Override + protected Level logLevel() { + return Level.WARNING; + } + + public void testMain() throws Exception { + Logger.global.addHandler(new BlockingHandler()); + Parael.main(null); + fail("Ok, just print the logged output"); + } + + private static final class BlockingHandler extends Handler { + + boolean runSecond; + + public synchronized void publish(LogRecord record) { + if (!record.getMessage().startsWith("cnt")) { + return; + } + if (runSecond == Thread.currentThread().getName().equals("2nd")) { + notify(); + runSecond = !runSecond; + } + try { + wait(500); + } catch (InterruptedException ex) { + } + } + + public void flush() { + } + + public void close() { + } + } +} +// END: test.parallel.test.sorted diff -r 907f5d8e343c -r a420a1124988 samples/deadlock/test/org/apidesign/deadlock/logs/ParallelTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelTest.java Sat Jun 14 09:54:32 2008 +0200 @@ -0,0 +1,28 @@ +package org.apidesign.deadlock.logs; + +import java.util.logging.Level; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.netbeans.junit.NbTestCase; +import static org.junit.Assert.*; + +// BEGIN: test.parallel.test +public class ParallelTest extends NbTestCase { + public ParallelTest(String testName) { + super(testName); + } + + @Override + protected Level logLevel() { + return Level.WARNING; + } + + public void testMain() throws Exception { + Parael.main(null); + fail("Ok, just print logged messages"); + } +} +// END: test.parallel.test