You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2015/11/07 18:17:56 UTC

svn commit: r1713158 - /tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java

Author: kkolinko
Date: Sat Nov  7 17:17:55 2015
New Revision: 1713158

URL: http://svn.apache.org/viewvc?rev=1713158&view=rev
Log:
Copy test implementation from Tomcat 7.
This a) uses logging instead of System.out,
b) validates result of the test and fail()s, instead of just printing a message onto System.out

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

Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java?rev=1713158&r1=1713157&r2=1713158&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java (original)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java Sat Nov  7 17:17:55 2015
@@ -20,11 +20,15 @@ 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;
 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;
@@ -32,13 +36,15 @@ import org.apache.catalina.tribes.Member
 import org.apache.catalina.tribes.TesterUtil;
 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"));
@@ -52,27 +58,44 @@ 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;
-        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);
+            boolean last = (i == n - 1);
+            if (!last && delay > 0) {
+                Thread.sleep(delay);
+            }
+        }
+        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);
         }
-        System.out.println("Messages sent. Sleeping for "+(sleep/1000)+" seconds to inspect connections");
-        if ( sleep > 0 ) Thread.sleep(sleep);
-
     }
 
     @Test
     public void testConnectionLinger() throws Exception {
         sendMessages(0,15000);
     }
-    
+
     @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);
@@ -82,7 +105,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);
@@ -91,11 +114,29 @@ 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();
         }
+    }
 
+    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.
@@ -103,7 +144,7 @@ public class TestGroupChannelSenderConne
         private static final long serialVersionUID = 1L;
         private static Random r = new Random();
         private HashMap<Integer, ArrayList<Object>> map =
-                new HashMap<Integer, ArrayList<Object>>();
+            new HashMap<Integer, ArrayList<Object>>();
         public TestMsg() {
             int size = Math.abs(r.nextInt() % 200);
             for (int i=0; i<size; i++ ) {
@@ -115,22 +156,29 @@ public class TestGroupChannelSenderConne
     }
 
     public class TestMsgListener implements ChannelListener {
-        public String name = null;
+        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();
+        }
+
         public void messageReceived(Serializable msg, Member sender) {
-            System.out.println("["+name+"] Received message:"+msg+" from " + sender.getName());
+            counter.incrementAndGet();
+            log.info("["+name+"] Received message:"+msg+" from " + sender.getName());
         }
 
-    
         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


Re: svn commit: r1713158 - /tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2015-11-07 21:35 GMT+03:00 Rémy Maucherat <re...@apache.org>:
> 2015-11-07 18:17 GMT+01:00 <kk...@apache.org>:
>
>> Author: kkolinko
>> Date: Sat Nov  7 17:17:55 2015
>> New Revision: 1713158
>>
>> URL: http://svn.apache.org/viewvc?rev=1713158&view=rev
>> Log:
>> Copy test implementation from Tomcat 7.
>> This a) uses logging instead of System.out,
>> b) validates result of the test and fail()s, instead of just printing a
>> message onto System.out
>>
>> When I voted for CTR on 6, it was agreed upon that only critical fixes
> would go in 6. Obviously, there's no regression risk with the testsuite,
> but what is the rationale with such an upgrade ?

On commit policy
----------
There is no such agreement as "only critical fixes would go in 6"

There was none both either before nor after the CTR vote.

In my opinion, any good fixes that do not introduce new bugs are OK.

Agenda
----------
My ultimate goal is to improve test coverage of Tomcat 6.

There is tomcat6-testing branch that I once started [1], you can look
at BRANCH-README.txt there

[1] https://svn.apache.org/viewvc/tomcat/tc6.0.x/branches/tomcat6-testing/

I do not know whether that goal of adding new tests is reachable.

As the first and simple goal I am reviewing the existing tests,
converting them to JUnit 4
and updating them by using Tomcat 7 as the reference.

I am converting th test to JUnit 4 for the following reasons:
a. It makes it easier to compare current code with Tomcat 7
b. It allows to use @Ignore and assumeX..() to skip tests

Tribes
----------
I am running all the tests locally (starting JUnit from within Eclipse
IDE) so to do not break anything. Initial state before staring this
work was: all tests were completing successfully, except 2 tests in
tribes:

1) o.a.c.tribes.test.channel.TestDataIntegrity.testDataSendASYNCM()  fails with:
junit.framework.AssertionFailedError: Checking success messages.
expected:<10000> but was:<1835>

2) o.a.c.tribes.test.channel.TestRemoteProcessException.testDataSendSYNCACK()
fails with:
ChannelException: Send failed, attempt:2 max:1; Faulty
members:tcp://{my id address here}:4001;

In Tomcat 7 there was some work to investigate test failures and to
improve stability of tribes tests several years ago (in March 2012).
If we are going to keep these tests as part of test suite, I think it
is important to backport those test fixes.

This specific commit (r1713158) is one of those backports.

As just now I am testing TestDataIntegrity, I see that its failure is
not fixed by simple backport of Tomcat 7 changes in the test.  Some
fix in the tribes itself is needed, as the test runs successfully in
Tomcat 7.  Fixing the tribes itself is out of my scope.


My plans on completing the current task
------------------------------------------------------------
1. Convert remaining tests to JUnit 4.  It is almost done, there are
just several of them remaining.

2. If we ever configure to run Tomcat 6 tests automatically, we are
going to skip those failing tests. Tomcat 7 does in its build.xml:

            <!-- Exclude the tests known to fail -->
            <exclude name="org/apache/catalina/tribes/test/**" />

tribes/test/** is a subset of Tribes tests. Most of the test have been
moved to other packages, tribes/group, /io, /membership.

Best regards,
Konstantin Kolinko

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


Re: svn commit: r1713158 - /tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java

Posted by Martin Grigorov <mg...@apache.org>.
On Sat, Nov 7, 2015 at 7:35 PM, Rémy Maucherat <re...@apache.org> wrote:

> 2015-11-07 18:17 GMT+01:00 <kk...@apache.org>:
>
> > Author: kkolinko
> > Date: Sat Nov  7 17:17:55 2015
> > New Revision: 1713158
> >
> > URL: http://svn.apache.org/viewvc?rev=1713158&view=rev
> > Log:
> > Copy test implementation from Tomcat 7.
> > This a) uses logging instead of System.out,
> > b) validates result of the test and fail()s, instead of just printing a
> > message onto System.out
> >
> > When I voted for CTR on 6, it was agreed upon that only critical fixes
> would go in 6. Obviously, there's no regression risk with the testsuite,
> but what is the rationale with such an upgrade ?
>

I've also asked the same myself.
My answer is: to be better prepared for the eventual fixes later :-)


>
> Rémy
>

Re: svn commit: r1713158 - /tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java

Posted by Rémy Maucherat <re...@apache.org>.
2015-11-07 18:17 GMT+01:00 <kk...@apache.org>:

> Author: kkolinko
> Date: Sat Nov  7 17:17:55 2015
> New Revision: 1713158
>
> URL: http://svn.apache.org/viewvc?rev=1713158&view=rev
> Log:
> Copy test implementation from Tomcat 7.
> This a) uses logging instead of System.out,
> b) validates result of the test and fail()s, instead of just printing a
> message onto System.out
>
> When I voted for CTR on 6, it was agreed upon that only critical fixes
would go in 6. Obviously, there's no regression risk with the testsuite,
but what is the rationale with such an upgrade ?

Rémy