samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java
changeset 108 a420a1124988
child 133 50bf1b976c0d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java	Sat Jun 14 09:54:32 2008 +0200
     1.3 @@ -0,0 +1,57 @@
     1.4 +package org.apidesign.deadlock.logs;
     1.5 +
     1.6 +import java.util.logging.Handler;
     1.7 +import java.util.logging.Level;
     1.8 +import java.util.logging.LogRecord;
     1.9 +import java.util.logging.Logger;
    1.10 +import org.junit.After;
    1.11 +import org.junit.AfterClass;
    1.12 +import org.junit.Before;
    1.13 +import org.junit.BeforeClass;
    1.14 +import org.junit.Test;
    1.15 +import org.netbeans.junit.NbTestCase;
    1.16 +import static org.junit.Assert.*;
    1.17 +
    1.18 +// BEGIN: test.parallel.test.sorted
    1.19 +public class ParallelSortedTest extends NbTestCase {
    1.20 +    public ParallelSortedTest(String testName) {
    1.21 +        super(testName);
    1.22 +    }
    1.23 +
    1.24 +    @Override
    1.25 +    protected Level logLevel() {
    1.26 +        return Level.WARNING;
    1.27 +    }
    1.28 +
    1.29 +    public void testMain() throws Exception {
    1.30 +        Logger.global.addHandler(new BlockingHandler());
    1.31 +        Parael.main(null);
    1.32 +        fail("Ok, just print the logged output");
    1.33 +    }
    1.34 +
    1.35 +    private static final class BlockingHandler extends Handler {
    1.36 +
    1.37 +        boolean runSecond;
    1.38 +
    1.39 +        public synchronized void publish(LogRecord record) {
    1.40 +            if (!record.getMessage().startsWith("cnt")) {
    1.41 +                return;
    1.42 +            }
    1.43 +            if (runSecond == Thread.currentThread().getName().equals("2nd")) {
    1.44 +                notify();
    1.45 +                runSecond = !runSecond;
    1.46 +            }
    1.47 +            try {
    1.48 +                wait(500);
    1.49 +            } catch (InterruptedException ex) {
    1.50 +            }
    1.51 +        }
    1.52 +
    1.53 +        public void flush() {
    1.54 +        }
    1.55 +
    1.56 +        public void close() {
    1.57 +        }
    1.58 +    }
    1.59 +}
    1.60 +// END: test.parallel.test.sorted