SourceForge: dvbcentral/dvbcentral: changeset 306:b55a50cea7c5
Synchronizing before adding the listener, so no events are missed
authorJaroslav Tulach <jtulach@netbeans.org>
Fri Apr 10 10:34:29 2009 +0200 (7 months ago)
changeset 306b55a50cea7c5
parent 305c0cfc54db1bc
child 307ea28fbdb74e7
Synchronizing before adding the listener, so no events are missed
dispatch/test/unit/src/net/sf/dvbcentral/dispatch/StreamingTest.java
     1.1 --- a/dispatch/test/unit/src/net/sf/dvbcentral/dispatch/StreamingTest.java	Fri Apr 10 10:00:03 2009 +0200
     1.2 +++ b/dispatch/test/unit/src/net/sf/dvbcentral/dispatch/StreamingTest.java	Fri Apr 10 10:34:29 2009 +0200
     1.3 @@ -90,26 +90,21 @@
     1.4  
     1.5      public void testRandomSequenceOfReads() throws Exception {
     1.6          frontend.useRandom(System.currentTimeMillis());
     1.7 -        
     1.8 -        dispatch.addDispatchListener(1, this);
     1.9          checkLoop();
    1.10      }
    1.11      public void testRandomSequenceOfReadsWith1151835179020() throws Exception {
    1.12          frontend.useRandom(1151835179020L);
    1.13 -        
    1.14 -        dispatch.addDispatchListener(1, this);
    1.15          checkLoop();
    1.16      }
    1.17  
    1.18 -    private void checkLoop() throws Exception {
    1.19 +    private synchronized void checkLoop() throws Exception {
    1.20 +        dispatch.addDispatchListener(1, this);
    1.21  
    1.22          while (expectingCnt < 10000) {
    1.23 -            synchronized (this) {
    1.24 -                long before = System.currentTimeMillis();
    1.25 -                wait(5000);
    1.26 -                if (System.currentTimeMillis() - before > 4500) {
    1.27 -                    fail("Too long waiting and only cnt: " + expectingCnt);
    1.28 -                }
    1.29 +            long before = System.currentTimeMillis();
    1.30 +            wait(5000);
    1.31 +            if (System.currentTimeMillis() - before > 4500) {
    1.32 +                fail("Too long waiting and only cnt: " + expectingCnt);
    1.33              }
    1.34              
    1.35              if (err != null) {
    1.36 @@ -133,7 +128,7 @@
    1.37      }
    1.38      
    1.39      
    1.40 -    public void dispatchPacket(DispatchEvent ev) {
    1.41 +    public synchronized void dispatchPacket(DispatchEvent ev) {
    1.42          assertEquals("188 units", 188, ev.getBuffer().remaining());
    1.43      
    1.44          for (int i = 0; i < 188; i++) {
    1.45 @@ -156,10 +151,7 @@
    1.46          }
    1.47          
    1.48          expectingCnt++;
    1.49 -        
    1.50 -        synchronized (this) {
    1.51 -            notifyAll();
    1.52 -        }
    1.53 +        notifyAll();
    1.54          Thread.yield();
    1.55      }
    1.56