Author: kkolinko
Date: Sat Nov 7 16:47:25 2015
New Revision: 1713153
URL: http://svn.apache.org/viewvc?rev=1713153&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/TestGroupChannelMemberArrival.java
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java
Modified:
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java?rev=1713153&r1=1713152&r2=1713153&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java
(original)
+++
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java
Sat Nov 7 16:47:25 2015
@@ -18,26 +18,29 @@ 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 junit.framework.TestCase;
-public class TestGroupChannelMemberArrival
- extends TestCase {
+public class TestGroupChannelMemberArrival {
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"));
listeners[i] = new TestMbrListener( ("Listener-" + (i + 1)));
channels[i].addMembershipListener(listeners[i]);
-
}
}
@@ -47,6 +50,7 @@ public class TestGroupChannelMemberArriv
}
}
+ @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
@@ -54,6 +58,7 @@ public class TestGroupChannelMemberArriv
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);
@@ -71,24 +76,27 @@ public class TestGroupChannelMemberArriv
for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking
member arrival length",channels.length-1,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/TestGroupChannelOptionFlag.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java?rev=1713153&r1=1713152&r2=1713153&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java
(original)
+++
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java
Sat Nov 7 16:47:25 2015
@@ -16,34 +16,41 @@
*/
package org.apache.catalina.tribes.group;
-import junit.framework.*;
-import org.apache.catalina.tribes.ChannelInterceptor;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.catalina.tribes.ChannelException;
+import org.apache.catalina.tribes.ChannelInterceptor;
/**
- * <p>Title: </p>
- *
- * <p>Description: </p>
- *
+ * <p>Title: </p>
+ *
+ * <p>Description: </p>
+ *
* <p>Company: </p>
- *
+ *
* @author not attributable
* @version 1.0
*/
-public class TestGroupChannelOptionFlag extends TestCase {
- GroupChannel channel = null;
- protected void setUp() throws Exception {
- super.setUp();
+public class TestGroupChannelOptionFlag {
+ private GroupChannel channel = null;
+
+ @Before
+ public void setUp() throws Exception {
channel = new GroupChannel();
}
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
if ( channel != null ) try {channel.stop(channel.DEFAULT);}catch (
Exception ignore) {}
channel = null;
}
-
-
+
+ @Test
public void testOptionConflict() throws Exception {
boolean error = false;
channel.setOptionCheck(true);
@@ -58,9 +65,10 @@ public class TestGroupChannelOptionFlag
}catch ( ChannelException x ) {
if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error =
true;
}
- assertEquals(true,error);
+ assertTrue(error);
}
+ @Test
public void testOptionNoConflict() throws Exception {
boolean error = false;
channel.setOptionCheck(true);
@@ -78,11 +86,11 @@ public class TestGroupChannelOptionFlag
}catch ( ChannelException x ) {
if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error =
true;
}
- assertEquals(false,error);
+ assertFalse(error);
}
-
+
public static class TestInterceptor extends ChannelInterceptorBase {
-
+ // Just use base class
}
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=1713153&r1=1713152&r2=1713153&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 16:47:25 2015
@@ -16,25 +16,28 @@
*/
package org.apache.catalina.tribes.group;
+import java.io.Serializable;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Random;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
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 junit.framework.TestCase;
-import org.apache.catalina.tribes.ChannelListener;
-import java.io.Serializable;
-import java.util.Random;
-import java.util.HashMap;
import org.apache.catalina.tribes.transport.ReplicationTransmitter;
-public class TestGroupChannelSenderConnections extends TestCase {
+public class TestGroupChannelSenderConnections {
private static int count = 2;
private ManagedChannel[] channels = new ManagedChannel[count];
private TestMsgListener[] listeners = new TestMsgListener[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"));
@@ -62,10 +65,12 @@ public class TestGroupChannelSenderConne
}
+ @Test
public void testConnectionLinger() throws Exception {
sendMessages(0,15000);
}
+ @Test
public void testKeepAliveCount() throws Exception {
System.out.println("Setting keep alive count to 0");
for (int i = 0; i < channels.length; i++) {
@@ -75,6 +80,7 @@ public class TestGroupChannelSenderConne
sendMessages(1000,15000);
}
+ @Test
public void testKeepAliveTime() throws Exception {
System.out.println("Setting keep alive count to 1 second");
for (int i = 0; i < channels.length; i++) {
@@ -84,22 +90,26 @@ public class TestGroupChannelSenderConne
sendMessages(2000,15000);
}
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
for (int i = 0; i < channels.length; i++) {
channels[i].stop(Channel.DEFAULT);
}
}
-
+
+ // Test message. The message size is random.
public static class TestMsg implements Serializable {
- static Random r = new Random();
- HashMap map = new HashMap();
+ private static final long serialVersionUID = 1L;
+ 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);
for (int i=0; i<size; i++ ) {
int length = Math.abs(r.nextInt() %65000);
- ArrayList list = new ArrayList(length);
- map.put(new Integer(i),list);
+ ArrayList<Object> list = new ArrayList<Object>(length);
+ map.put(Integer.valueOf(i),list);
}
}
}
Modified:
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java
URL:
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java?rev=1713153&r1=1713152&r2=1713153&view=diff
==============================================================================
---
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java
(original)
+++
tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java
Sat Nov 7 16:47:25 2015
@@ -5,35 +5,43 @@
* The ASF licenses this file to You 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.catalina.tribes.group;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import org.apache.catalina.tribes.transport.ReceiverBase;
/**
* @author Filip Hanik
* @version 1.0
*/
-public class TestGroupChannelStartStop extends TestCase {
- GroupChannel channel = null;
- protected void setUp() throws Exception {
- super.setUp();
+public class TestGroupChannelStartStop {
+ private GroupChannel channel = null;
+
+ @Before
+ public void setUp() throws Exception {
channel = new GroupChannel();
}
- protected void tearDown() throws Exception {
- super.tearDown();
- try {channel.stop(channel.DEFAULT);}catch (Exception ignore){}
+ @After
+ public void tearDown() throws Exception {
+ try {channel.stop(channel.DEFAULT);}catch (Exception ignore){ /*
Ignore */ }
}
-
+
+ @Test
public void testDoubleFullStart() throws Exception {
int count = 0;
try {
@@ -48,14 +56,15 @@ public class TestGroupChannelStartStop e
channel.stop(channel.DEFAULT);
}
+ @Test
public void testScrap() throws Exception {
System.out.println(channel.getChannelReceiver().getClass());
((ReceiverBase)channel.getChannelReceiver()).setMaxThreads(1);
- }
-
+ }
+ @Test
public void testDoublePartialStart() throws Exception {
- //try to double start the RX
+ //try to double start the RX
int count = 0;
try {
channel.start(channel.SND_RX_SEQ);
@@ -106,7 +115,8 @@ public class TestGroupChannelStartStop e
assertEquals(count,1);
channel.stop(channel.DEFAULT);
}
-
+
+ @Test
public void testFalseOption() throws Exception {
int flag = 0xFFF0;//should get ignored by the underlying components
int count = 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]