geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: rev 55158 - in geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol: . control
Date Wed, 20 Oct 2004 15:29:58 GMT
Author: adc
Date: Wed Oct 20 08:29:57 2004
New Revision: 55158

Added:
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestCountingProtocol.java
Modified:
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/DatagramProtocolTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/GSSAPIProtocolTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/PacketStreamTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/ProtocolStackTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolStressTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolTest.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestProtocol.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/UsernamePasswordCallback.java
   geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/control/ControlProtocolTest.java
Log:
Not that this will stop you.  You know who you are and what it is that you do...

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/DatagramProtocolTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/DatagramProtocolTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/DatagramProtocolTest.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import java.net.InetSocketAddress;
@@ -23,6 +22,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
 import junit.framework.TestCase;
 
 import org.apache.geronimo.network.SelectorManager;
@@ -34,6 +34,9 @@
  */
 public class DatagramProtocolTest extends TestCase {
 
+    protected final int COUNT = 5;
+    protected CountDown completed;
+
     public void test() throws Exception {
         ThreadPool tp = new ThreadPool();
         tp.setKeepAliveTime(100);
@@ -44,72 +47,33 @@
         SelectorManager sm = new SelectorManager();
         sm.setThreadPool(tp);
         sm.setThreadName("SM");
-        sm.setTimeout(500);
         sm.doStart();
 
+        ProtocolStack stack = new ProtocolStack();
         DatagramProtocol dgp = new DatagramProtocol();
-        dgp.setUpProtocol(new Protocol() {
-            public Protocol getUpProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setUpProtocol(Protocol up) {
-                throw new NoSuchMethodError();
-            }
-
-            public Protocol getDownProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setDownProtocol(Protocol down) {
-                throw new NoSuchMethodError();
-            }
-
-            public void clearLinks() {
-            }
-
-            public Protocol cloneProtocol() throws CloneNotSupportedException {
-                return (Protocol) super.clone();
-            }
-
-            public void setup() {
-            }
-
-            public void drain() {
-            }
-
-            public void teardown() throws ProtocolException {
-            }
-
-            public void sendUp(UpPacket packet) {
-                DatagramUpPacket datgramPacket = (DatagramUpPacket) packet;
-                System.out.println("FOO " + datgramPacket.getAddress());
-            }
-
-            public void sendDown(DownPacket packet) {
-            }
-
-            public void flush() throws ProtocolException {
-            }
-        });
-
         dgp.setDestinationInterface(new InetSocketAddress("localhost", 0));
         dgp.setSourceAddress(new InetSocketAddress("localhost", 0));
         dgp.setSelectorManager(sm);
 
-        dgp.setup();
+        stack.push(dgp);
+        stack.push(new TopProtocol());
+        stack.push(new TestCountingProtocol(completed));
+
+        stack.setup();
 
         DatagramDownPacket packet = new DatagramDownPacket();
         packet.setAddress(new InetSocketAddress(dgp.getConnectURI().getHost(), dgp.getConnectURI().getPort()));
         packet.setBuffers(getByteBuffer());
 
-        dgp.sendDown(packet);
-        dgp.sendDown(packet);
-        dgp.sendDown(packet);
-
-        Thread.sleep(1 * 1000);
+        for (int i = 0; i < COUNT; i++) {
+            stack.sendDown(packet);
+        }
+
+        if (!completed.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
-        dgp.drain();
+        stack.drain();
 
         sm.doStop();
 
@@ -128,77 +92,43 @@
         sm.setThreadName("SM");
         sm.doStart();
 
+        ProtocolStack stack = new ProtocolStack();
         DatagramProtocol dgp = new DatagramProtocol();
-        dgp.setUpProtocol(new Protocol() {
-            public Protocol getUpProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setUpProtocol(Protocol up) {
-                throw new NoSuchMethodError();
-            }
-
-            public Protocol getDownProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setDownProtocol(Protocol down) {
-                throw new NoSuchMethodError();
-            }
-
-            public void clearLinks() {
-            }
-
-            public Protocol cloneProtocol() throws CloneNotSupportedException {
-                return (Protocol) super.clone();
-            }
-
-            public void setup() {
-            }
-
-            public void drain() {
-            }
-
-            public void teardown() throws ProtocolException {
-            }
-
-            public void sendUp(UpPacket packet) {
-                DatagramUpPacket datgramPacket = (DatagramUpPacket) packet;
-                System.out.println("FOO " + datgramPacket.getAddress());
-            }
-
-            public void sendDown(DownPacket packet) {
-            }
-
-            public void flush() throws ProtocolException {
-            }
-        });
-
         dgp.setDestinationInterface(new InetSocketAddress("localhost", 0));
         dgp.setSourceAddress(new InetSocketAddress("localhost", 8081));
         dgp.setSelectorManager(sm);
 
-        DatagramProtocol dgp2 = (DatagramProtocol) dgp.cloneProtocol();
+        stack.push(dgp);
+        stack.push(new TopProtocol());
+        stack.push(new TestCountingProtocol(completed));
+
+        ProtocolStack stack_copy = (ProtocolStack) stack.cloneProtocol();
 
-        dgp2.setup();
+        stack_copy.setup();
 
         DatagramDownPacket packet = new DatagramDownPacket();
         packet.setAddress(new InetSocketAddress("localhost", 8081));
         packet.setBuffers(getByteBuffer());
 
-        dgp2.sendDown(packet);
-        dgp2.sendDown(packet);
-        dgp2.sendDown(packet);
+        for (int i = 0; i < COUNT; i++) {
+            stack_copy.sendDown(packet);
+        }
+
+        if (!completed.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
-        Thread.sleep(5 * 1000);
-
-        dgp2.drain();
+        stack_copy.drain();
 
         sm.doStop();
 
         tp.doStop();
     }
 
+    public void setUp() throws Exception {
+        completed = new CountDown(COUNT);
+    }
+
     public Collection getByteBuffer() {
         ArrayList list = new ArrayList();
 
@@ -215,5 +145,30 @@
         list.add(byteBuffer);
 
         return list;
+    }
+
+    class TopProtocol extends AbstractProtocol {
+
+        public void setup() {
+        }
+
+        public void drain() {
+        }
+
+        public void teardown() {
+        }
+
+        public void sendUp(UpPacket packet) throws ProtocolException {
+            DatagramUpPacket datgramPacket = (DatagramUpPacket) packet;
+            System.out.println("FOO " + datgramPacket.getAddress());
+            getUpProtocol().sendUp(packet);
+        }
+
+        public void sendDown(DownPacket packet) throws ProtocolException {
+            getDownProtocol().sendDown(packet);
+        }
+
+        public void flush() throws ProtocolException {
+        }
     }
 }

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/GSSAPIProtocolTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/GSSAPIProtocolTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/GSSAPIProtocolTest.java
Wed Oct 20 08:29:57 2004
@@ -14,13 +14,11 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
-
 import java.io.File;
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -31,6 +29,7 @@
 import java.util.ArrayList;
 import java.util.Properties;
 
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
 import EDU.oswego.cs.dl.util.concurrent.Latch;
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
@@ -53,6 +52,8 @@
 public class GSSAPIProtocolTest extends TestCase {
 
     final static private Log log = LogFactory.getLog(GSSAPIProtocolTest.class);
+    protected final int COUNT = 5;
+    protected CountDown completed;
 
     private Properties properties;
     private Subject clientSubject;
@@ -105,7 +106,7 @@
             clientStack.setSelectorManager(sm);
 
             SocketProtocol sp = new SocketProtocol();
-            sp.setTimeout(1000 * 1000); //todo reset to 10s
+            sp.setTimeout(10 * 1000);
             sp.setInterface(new InetSocketAddress(ssa.getConnectURI().getHost(), 0));
             sp.setAddress(new InetSocketAddress(ssa.getConnectURI().getHost(), ssa.getConnectURI().getPort()));
             sp.setSelectorManager(sm);
@@ -113,18 +114,19 @@
             clientStack.push(sp);
 
             ControlClientProtocol ccp = new ControlClientProtocol();
-            ccp.setTimeout(1000 * 1000); //todo set to 10s
+            ccp.setTimeout(10 * 1000);
 
             clientStack.push(ccp);
 
             clientStack.setup();
-            Thread.sleep(5 * 1000); //todo delete
 
             clientStack.sendDown(getPlainPacket());
             clientStack.sendDown(getPlainPacket());
             clientStack.sendDown(getPlainPacket());
 
-            Thread.sleep(5 * 1000); //todo back to 5s
+            if (!completed.attempt(60 * 1000)) {
+                throw new IllegalStateException("TIMEOUT");
+            }
 
             clientStack.drain();
 
@@ -222,6 +224,8 @@
 
             templateStack.push(waiter);
 
+            templateStack.push(new TestCountingProtocol(completed));
+
             ProtocolFactory pf = new ProtocolFactory();
             pf.setClockPool(cp);
             pf.setMaxAge(Long.MAX_VALUE);
@@ -258,6 +262,7 @@
         startLatch = new Latch();
         shutdownLatch = new Latch();
         stopLatch = new Latch();
+        completed = new CountDown(COUNT);
         try {
             properties = new Properties();
             try {
@@ -280,8 +285,6 @@
             hasKerberos = false;
         }
     }
-
-    static volatile long id = 0;
 
     protected PlainDownPacket getPlainPacket() {
         PlainDownPacket packet = new PlainDownPacket();

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/PacketStreamTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/PacketStreamTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/PacketStreamTest.java
Wed Oct 20 08:29:57 2004
@@ -29,11 +29,12 @@
  */
 public class PacketStreamTest extends TestCase {
 
-    EchoUpProtocol eup;
-    Latch startLatch;
-    boolean failed;
+    protected EchoUpProtocol eup;
+    protected Latch startLatch;
+    protected boolean failed;
 
-    public void testDummy() throws Exception { }
+    public void testDummy() throws Exception {
+    }
 
     public void testStream() throws Exception {
         new Thread(new WriterThread((short) 1024), "Test Writer").start();

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/ProtocolStackTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/ProtocolStackTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/ProtocolStackTest.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import java.net.InetSocketAddress;
@@ -23,6 +22,7 @@
 import java.nio.CharBuffer;
 import java.util.ArrayList;
 
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
 import junit.framework.TestCase;
 
 import org.apache.geronimo.network.SelectorManager;
@@ -34,7 +34,12 @@
  * @version $Rev$ $Date$
  */
 public class ProtocolStackTest extends TestCase {
-    public void testNothing() {}
+
+    protected final int COUNT = 5;
+    protected CountDown completed;
+
+    public void testNothing() {
+    }
 
     public void test() throws Exception {
         ThreadPool tp = new ThreadPool();
@@ -68,6 +73,8 @@
         test.setSelectorManager(sm);
         s.push(test);
 
+        s.push(new TestCountingProtocol(completed));
+
         ProtocolFactory pf = new ProtocolFactory();
         pf.setClockPool(cp);
         pf.setMaxAge(Long.MAX_VALUE);
@@ -82,69 +89,27 @@
         ssa.setAcceptorListener(pf);
         ssa.startup();
 
-        SocketProtocol sp = new SocketProtocol();
-        sp.setUpProtocol(new Protocol() {
-            public Protocol getUpProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setUpProtocol(Protocol up) {
-                throw new NoSuchMethodError();
-            }
-
-            public Protocol getDownProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setDownProtocol(Protocol down) {
-                throw new NoSuchMethodError();
-            }
-
-            public void clearLinks() {
-            }
-
-            public Protocol cloneProtocol() throws CloneNotSupportedException {
-                return (Protocol) super.clone();
-            }
+        ProtocolStack stack = new ProtocolStack();
 
-            public void setup() {
-            }
-
-            public void drain() {
-            }
-
-            public void teardown() throws ProtocolException {
-            }
-
-            public void sendUp(UpPacket packet) {
-            }
-
-            public void sendDown(DownPacket packet) {
-            }
-
-            public void flush() throws ProtocolException {
-            }
-        });
-
-        sp.setTimeout(1000 * 1000);  //todo set back to 10s
+        SocketProtocol sp = new SocketProtocol();
+        sp.setTimeout(10 * 1000);
         sp.setInterface(new InetSocketAddress(ssa.getConnectURI().getHost(), 0));
         sp.setAddress(new InetSocketAddress(ssa.getConnectURI().getHost(), ssa.getConnectURI().getPort()));
         sp.setSelectorManager(sm);
 
-        sp.setup();
+        stack.push(sp);
 
+        stack.setup();
 
-        sp.sendDown(getDatagramPacket());
-        sp.sendDown(getDatagramPacket());
-        sp.sendDown(getDatagramPacket());
+        for (int i = 0; i < COUNT; i++) {
+            stack.sendDown(getDatagramPacket());
+        }
 
-        DatagramDownPacket packet = getDatagramPacket();
-        sp.sendDown(packet);
-        sp.sendDown(packet);
+        if (!completed.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
-        Thread.sleep(5 * 1000);
-
-        sp.drain();
+        stack.drain();
 
         ssa.drain();
 
@@ -157,6 +122,10 @@
         cp.doStop();
 
         tp.doStop();
+    }
+
+    public void setUp() throws Exception {
+        completed = new CountDown(COUNT);
     }
 
     static volatile long id = 0;

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolStressTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolStressTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolStressTest.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import java.net.InetSocketAddress;
@@ -36,6 +35,12 @@
  */
 public class SocketProtocolStressTest extends TestCase {
 
+    protected final int WORKERS = 10;
+    protected final int MESSAGE_COUNT = 10;
+    protected CountDown simpleCompleted;
+    protected CountDown concurrentCompleted;
+    protected TestCountingProtocol simpleCounter;
+    protected TestCountingProtocol concurrentCounter;
     protected ThreadPool tp;
     protected ClockPool cp;
     protected SelectorManager sm;
@@ -45,26 +50,26 @@
     protected SocketProtocol sp;
     protected volatile int count;
 
-    public void testNothing() {}
+    public void testNothing() {
+    }
 
     public void testSimple() throws Exception {
-        sp.sendDown(allocateDownPacket());
-        sp.sendDown(allocateDownPacket());
-        sp.sendDown(allocateDownPacket());
-
-        DatagramDownPacket packet = allocateDownPacket();
-        sp.sendDown(packet);
-        sp.sendDown(packet);
+        simpleCounter.setCompleted(simpleCompleted = new CountDown(MESSAGE_COUNT));
+
+        for (int i = 0; i < MESSAGE_COUNT; i++) {
+            sp.sendDown(allocateDownPacket());
+        }
 
-        Thread.sleep(5 * 1000);
+        if (!simpleCompleted.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
     }
 
-    public void XtestConcurrentRequests() throws Exception {
+    public void testConcurrentRequests() throws Exception {
 
-        final int WORKERS = 10;
-        final int MESSAGE_COUNT = 10;
         final CyclicBarrier barrier = new CyclicBarrier(WORKERS);
-        final CountDown finished = new CountDown(WORKERS);
+
+        concurrentCounter.setCompleted(concurrentCompleted = new CountDown(WORKERS * MESSAGE_COUNT));
 
         for (int i = 0; i < WORKERS; i++) {
 
@@ -79,24 +84,22 @@
                         for (int i = 0; i < MESSAGE_COUNT; i++)
                             sp.sendDown(allocateDownPacket());
 
-
                     } catch (Exception e) {
                         e.printStackTrace();
-                    } finally {
-                        finished.release();
                     }
                 }
             }.start();
         }
 
-        finished.acquire();
-
-        Thread.sleep(5 * 1000);
+        if (!concurrentCompleted.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
         assertEquals(WORKERS * MESSAGE_COUNT, count);
     }
 
     public void setUp() throws Exception {
+
         count = 0;
 
         tp = new ThreadPool();
@@ -135,13 +138,38 @@
 
             public void sendUp(UpPacket packet) throws ProtocolException {
                 count++;
+                getUpProtocol().sendUp(packet);
+            }
+
+            public void sendDown(DownPacket packet) throws ProtocolException {
+                getDownProtocol().sendDown(packet);
+            }
+
+            public void flush() {
+            }
+        });
+
+        aps.push(simpleCounter = new TestCountingProtocol(new CountDown(MESSAGE_COUNT)));
+        aps.push(concurrentCounter = new TestCountingProtocol(new CountDown(WORKERS * MESSAGE_COUNT)));
+
+        aps.push(new AbstractProtocol() {
+            public void setup() {
+            }
+
+            public void drain() {
+            }
+
+            public void teardown() {
+            }
+
+            public void sendUp(UpPacket packet) throws ProtocolException {
                 this.getDownProtocol().sendDown(allocateDownPacket());
             }
 
             public void sendDown(DownPacket packet) {
             }
 
-            public void flush() throws ProtocolException {
+            public void flush() {
             }
         });
 
@@ -199,7 +227,7 @@
             public void sendDown(DownPacket packet) {
             }
 
-            public void flush() throws ProtocolException {
+            public void flush() {
             }
         });
 

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/SocketProtocolTest.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import java.net.InetSocketAddress;
@@ -23,6 +22,7 @@
 import java.nio.ByteOrder;
 import java.util.ArrayList;
 
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
 import junit.framework.TestCase;
 
 import org.apache.geronimo.network.SelectorManager;
@@ -35,7 +35,11 @@
  */
 public class SocketProtocolTest extends TestCase {
 
-    public void testNothing() {}
+    protected final int COUNT = 5;
+    protected CountDown completed;
+
+    public void testNothing() {
+    }
 
     public void test() throws Exception {
         ThreadPool tp = new ThreadPool();
@@ -55,49 +59,7 @@
         sm.doStart();
 
         SocketProtocol spt = new SocketProtocol();
-        spt.setUpProtocol(new Protocol() {
-            public Protocol getUpProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setUpProtocol(Protocol up) {
-                throw new NoSuchMethodError();
-            }
-
-            public Protocol getDownProtocol() {
-                throw new NoSuchMethodError();
-            }
-
-            public void setDownProtocol(Protocol down) {
-                throw new NoSuchMethodError();
-            }
-
-            public void clearLinks() {
-            }
-
-            public Protocol cloneProtocol() throws CloneNotSupportedException {
-                return (Protocol) super.clone();
-            }
-
-            public void setup() {
-            }
-
-            public void drain() {
-            }
-
-            public void teardown() throws ProtocolException {
-            }
-
-            public void sendUp(UpPacket packet) {
-                System.out.println("BAR ");
-            }
-
-            public void sendDown(DownPacket packet) {
-            }
-
-            public void flush() throws ProtocolException {
-            }
-        });
+        spt.setUpProtocol(new TestCountingProtocol(completed));
         spt.setTimeout(10 * 1000);
         spt.setSelectorManager(sm);
 
@@ -146,7 +108,7 @@
             public void drain() {
             }
 
-            public void teardown() throws ProtocolException {
+            public void teardown() {
             }
 
             public void sendUp(UpPacket packet) {
@@ -155,7 +117,7 @@
             public void sendDown(DownPacket packet) {
             }
 
-            public void flush() throws ProtocolException {
+            public void flush() {
             }
         });
 
@@ -167,15 +129,13 @@
         sp.setup();
 
 
-        sp.sendDown(getDatagramPacket());
-        sp.sendDown(getDatagramPacket());
-        sp.sendDown(getDatagramPacket());
-
-        DatagramDownPacket packet = getDatagramPacket();
-        sp.sendDown(packet);
-        sp.sendDown(packet);
-
-        Thread.sleep(5 * 1000);
+        for (int i = 0; i < COUNT; i++) {
+            sp.sendDown(getDatagramPacket());
+        }
+
+        if (!completed.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
         sp.drain();
 
@@ -190,6 +150,10 @@
         cp.doStop();
 
         tp.doStop();
+    }
+
+    public void setUp() throws Exception {
+        completed = new CountDown(COUNT);
     }
 
     public DatagramDownPacket getDatagramPacket() {

Added: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestCountingProtocol.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestCountingProtocol.java
Wed Oct 20 08:29:57 2004
@@ -0,0 +1,59 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.network.protocol;
+
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
+
+
+/**
+ * @version $Rev: 46019 $ $Date: 2004-09-14 05:56:06 -0400 (Tue, 14 Sep 2004) $
+ */
+public class TestCountingProtocol extends AbstractProtocol {
+    private CountDown completed;
+
+    public TestCountingProtocol() {
+    }
+
+    public TestCountingProtocol(CountDown completed) {
+        this.completed = completed;
+    }
+
+    public void setCompleted(CountDown completed) {
+        this.completed = completed;
+    }
+
+    public void setup() throws ProtocolException {
+    }
+
+    public void drain() throws ProtocolException {
+    }
+
+    public void teardown() throws ProtocolException {
+    }
+
+    public void sendUp(UpPacket packet) throws ProtocolException {
+        completed.release();
+        if (getUpProtocol() != null) getUpProtocol().sendUp(packet);
+    }
+
+    public void sendDown(DownPacket packet) throws ProtocolException {
+        getDownProtocol().sendDown(packet);
+    }
+
+    public void flush() throws ProtocolException {
+    }
+}

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestProtocol.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestProtocol.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/TestProtocol.java
Wed Oct 20 08:29:57 2004
@@ -14,11 +14,9 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import javax.security.auth.Subject;
-
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/UsernamePasswordCallback.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/UsernamePasswordCallback.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/UsernamePasswordCallback.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol;
 
 import javax.security.auth.callback.Callback;
@@ -22,7 +21,6 @@
 import javax.security.auth.callback.NameCallback;
 import javax.security.auth.callback.PasswordCallback;
 import javax.security.auth.callback.UnsupportedCallbackException;
-
 import java.io.IOException;
 
 

Modified: geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/control/ControlProtocolTest.java
==============================================================================
--- geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/control/ControlProtocolTest.java
(original)
+++ geronimo/trunk/modules/network/src/test/org/apache/geronimo/network/protocol/control/ControlProtocolTest.java
Wed Oct 20 08:29:57 2004
@@ -14,7 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.geronimo.network.protocol.control;
 
 import java.net.InetSocketAddress;
@@ -22,16 +21,17 @@
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
 import junit.framework.TestCase;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.geronimo.network.SelectorManager;
-import org.apache.geronimo.network.protocol.CountingProtocol;
 import org.apache.geronimo.network.protocol.DatagramDownPacket;
 import org.apache.geronimo.network.protocol.ProtocolFactory;
 import org.apache.geronimo.network.protocol.ServerSocketAcceptor;
 import org.apache.geronimo.network.protocol.SocketProtocol;
+import org.apache.geronimo.network.protocol.TestCountingProtocol;
 import org.apache.geronimo.network.protocol.TestProtocol;
 import org.apache.geronimo.pool.ClockPool;
 import org.apache.geronimo.pool.ThreadPool;
@@ -43,8 +43,11 @@
 public class ControlProtocolTest extends TestCase {
 
     final static private Log log = LogFactory.getLog(ControlProtocolTest.class);
+    protected final int COUNT = 5;
+    protected CountDown completed;
 
-    public void testDummy() throws Exception { }
+    public void testDummy() throws Exception {
+    }
 
     public void test() throws Exception {
         ThreadPool tp = new ThreadPool();
@@ -85,8 +88,6 @@
 
         ControlServerProtocolWaiter waiter = new ControlServerProtocolWaiter();
 
-        waiter.push(new CountingProtocol());
-
         TestProtocol test = new TestProtocol();
         test.setValue("SimpleTest");
         test.setThreadPool(tp);
@@ -97,6 +98,8 @@
 
         templateStack.push(waiter);
 
+        templateStack.push(new TestCountingProtocol(completed));
+
         ProtocolFactory pf = new ProtocolFactory();
         pf.setClockPool(cp);
         pf.setMaxAge(Long.MAX_VALUE);
@@ -132,16 +135,16 @@
 
         clientStack.setup();
 
-        clientStack.sendDown(getDatagramPacket());
-        clientStack.sendDown(getDatagramPacket());
-        clientStack.sendDown(getDatagramPacket());
+        for (int i = 0; i < COUNT; i++) {
+            clientStack.sendDown(getDatagramPacket());
+        }
 
-        Thread.sleep(5 * 1000);
+        if (!completed.attempt(60 * 1000)) {
+            throw new IllegalStateException("TIMEOUT");
+        }
 
         clientStack.drain();
 
-        Thread.sleep(5 * 1000);
-
         ssa.drain();
 
         pf.drain();
@@ -153,7 +156,9 @@
         tp.doStop();
     }
 
-    static volatile long id = 0;
+    public void setUp() throws Exception {
+        completed = new CountDown(COUNT);
+    }
 
     protected DatagramDownPacket getDatagramPacket() {
         DatagramDownPacket packet = new DatagramDownPacket();
@@ -164,10 +169,6 @@
         for (int i = 0; i < COUNT; i++) {
             buffer.put((byte) 0x0b);
         }
-//        CharBuffer b = buffer.asCharBuffer();
-//        b.put("Hello! " + id++);
-//
-//        buffer.position(b.position()*2);
         buffer.flip();
         list.add(buffer);
 

Mime
View raw message