commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1133826 - /commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
Date Thu, 09 Jun 2011 12:28:11 GMT
Author: mturk
Date: Thu Jun  9 12:28:11 2011
New Revision: 1133826

URL: http://svn.apache.org/viewvc?rev=1133826&view=rev
Log:
Make sure we clear any leftovers from the previous run

Modified:
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java?rev=1133826&r1=1133825&r2=1133826&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
Thu Jun  9 12:28:11 2011
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime.net;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 import org.testng.annotations.*;
@@ -24,6 +25,16 @@ import org.testng.Assert;
 public class TestPosixEndpoint extends Assert
 {
 
+    @BeforeSuite
+    @Test(groups = { "posix" })
+    public void setUp()
+        throws Exception
+    {
+        // Cleanup any previous leftovers
+        File f = new File("/tmp/acrposixep1.sock");
+        f.delete();
+    }
+    
     private Object sync = new Object();
 
     class Acceptor extends Thread
@@ -57,9 +68,13 @@ public class TestPosixEndpoint extends A
                     // System.out.println("Accepting connection ...");
                     List<SelectionKey> set = ps.select();
                     // System.out.println("Accepted  connection: " + set.size());
+                    assertEquals(set.size(), 1);
                     sk = set.get(0);
                     LocalEndpoint e = ((LocalServerEndpoint)sk.endpoint()).accept();
                     assertNotNull(e.descriptor());
+                    // Another select with zero timeout
+                    set = ps.select(0);
+                    assertEquals(set.size(), 0);
                 } catch (Exception x) {
                     fail("Accept failed " + x.toString());
                 }
@@ -78,11 +93,15 @@ public class TestPosixEndpoint extends A
     public void connectLocalEndpoint()
         throws Exception
     {
+        
         Selector             ps = Selector.open(EndpointType.LOCAL);
         LocalServerEndpoint  ss = new LocalServerEndpoint();
         LocalEndpointAddress sa = new LocalEndpointAddress("/tmp/acrposixep1.sock");
         ss.configureBlocking(false);
         ss.bind(sa);
+        // keyFor() should return null since the endpoint
+        // is not yet registered.
+        assertNull(ss.keyFor(ps));
         // ps.setAutoCancel(true);
         Acceptor aw = new Acceptor(ss, ps);
         aw.setName("TestAcceptorThread");
@@ -96,15 +115,16 @@ public class TestPosixEndpoint extends A
         } catch (InterruptedException x) {
             // Ignore
         }
+        // By this time the key is set up.
+        assertNotNull(ss.keyFor(ps));
         aw.running = false;
-        // Create unbound socket
-        // FileDescriptor is null until bind call
+        // Connect to the Acceptor
         //
         LocalEndpoint cs = new LocalEndpoint();
         cs.connect(sa);
         assertTrue(cs.isBlocking());
         cs.close();
-        // Wait for acceptor thread to finish
+        // Wait for the Acceptor thread to finish
         aw.join();
         List<SelectionKey> set = ps.clear();
         // Shoud equal zero if autoCancel is set to true



Mime
View raw message