You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by mh...@apache.org on 2007/01/27 20:26:26 UTC

svn commit: r500596 - /mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java

Author: mheath
Date: Sat Jan 27 11:26:26 2007
New Revision: 500596

URL: http://svn.apache.org/viewvc?view=rev&rev=500596
Log:
Added open callback test.

Modified:
    mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java

Modified: mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java
URL: http://svn.apache.org/viewvc/mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java?view=diff&rev=500596&r1=500595&r2=500596
==============================================================================
--- mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java (original)
+++ mina/sandbox/mheath/aioj/trunk/src/test/java/org/apache/aio/concurrent/TestOpen.java Sat Jan 27 11:26:26 2007
@@ -3,18 +3,19 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Semaphore;
 
+import org.apache.aio.AioCompletionHandler;
 import org.apache.aio.AioFuture;
 import org.apache.aio.AsynchronousFileChannel;
 import org.apache.aio.AsynchronousFileChannelFactory;
 import org.apache.aio.Modes;
 import org.testng.AssertJUnit;
-import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
 public class TestOpen {
 
-    @Test(groups={"concurrent"})
+    @Test(groups={"concurrent", "open"})
     public void openNonExistingFile() throws Exception {
         AioFuture<AsynchronousFileChannel> future = AsynchronousFileChannelFactory.open(new File("Foo"), Modes.READ_ONLY);
         try {
@@ -25,7 +26,7 @@
         }
     }
 
-    @Test(groups={"concurrent"})
+    @Test(groups={"concurrent", "open"})
     public void openFileReadOnly() throws Exception {
         File testFile = File.createTempFile("aio", "test");
         AioFuture<AsynchronousFileChannel> future = AsynchronousFileChannelFactory.open(testFile, Modes.READ_ONLY);
@@ -37,7 +38,7 @@
         assert !channel.isOpen();
     }
     
-    @Test(groups={"concurrent"})
+    @Test(groups={"concurrent", "open"})
     public void openFileReadWrite() throws Exception {
         File testFile = File.createTempFile("aio", "test");
         AioFuture<AsynchronousFileChannel> future = AsynchronousFileChannelFactory.open(testFile, Modes.READ_WRITE);
@@ -45,6 +46,30 @@
         assert channel.isReadable();
         assert channel.isWriteable();
         channel.close();
+    }
+    
+    @Test(timeOut=5000, groups={"concurrent", "open", "callback"})
+    public void openCallback() throws Exception {
+        final int callbackCount = 3;
+        
+        File testFile = File.createTempFile("aio", "test");
+        AioFuture<AsynchronousFileChannel> future = AsynchronousFileChannelFactory.open(testFile, Modes.READ_WRITE);
+        final Semaphore sem = new Semaphore(callbackCount);
+        sem.acquire(callbackCount);
+        for (int i = 0; i < callbackCount; i++) {
+            future.addCompletionHandler(new AioCompletionHandler<AioFuture>() {
+                public void onCompletion(AioFuture future) {
+                    sem.release();
+                }
+            });
+        }
+        future.get();
+        try {
+            sem.acquire(callbackCount);
+        } catch (InterruptedException e) {
+            System.out.printf("%d available semaphore permits, expected %d\n", sem.availablePermits(), callbackCount);
+            throw e;
+        }
     }
     
 }