samples/deadlock/test/org/apidesign/deadlock/logs/ParallelSortedTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:54:32 +0200
changeset 108 a420a1124988
child 133 50bf1b976c0d
permissions -rw-r--r--
Enough of logging, Jesse will anyway advice to delete this part
jtulach@108
     1
package org.apidesign.deadlock.logs;
jtulach@108
     2
jtulach@108
     3
import java.util.logging.Handler;
jtulach@108
     4
import java.util.logging.Level;
jtulach@108
     5
import java.util.logging.LogRecord;
jtulach@108
     6
import java.util.logging.Logger;
jtulach@108
     7
import org.junit.After;
jtulach@108
     8
import org.junit.AfterClass;
jtulach@108
     9
import org.junit.Before;
jtulach@108
    10
import org.junit.BeforeClass;
jtulach@108
    11
import org.junit.Test;
jtulach@108
    12
import org.netbeans.junit.NbTestCase;
jtulach@108
    13
import static org.junit.Assert.*;
jtulach@108
    14
jtulach@108
    15
// BEGIN: test.parallel.test.sorted
jtulach@108
    16
public class ParallelSortedTest extends NbTestCase {
jtulach@108
    17
    public ParallelSortedTest(String testName) {
jtulach@108
    18
        super(testName);
jtulach@108
    19
    }
jtulach@108
    20
jtulach@108
    21
    @Override
jtulach@108
    22
    protected Level logLevel() {
jtulach@108
    23
        return Level.WARNING;
jtulach@108
    24
    }
jtulach@108
    25
jtulach@108
    26
    public void testMain() throws Exception {
jtulach@108
    27
        Logger.global.addHandler(new BlockingHandler());
jtulach@108
    28
        Parael.main(null);
jtulach@108
    29
        fail("Ok, just print the logged output");
jtulach@108
    30
    }
jtulach@108
    31
jtulach@108
    32
    private static final class BlockingHandler extends Handler {
jtulach@108
    33
jtulach@108
    34
        boolean runSecond;
jtulach@108
    35
jtulach@108
    36
        public synchronized void publish(LogRecord record) {
jtulach@108
    37
            if (!record.getMessage().startsWith("cnt")) {
jtulach@108
    38
                return;
jtulach@108
    39
            }
jtulach@108
    40
            if (runSecond == Thread.currentThread().getName().equals("2nd")) {
jtulach@108
    41
                notify();
jtulach@108
    42
                runSecond = !runSecond;
jtulach@108
    43
            }
jtulach@108
    44
            try {
jtulach@108
    45
                wait(500);
jtulach@108
    46
            } catch (InterruptedException ex) {
jtulach@108
    47
            }
jtulach@108
    48
        }
jtulach@108
    49
jtulach@108
    50
        public void flush() {
jtulach@108
    51
        }
jtulach@108
    52
jtulach@108
    53
        public void close() {
jtulach@108
    54
        }
jtulach@108
    55
    }
jtulach@108
    56
}
jtulach@108
    57
// END: test.parallel.test.sorted