tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kkoli...@apache.org
Subject svn commit: r1197305 - /tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
Date Thu, 03 Nov 2011 20:54:52 GMT
Author: kkolinko
Date: Thu Nov  3 20:54:52 2011
New Revision: 1197305

URL: http://svn.apache.org/viewvc?rev=1197305&view=rev
Log:
Remove 15s wait after each test.
I do not understand why that 15s wait with "inspect connections" message was there. Nothing
was checked after the wait. Replaced it with a check of the count of received messages.
Removed wait after sending the last message in the group of 3.
This change saves (3 * 15 sec) + (1 sec + 2 sec) = 48 seconds.

Modified:
    tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java

Modified: tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java?rev=1197305&r1=1197304&r2=1197305&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
(original)
+++ tomcat/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
Thu Nov  3 20:54:52 2011
@@ -20,6 +20,9 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.junit.Assert.fail;
 
 import org.junit.After;
 import org.junit.Before;
@@ -51,6 +54,7 @@ public class TestGroupChannelSenderConne
     }
 
     public void sendMessages(long delay, long sleep) throws Exception {
+        resetMessageCounters();
         Member local = channels[0].getLocalMember(true);
         Member dest = channels[1].getLocalMember(true);
         int n = 3;
@@ -59,14 +63,24 @@ public class TestGroupChannelSenderConne
                 + " ms between them.");
         for (int i = 0; i < n; i++) {
             channels[0].send(new Member[] { dest }, new TestMsg(), 0);
-            if (delay > 0) {
+            boolean last = (i == n - 1);
+            if (!last && delay > 0) {
                 Thread.sleep(delay);
             }
         }
-        log.info("Messages sent. Sleeping for " + (sleep / 1000)
-                + " seconds to inspect connections");
-        if (sleep > 0) {
-            Thread.sleep(sleep);
+        log.info("Messages sent. Waiting no more than " + (sleep / 1000)
+                + " seconds for them to be received");
+        long startTime = System.currentTimeMillis();
+        int countReceived;
+        while ((countReceived = getReceivedMessageCount()) != n) {
+            long time = System.currentTimeMillis();
+            if ((time - startTime) > sleep) {
+                fail("Only " + countReceived + " out of " + n
+                        + " messages have been received in " + (sleep / 1000)
+                        + " seconds");
+                break;
+            }
+            Thread.sleep(100);
         }
     }
 
@@ -107,6 +121,20 @@ public class TestGroupChannelSenderConne
         }
     }
 
+    private void resetMessageCounters() {
+        for (TestMsgListener listener: listeners) {
+            listener.reset();
+        }
+    }
+
+    private int getReceivedMessageCount() {
+        int count = 0;
+        for (TestMsgListener listener: listeners) {
+            count += listener.getReceivedCount();
+        }
+        return count;
+    }
+
     // Test message. The message size is random.
     public static class TestMsg implements Serializable {
         private static final long serialVersionUID = 1L;
@@ -124,13 +152,23 @@ public class TestGroupChannelSenderConne
     }
 
     public class TestMsgListener implements ChannelListener {
-        public final String name;
+        private final String name;
+        private final AtomicInteger counter = new AtomicInteger();
         public TestMsgListener(String name) {
             this.name = name;
         }
 
+        public void reset() {
+            counter.set(0);
+        }
+
+        public int getReceivedCount() {
+            return counter.get();
+        }
+
         @Override
         public void messageReceived(Serializable msg, Member sender) {
+            counter.incrementAndGet();
             log.info("["+name+"] Received message:"+msg+" from " + sender.getName());
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message