tomcat-dev mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1197263&view=rev
Log:
Clean up code and use logging framework instead of System.out.

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=1197263&r1=1197262&r2=1197263&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 18:43:09 2011
@@ -25,45 +25,49 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.catalina.startup.LoggingBaseTest;
 import org.apache.catalina.tribes.Channel;
 import org.apache.catalina.tribes.ChannelListener;
 import org.apache.catalina.tribes.ManagedChannel;
 import org.apache.catalina.tribes.Member;
 import org.apache.catalina.tribes.transport.ReplicationTransmitter;
 
-public class TestGroupChannelSenderConnections {
-    private static int count = 2;
+public class TestGroupChannelSenderConnections extends LoggingBaseTest {
+    private static final int count = 2;
     private ManagedChannel[] channels = new ManagedChannel[count];
     private TestMsgListener[] listeners = new TestMsgListener[count];
 
     @Before
+    @Override
     public void setUp() throws Exception {
+        super.setUp();
         for (int i = 0; i < channels.length; i++) {
             channels[i] = new GroupChannel();
             channels[i].getMembershipService().setPayload( ("Channel-" + (i + 1)).getBytes("ASCII"));
             listeners[i] = new TestMsgListener( ("Listener-" + (i + 1)));
             channels[i].addChannelListener(listeners[i]);
             channels[i].start(Channel.SND_RX_SEQ|Channel.SND_TX_SEQ);
-
         }
     }
 
-    public void clear() {
-        // NOOP
-    }
-
     public void sendMessages(long delay, long sleep) throws Exception {
         Member local = channels[0].getLocalMember(true);
         Member dest = channels[1].getLocalMember(true);
         int n = 3;
-        System.out.println("Sending " + n + " messages from [" + local.getName() + "] to
[" + dest.getName() + "]");
+        log.info("Sending " + n + " messages from [" + local.getName()
+                + "] to [" + dest.getName() + "] with delay of " + delay
+                + " ms between them.");
         for (int i = 0; i < n; i++) {
-            channels[0].send(new Member[] {dest}, new TestMsg(), 0);
-            if ( delay > 0 ) Thread.sleep(delay);
+            channels[0].send(new Member[] { dest }, new TestMsg(), 0);
+            if (delay > 0) {
+                Thread.sleep(delay);
+            }
+        }
+        log.info("Messages sent. Sleeping for " + (sleep / 1000)
+                + " seconds to inspect connections");
+        if (sleep > 0) {
+            Thread.sleep(sleep);
         }
-        System.out.println("Messages sent. Sleeping for "+(sleep/1000)+" seconds to inspect
connections");
-        if ( sleep > 0 ) Thread.sleep(sleep);
-
     }
 
     @Test
@@ -73,7 +77,7 @@ public class TestGroupChannelSenderConne
 
     @Test
     public void testKeepAliveCount() throws Exception {
-        System.out.println("Setting keep alive count to 0");
+        log.info("Setting keep alive count to 0");
         for (int i = 0; i < channels.length; i++) {
             ReplicationTransmitter t = (ReplicationTransmitter)channels[0].getChannelSender();
             t.getTransport().setKeepAliveCount(0);
@@ -83,7 +87,7 @@ public class TestGroupChannelSenderConne
 
     @Test
     public void testKeepAliveTime() throws Exception {
-        System.out.println("Setting keep alive count to 1 second");
+        log.info("Setting keep alive count to 1 second");
         for (int i = 0; i < channels.length; i++) {
             ReplicationTransmitter t = (ReplicationTransmitter)channels[0].getChannelSender();
             t.getTransport().setKeepAliveTime(1000);
@@ -92,17 +96,22 @@ public class TestGroupChannelSenderConne
     }
 
     @After
+    @Override
     public void tearDown() throws Exception {
-        for (int i = 0; i < channels.length; i++) {
-            channels[i].stop(Channel.DEFAULT);
+        try {
+            for (int i = 0; i < channels.length; i++) {
+                channels[i].stop(Channel.DEFAULT);
+            }
+        } finally {
+            super.tearDown();
         }
-
     }
 
+    // Test message. The message size is random.
     public static class TestMsg implements Serializable {
         private static final long serialVersionUID = 1L;
-        static Random r = new Random();
-        HashMap<Integer, ArrayList<Object>> map =
+        private static Random r = new Random();
+        private HashMap<Integer, ArrayList<Object>> map =
             new HashMap<Integer, ArrayList<Object>>();
         public TestMsg() {
             int size = Math.abs(r.nextInt() % 200);
@@ -114,24 +123,22 @@ public class TestGroupChannelSenderConne
         }
     }
 
-    public static class TestMsgListener implements ChannelListener {
-        public String name = null;
+    public class TestMsgListener implements ChannelListener {
+        public final String name;
         public TestMsgListener(String name) {
             this.name = name;
         }
 
         @Override
         public void messageReceived(Serializable msg, Member sender) {
-            System.out.println("["+name+"] Received message:"+msg+" from " + sender.getName());
+            log.info("["+name+"] Received message:"+msg+" from " + sender.getName());
         }
 
-
         @Override
         public boolean accept(Serializable msg, Member sender) {
             return true;
         }
 
-
     }
 
 }



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


Mime
View raw message