samples/deadlock/test/org/apidesign/javamonitorflaws/CacheTest.java
changeset 409 40cabcdcd2be
parent 317 e101649dbd17
     1.1 --- a/samples/deadlock/test/org/apidesign/javamonitorflaws/CacheTest.java	Wed Feb 11 08:52:00 2009 +0100
     1.2 +++ b/samples/deadlock/test/org/apidesign/javamonitorflaws/CacheTest.java	Thu Oct 30 21:30:10 2014 +0100
     1.3 @@ -5,8 +5,6 @@
     1.4  import org.netbeans.junit.NbTestCase;
     1.5  
     1.6  public class CacheTest extends NbTestCase {
     1.7 -    private MultiplyCache cache = new MultiplyCache();
     1.8 -
     1.9      public CacheTest(String n) {
    1.10          super(n);
    1.11      }
    1.12 @@ -48,6 +46,8 @@
    1.13      public void testDeadlockWithSetter() throws Exception {
    1.14          if (Boolean.getBoolean("no.failures")) return;
    1.15          
    1.16 +        final CacheToTest cache = new MultiplyCache();
    1.17 +
    1.18          class ToDeadlock implements Runnable, PropertyChangeListener {
    1.19              int value;
    1.20  
    1.21 @@ -98,10 +98,14 @@
    1.22    org.apidesign.javamonitorflaws.CacheTest$2ToDeadlock.run:90
    1.23    java.lang.Thread.run:619
    1.24       */
    1.25 -    // BEGIN: monitor.pitfalls.block.propertychange
    1.26      public void testDeadlockViaAPI() throws Exception {
    1.27          if (Boolean.getBoolean("no.failures")) return;
    1.28 -        
    1.29 +        testDeadlockViaAPI(new MultiplyCache());
    1.30 +    }
    1.31 +
    1.32 +    // BEGIN: monitor.pitfalls.block.propertychange
    1.33 +    private static void testDeadlockViaAPI(final CacheToTest cache)
    1.34 +    throws Exception {
    1.35          class ToDeadlock implements Runnable, PropertyChangeListener {
    1.36              int lastMultiply;
    1.37  
    1.38 @@ -139,4 +143,17 @@
    1.39          // END: monitor.pitfalls.brokencall
    1.40      }
    1.41      // END: monitor.pitfalls.block.propertychange
    1.42 +
    1.43 +    public void testDeadlockViaAPIWithCacheOK() throws Exception {
    1.44 +        testDeadlockViaAPI(new MultiplyCacheOK());
    1.45 +    }
    1.46 +
    1.47 +    static interface CacheToTest {
    1.48 +        public Integer get(String key);
    1.49 +
    1.50 +        public void setMultiply(int m);
    1.51 +        public int getMultiply();
    1.52 +        public void addPropertyChangeListener(PropertyChangeListener l);
    1.53 +        public void removePropertyChangeListener(PropertyChangeListener l);
    1.54 +    }
    1.55  }
    1.56 \ No newline at end of file