Author: kkolinko Date: Sat Nov 7 15:40:03 2015 New Revision: 1713145 URL: http://svn.apache.org/viewvc?rev=1713145&view=rev Log: Convert test classes to JUnit 4 and apply some trivial fixes & formatting from Tomcat 7 Non-trivial fixes will be in separate commits
Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestOrderInterceptor.java tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/TribesTestSuite.java Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java?rev=1713145&r1=1713144&r2=1713145&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java Sat Nov 7 15:40:03 2015 @@ -18,22 +18,26 @@ package org.apache.catalina.tribes.group import java.util.ArrayList; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.ManagedChannel; import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.MembershipListener; import org.apache.catalina.tribes.group.GroupChannel; -import junit.framework.TestCase; import org.apache.catalina.tribes.util.UUIDGenerator; -public class TestDomainFilterInterceptor - extends TestCase { +public class TestDomainFilterInterceptor { private static int count = 10; private ManagedChannel[] channels = new ManagedChannel[count]; private TestMbrListener[] listeners = new TestMbrListener[count]; - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { for (int i = 0; i < channels.length; i++) { channels[i] = new GroupChannel(); channels[i].getMembershipService().setPayload( ("Channel-" + (i + 1)).getBytes("ASCII")); @@ -51,6 +55,7 @@ public class TestDomainFilterInterceptor } } + @Test public void testMemberArrival() throws Exception { //purpose of this test is to make sure that we have received all the members //that we can expect before the start method returns @@ -58,6 +63,7 @@ public class TestDomainFilterInterceptor for (int i=0; i<channels.length; i++ ) { final Channel channel = channels[i]; Thread t = new Thread() { + @Override public void run() { try { channel.start(Channel.DEFAULT); @@ -74,24 +80,26 @@ public class TestDomainFilterInterceptor for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking member arrival length",0,listeners[i].members.size()); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { for (int i = 0; i < channels.length; i++) { try { channels[i].stop(Channel.DEFAULT); - } catch (Exception ignore) {} + } catch (Exception ignore) { + // Ignore + } } - super.tearDown(); } - public class TestMbrListener + public static class TestMbrListener implements MembershipListener { public String name = null; public TestMbrListener(String name) { this.name = name; } - public ArrayList members = new ArrayList(); + public ArrayList<Member> members = new ArrayList<Member>(); public void memberAdded(Member member) { if (!members.contains(member)) { members.add(member); Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java?rev=1713145&r1=1713144&r2=1713145&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java Sat Nov 7 15:40:03 2015 @@ -16,22 +16,26 @@ */ package org.apache.catalina.tribes.group.interceptors; +import static org.junit.Assert.assertEquals; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.group.GroupChannel; -import junit.framework.TestCase; -import junit.framework.TestResult; -import junit.framework.TestSuite; - -public class TestNonBlockingCoordinator extends TestCase { - - GroupChannel[] channels = null; - NonBlockingCoordinator[] coordinators = null; - int channelCount = 10; - Thread[] threads = null; - protected void setUp() throws Exception { + +public class TestNonBlockingCoordinator { + + private GroupChannel[] channels = null; + private NonBlockingCoordinator[] coordinators = null; + private final int channelCount = 10; + private Thread[] threads = null; + + @Before + public void setUp() throws Exception { System.out.println("Setup"); - super.setUp(); channels = new GroupChannel[channelCount]; coordinators = new NonBlockingCoordinator[channelCount]; threads = new Thread[channelCount]; @@ -42,6 +46,7 @@ public class TestNonBlockingCoordinator channels[i].addInterceptor(new TcpFailureDetector()); final int j = i; threads[i] = new Thread() { + @Override public void run() { try { channels[j].start(Channel.DEFAULT); @@ -52,22 +57,39 @@ public class TestNonBlockingCoordinator } }; } - for ( int i=0; i<channelCount; i++ ) threads[i].start(); - for ( int i=0; i<channelCount; i++ ) threads[i].join(); + for (int i = 0; i < channelCount; i++) { + threads[i].start(); + } + for (int i = 0; i < channelCount; i++) { + threads[i].join(); + } Thread.sleep(1000); } - + + @Test public void testCoord1() throws Exception { - for (int i=1; i<channelCount; i++ ) - assertEquals("Message count expected to be equal.",channels[i-1].getMembers().length,channels[i].getMembers().length); + for (int i = 1; i < channelCount; i++) { + assertEquals("Message count expected to be equal.", + channels[i - 1].getMembers().length, + channels[i].getMembers().length); + } Member member = coordinators[0].getCoordinator(); int cnt = 0; - while ( member == null && (cnt++ < 100 ) ) try {Thread.sleep(100); member = coordinators[0].getCoordinator();}catch ( Exception x){} - for (int i=0; i<channelCount; i++ ) super.assertEquals(member,coordinators[i].getCoordinator()); + while (member == null && (cnt++ < 100)) { + try { + Thread.sleep(100); + member = coordinators[0].getCoordinator(); + } catch (Exception x) { + /* Ignore */ + } + } + for (int i=0; i<channelCount; i++ ) { + assertEquals(member,coordinators[i].getCoordinator()); + } System.out.println("Coordinator[1] is:"+member); - } - + + @Test public void testCoord2() throws Exception { Member member = coordinators[1].getCoordinator(); System.out.println("Coordinator[2a] is:" + member); @@ -81,29 +103,27 @@ public class TestNonBlockingCoordinator } int dead = index; Thread.sleep(1000); - if ( index == 0 ) index = 1; else index = 0; + if (index == 0) { + index = 1; + } else { + index = 0; + } System.out.println("Member count:"+channels[index].getMembers().length); member = coordinators[index].getCoordinator(); - for (int i = 1; i < channelCount; i++) if ( i != dead ) super.assertEquals(member, coordinators[i].getCoordinator()); + for (int i = 1; i < channelCount; i++) { + if (i != dead) { + assertEquals(member, coordinators[i].getCoordinator()); + } + } System.out.println("Coordinator[2b] is:" + member); } - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { System.out.println("tearDown"); - super.tearDown(); for ( int i=0; i<channelCount; i++ ) { channels[i].stop(Channel.DEFAULT); } } - - public static void main(String[] args) throws Exception { - TestSuite suite = new TestSuite(); - suite.addTestSuite(TestNonBlockingCoordinator.class); - suite.run(new TestResult()); - } - - - - } Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestOrderInterceptor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestOrderInterceptor.java?rev=1713145&r1=1713144&r2=1713145&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestOrderInterceptor.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestOrderInterceptor.java Sat Nov 7 15:40:03 2015 @@ -16,21 +16,28 @@ */ package org.apache.catalina.tribes.group.interceptors; +import java.io.Serializable; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.apache.catalina.tribes.Channel; -import org.apache.catalina.tribes.Member; -import org.apache.catalina.tribes.group.GroupChannel; -import junit.framework.TestCase; -import junit.framework.TestResult; -import junit.framework.TestSuite; +import org.apache.catalina.tribes.ChannelException; import org.apache.catalina.tribes.ChannelListener; -import java.io.Serializable; -import org.apache.catalina.tribes.group.ChannelInterceptorBase; import org.apache.catalina.tribes.ChannelMessage; +import org.apache.catalina.tribes.Member; +import org.apache.catalina.tribes.group.ChannelInterceptorBase; +import org.apache.catalina.tribes.group.GroupChannel; import org.apache.catalina.tribes.group.InterceptorPayload; -import org.apache.catalina.tribes.ChannelException; -import java.util.concurrent.atomic.AtomicInteger; -public class TestOrderInterceptor extends TestCase { +public class TestOrderInterceptor { GroupChannel[] channels = null; OrderInterceptor[] orderitcs = null; @@ -38,9 +45,10 @@ public class TestOrderInterceptor extend TestListener[] test = null; int channelCount = 2; Thread[] threads = null; - protected void setUp() throws Exception { + + @Before + public void setUp() throws Exception { System.out.println("Setup"); - super.setUp(); channels = new GroupChannel[channelCount]; orderitcs = new OrderInterceptor[channelCount]; mangleitcs = new MangleOrderInterceptor[channelCount]; @@ -48,7 +56,7 @@ public class TestOrderInterceptor extend threads = new Thread[channelCount]; for ( int i=0; i<channelCount; i++ ) { channels[i] = new GroupChannel(); - + orderitcs[i] = new OrderInterceptor(); mangleitcs[i] = new MangleOrderInterceptor(); orderitcs[i].setExpire(Long.MAX_VALUE); @@ -58,6 +66,7 @@ public class TestOrderInterceptor extend channels[i].addChannelListener(test[i]); final int j = i; threads[i] = new Thread() { + @Override public void run() { try { channels[j].start(Channel.DEFAULT); @@ -72,32 +81,34 @@ public class TestOrderInterceptor extend for ( int i=0; i<channelCount; i++ ) threads[i].join(); Thread.sleep(1000); } - + + @Test public void testOrder1() throws Exception { Member[] dest = channels[0].getMembers(); final AtomicInteger value = new AtomicInteger(0); for ( int i=0; i<100; i++ ) { - channels[0].send(dest,new Integer(value.getAndAdd(1)),0); + channels[0].send(dest,Integer.valueOf(value.getAndAdd(1)),0); } Thread.sleep(5000); for ( int i=0; i<test.length; i++ ) { - super.assertEquals(false,test[i].fail); + assertFalse(test[i].fail); } } - + + @Test public void testOrder2() throws Exception { final Member[] dest = channels[0].getMembers(); final AtomicInteger value = new AtomicInteger(0); + final Queue<Exception> exceptionQueue = new ConcurrentLinkedQueue<Exception>(); Runnable run = new Runnable() { public void run() { for (int i = 0; i < 100; i++) { try { synchronized (channels[0]) { - channels[0].send(dest, new Integer(value.getAndAdd(1)), 0); + channels[0].send(dest, Integer.valueOf(value.getAndAdd(1)), 0); } }catch ( Exception x ) { - x.printStackTrace(); - assertEquals(true,false); + exceptionQueue.add(x); } } } @@ -112,27 +123,28 @@ public class TestOrderInterceptor extend for (int i=0;i<threads.length;i++) { threads[i].join(); } + if (!exceptionQueue.isEmpty()) { + fail("Exception while sending in threads: " + + exceptionQueue.remove().toString()); + } Thread.sleep(5000); for ( int i=0; i<test.length; i++ ) { - super.assertEquals(false,test[i].fail); + assertFalse(test[i].fail); } } - - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { System.out.println("tearDown"); - super.tearDown(); for ( int i=0; i<channelCount; i++ ) { channels[i].stop(Channel.DEFAULT); } } - - public static void main(String[] args) throws Exception { - TestSuite suite = new TestSuite(); - suite.addTestSuite(TestOrderInterceptor.class); - suite.run(new TestResult()); + + public static void main(String[] args) { + org.junit.runner.JUnitCore.main(TestOrderInterceptor.class.getName()); } - + public static class TestListener implements ChannelListener { int id = -1; public TestListener(int id) { @@ -140,7 +152,7 @@ public class TestOrderInterceptor extend } int cnt = 0; int total = 0; - boolean fail = false; + volatile boolean fail = false; public synchronized void messageReceived(Serializable msg, Member sender) { total++; Integer i = (Integer)msg; @@ -154,11 +166,11 @@ public class TestOrderInterceptor extend return (msg instanceof Integer); } } - + public static class MangleOrderInterceptor extends ChannelInterceptorBase { - int cnt = 1; ChannelMessage hold = null; Member[] dest = null; + @Override public synchronized void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException { if ( hold == null ) { //System.out.println("Skipping message:"+msg); @@ -175,9 +187,6 @@ public class TestOrderInterceptor extend } } } - - - - + } Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java?rev=1713145&r1=1713144&r2=1713145&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/interceptors/TestTcpFailureDetector.java Sat Nov 7 15:40:03 2015 @@ -18,6 +18,13 @@ package org.apache.catalina.tribes.group import java.util.ArrayList; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + import org.apache.catalina.tribes.ByteMessage; import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.ChannelException; @@ -25,27 +32,27 @@ import org.apache.catalina.tribes.Manage import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.MembershipListener; import org.apache.catalina.tribes.group.GroupChannel; -import junit.framework.TestCase; /** - * <p>Title: </p> - * - * <p>Description: </p> - * + * <p>Title: </p> + * + * <p>Description: </p> + * * <p>Company: </p> - * + * * @author not attributable * @version 1.0 */ -public class TestTcpFailureDetector extends TestCase { +public class TestTcpFailureDetector { private TcpFailureDetector tcpFailureDetector1 = null; private TcpFailureDetector tcpFailureDetector2 = null; private ManagedChannel channel1 = null; private ManagedChannel channel2 = null; private TestMbrListener mbrlist1 = null; private TestMbrListener mbrlist2 = null; - protected void setUp() throws Exception { - super.setUp(); + + @Before + public void setUp() throws Exception { channel1 = new GroupChannel(); channel2 = new GroupChannel(); channel1.getMembershipService().setPayload("Channel-1".getBytes("ASCII")); @@ -59,12 +66,13 @@ public class TestTcpFailureDetector exte channel1.addMembershipListener(mbrlist1); channel2.addMembershipListener(mbrlist2); } - + public void clear() { mbrlist1.members.clear(); mbrlist2.members.clear(); } - + + @Test public void testTcpSendFailureMemberDrop() throws Exception { System.out.println("testTcpSendFailureMemberDrop()"); clear(); @@ -76,15 +84,16 @@ public class TestTcpFailureDetector exte ByteMessage msg = new ByteMessage(new byte[1024]); try { channel1.send(channel1.getMembers(), msg, 0); - assertEquals("Message send should have failed.",true,false); + fail("Message send should have failed."); } catch ( ChannelException x ) { - + // Ignore } assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size()); channel1.stop(Channel.DEFAULT); channel2.stop(Channel.DEFAULT); } - + + @Test public void testTcpFailureMemberAdd() throws Exception { System.out.println("testTcpFailureMemberAdd()"); clear(); @@ -100,6 +109,7 @@ public class TestTcpFailureDetector exte channel2.stop(Channel.DEFAULT); } + @Test public void testTcpMcastFail() throws Exception { System.out.println("testTcpMcastFail()"); clear(); @@ -114,29 +124,28 @@ public class TestTcpFailureDetector exte assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); channel1.send(channel1.getMembers(), msg, 0); } catch ( ChannelException x ) { - assertEquals("Message send should have succeeded.",true,false); + fail("Message send should have succeeded."); } channel1.stop(Channel.DEFAULT); channel2.stop(Channel.DEFAULT); } - - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { tcpFailureDetector1 = null; tcpFailureDetector2 = null; - try { channel1.stop(Channel.DEFAULT);}catch (Exception ignore){} + try { channel1.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ } channel1 = null; - try { channel2.stop(Channel.DEFAULT);}catch (Exception ignore){} + try { channel2.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ } channel2 = null; - super.tearDown(); } - - public class TestMbrListener implements MembershipListener { + + public static class TestMbrListener implements MembershipListener { public String name = null; public TestMbrListener(String name) { this.name = name; } - public ArrayList members = new ArrayList(); + public ArrayList<Member> members = new ArrayList<Member>(); public void memberAdded(Member member) { if ( !members.contains(member) ) { members.add(member); @@ -147,7 +156,7 @@ public class TestTcpFailureDetector exte } } } - + public void memberDisappeared(Member member) { if ( members.contains(member) ) { members.remove(member); @@ -158,7 +167,7 @@ public class TestTcpFailureDetector exte } } } - + } } Modified: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/TribesTestSuite.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/TribesTestSuite.java?rev=1713145&r1=1713144&r2=1713145&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/TribesTestSuite.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/TribesTestSuite.java Sat Nov 7 15:40:03 2015 @@ -16,26 +16,28 @@ */ package org.apache.catalina.tribes.test; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; -public class TribesTestSuite - extends TestCase { +import org.apache.catalina.tribes.group.TestGroupChannelMemberArrival; +import org.apache.catalina.tribes.group.TestGroupChannelOptionFlag; +import org.apache.catalina.tribes.group.TestGroupChannelStartStop; +import org.apache.catalina.tribes.group.interceptors.TestOrderInterceptor; +import org.apache.catalina.tribes.group.interceptors.TestTcpFailureDetector; +import org.apache.catalina.tribes.membership.TestMemberImplSerialization; +import org.apache.catalina.tribes.test.channel.TestDataIntegrity; - public TribesTestSuite(String s) { - super(s); - } +@RunWith(Suite.class) +@SuiteClasses({ + TestGroupChannelStartStop.class, + TestGroupChannelOptionFlag.class, + TestMemberImplSerialization.class, + TestGroupChannelMemberArrival.class, + TestTcpFailureDetector.class, + TestDataIntegrity.class, + TestOrderInterceptor.class +}) +public class TribesTestSuite { - public static Test suite() { - TestSuite suite = new TestSuite(); - suite.addTestSuite(org.apache.catalina.tribes.group.TestGroupChannelStartStop.class); - suite.addTestSuite(org.apache.catalina.tribes.group.TestGroupChannelOptionFlag.class); - suite.addTestSuite(org.apache.catalina.tribes.membership.TestMemberImplSerialization.class); - suite.addTestSuite(org.apache.catalina.tribes.group.TestGroupChannelMemberArrival.class); - suite.addTestSuite(org.apache.catalina.tribes.group.interceptors.TestTcpFailureDetector.class); - suite.addTestSuite(org.apache.catalina.tribes.test.channel.TestDataIntegrity.class); - suite.addTestSuite(org.apache.catalina.tribes.group.interceptors.TestOrderInterceptor.class); - return suite; - } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org