import java.util.ArrayList;
-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.Channel;
import org.apache.catalina.tribes.ManagedChannel;
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.MembershipListener;
-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];
- @Override
- 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"));
}
}
+ @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
for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking member arrival length",channels.length-1,listeners[i].members.size());
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
for (int i = 0; i < channels.length; i++) {
try {
// Ignore
}
}
- super.tearDown();
}
public static class TestMbrListener
*/
package org.apache.catalina.tribes.group;
-import junit.framework.TestCase;
+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.Channel;
import org.apache.catalina.tribes.ChannelException;
* @author not attributable
* @version 1.0
*/
-public class TestGroupChannelOptionFlag extends TestCase {
- GroupChannel channel = null;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+public class TestGroupChannelOptionFlag {
+ private GroupChannel channel = null;
+
+ @Before
+ public void setUp() throws Exception {
channel = new GroupChannel();
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
if ( channel != null ) try {channel.stop(Channel.DEFAULT);}catch ( Exception ignore) { /* Ignore */ }
channel = null;
}
-
-
+
+ @Test
public void testOptionConflict() throws Exception {
boolean error = false;
channel.setOptionCheck(true);
}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);
}catch ( ChannelException x ) {
if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true;
}
- assertEquals(false,error);
+ assertFalse(error);
}
public static class TestInterceptor extends ChannelInterceptorBase {
import java.util.HashMap;
import java.util.Random;
-import junit.framework.TestCase;
+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.Member;
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];
- @Override
- 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"));
}
+ @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++) {
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++) {
sendMessages(2000,15000);
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
for (int i = 0; i < channels.length; i++) {
channels[i].stop(Channel.DEFAULT);
}
*/
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.Channel;
import org.apache.catalina.tribes.transport.ReceiverBase;
* @author Filip Hanik
* @version 1.0
*/
-public class TestGroupChannelStartStop extends TestCase {
- GroupChannel channel = null;
- int udpPort = 45543;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+public class TestGroupChannelStartStop {
+ private GroupChannel channel = null;
+ private int udpPort = 45543;
+
+ @Before
+ public void setUp() throws Exception {
channel = new GroupChannel();
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @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 {
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
int count = 0;
channel.stop(Channel.DEFAULT);
}
+ @Test
public void testFalseOption() throws Exception {
int flag = 0xFFF0;//should get ignored by the underlying components
int count = 0;
channel.stop(Channel.DEFAULT);
}
+ @Test
public void testUdpReceiverStart() throws Exception {
ReceiverBase rb = (ReceiverBase)channel.getChannelReceiver();
rb.setUdpPort(udpPort);
import java.util.ArrayList;
-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.Channel;
import org.apache.catalina.tribes.ManagedChannel;
import org.apache.catalina.tribes.group.GroupChannel;
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];
- @Override
- 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"));
}
}
+ @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
for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking member arrival length",0,listeners[i].members.size());
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
for (int i = 0; i < channels.length; i++) {
try {
// Ignore
}
}
- super.tearDown();
}
public static class TestMbrListener
import java.util.Arrays;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
-public class TestGzipInterceptor extends TestCase {
+import org.junit.Test;
+public class TestGzipInterceptor {
+
+ @Test
public void testSmallerThanBufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE / 2);
}
+ @Test
public void testJustSmallerThanBufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE -1);
}
+ @Test
public void testExactBufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE);
}
+ @Test
public void testJustLargerThanBufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE + 1);
}
+ @Test
public void testFactor2BufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 2);
}
+ @Test
public void testFactor4BufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 4);
}
+ @Test
public void testMuchLargerThanBufferSize() throws Exception {
doCompressDecompress(GzipInterceptor.DEFAULT_BUFFER_SIZE * 10 + 1000);
}
*/
package org.apache.catalina.tribes.group.interceptors;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
+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;
-public class TestNonBlockingCoordinator extends TestCase {
+public class TestNonBlockingCoordinator {
+
+ private GroupChannel[] channels = null;
+ private NonBlockingCoordinator[] coordinators = null;
+ private int channelCount = 10;
+ private Thread[] threads = null;
- GroupChannel[] channels = null;
- NonBlockingCoordinator[] coordinators = null;
- int channelCount = 10;
- Thread[] threads = null;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
System.out.println("Setup");
- super.setUp();
channels = new GroupChannel[channelCount];
coordinators = new NonBlockingCoordinator[channelCount];
threads = new Thread[channelCount];
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);
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);
System.out.println("Coordinator[2b] is:" + member);
}
- @Override
- 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());
+ org.junit.runner.JUnitCore.main(TestNonBlockingCoordinator.class.getName());
}
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
+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.ChannelException;
import org.apache.catalina.tribes.group.GroupChannel;
import org.apache.catalina.tribes.group.InterceptorPayload;
-public class TestOrderInterceptor extends TestCase {
+public class TestOrderInterceptor {
GroupChannel[] channels = null;
OrderInterceptor[] orderitcs = null;
TestListener[] test = null;
int channelCount = 2;
Thread[] threads = null;
- @Override
- 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];
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);
}
Thread.sleep(5000);
for ( int i=0; i<test.length; i++ ) {
- 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);
}
Thread.sleep(5000);
for ( int i=0; i<test.length; i++ ) {
- assertEquals(false,test[i].fail);
+ assertFalse(test[i].fail);
}
}
-
- @Override
- 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 {
import java.util.ArrayList;
-import junit.framework.TestCase;
+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;
* @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;
- @Override
- 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"));
mbrlist1.members.clear();
mbrlist2.members.clear();
}
-
+
+ @Test
public void testTcpSendFailureMemberDrop() throws Exception {
System.out.println("testTcpSendFailureMemberDrop()");
clear();
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
}
channel1.stop(Channel.DEFAULT);
channel2.stop(Channel.DEFAULT);
}
-
+
+ @Test
public void testTcpFailureMemberAdd() throws Exception {
System.out.println("testTcpFailureMemberAdd()");
clear();
channel2.stop(Channel.DEFAULT);
}
+ @Test
public void testTcpMcastFail() throws Exception {
System.out.println("testTcpMcastFail()");
clear();
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);
}
-
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
tcpFailureDetector1 = null;
tcpFailureDetector2 = null;
try { channel1.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ }
channel1 = null;
try { channel2.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ }
channel2 = null;
- super.tearDown();
}
public static class TestMbrListener implements MembershipListener {
*/
package org.apache.catalina.tribes.io;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
-public class TestXByteBuffer extends TestCase {
+import org.junit.Test;
+public class TestXByteBuffer {
+
+ @Test
public void testEmptyArray() throws Exception {
Object obj = XByteBuffer.deserialize(new byte[0]);
assertNull(obj);
}
+ @Test
public void testSerializationString() throws Exception {
String test = "This is as test.";
byte[] msg = XByteBuffer.serialize(test);
import java.util.Arrays;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
/**
* <p>Title: </p>
* @author not attributable
* @version 1.0
*/
-public class TestMemberImplSerialization extends TestCase {
- MemberImpl m1, m2, p1,p2;
- byte[] payload = null;
- int udpPort = 3445;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+public class TestMemberImplSerialization {
+ private MemberImpl m1, m2, p1,p2;
+ private byte[] payload = null;
+ private int udpPort = 3445;
+
+ @Before
+ public void setUp() throws Exception {
payload = new byte[333];
Arrays.fill(payload,(byte)1);
m1 = new MemberImpl("localhost",3333,1,payload);
m1.setUdpPort(udpPort);
m2.setUdpPort(m1.getUdpPort());
}
-
+
+ @Test
public void testCompare() throws Exception {
assertTrue(m1.equals(m2));
assertTrue(m2.equals(m1));
assertFalse(m2.equals(p2));
assertFalse(p1.equals(p2));
}
-
+
+ @Test
public void testUdpPort() throws Exception {
byte[] md1 = m1.getData();
byte[] md2 = m2.getData();
MemberImpl a1 = MemberImpl.getMember(md1);
MemberImpl a2 = MemberImpl.getMember(md2);
- assertEquals(true, a1.getUdpPort()==a2.getUdpPort());
- assertEquals(true,a1.getUdpPort()==udpPort);
+ assertTrue(a1.getUdpPort()==a2.getUdpPort());
+ assertTrue(a1.getUdpPort()==udpPort);
}
-
+
+ @Test
public void testSerializationOne() throws Exception {
MemberImpl m = m1;
byte[] md1 = m.getData(false,true);
*/
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;
import org.apache.catalina.tribes.group.TestGroupChannelMemberArrival;
import org.apache.catalina.tribes.group.TestGroupChannelOptionFlag;
import org.apache.catalina.tribes.test.channel.TestRemoteProcessException;
import org.apache.catalina.tribes.test.channel.TestUdpPackages;
-public class TribesTestSuite
- extends TestCase {
-
- public TribesTestSuite(String s) {
- super(s);
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
+@RunWith(Suite.class)
+@SuiteClasses({
// o.a.catalina.tribes.test.channel
- suite.addTestSuite(TestGroupChannelStartStop.class);
- suite.addTestSuite(TestGroupChannelOptionFlag.class);
- suite.addTestSuite(TestDataIntegrity.class);
- suite.addTestSuite(TestMulticastPackages.class);
- suite.addTestSuite(TestRemoteProcessException.class);
- suite.addTestSuite(TestUdpPackages.class);
+ TestGroupChannelStartStop.class, TestGroupChannelOptionFlag.class,
+ TestDataIntegrity.class, TestMulticastPackages.class,
+ TestRemoteProcessException.class, TestUdpPackages.class,
// o.a.catalina.tribes.test.interceptors
- suite.addTestSuite(TestNonBlockingCoordinator.class);
- suite.addTestSuite(TestOrderInterceptor.class);
+ TestNonBlockingCoordinator.class, TestOrderInterceptor.class,
// o.a.catalina.tribes.test.io
- suite.addTestSuite(TestGroupChannelSenderConnections.class);
- suite.addTestSuite(TestXByteBuffer.class);
+ TestGroupChannelSenderConnections.class, TestXByteBuffer.class,
// o.a.catalina.tribes.test.membership
- suite.addTestSuite(TestMemberImplSerialization.class);
- suite.addTestSuite(TestDomainFilterInterceptor.class);
- suite.addTestSuite(TestGroupChannelMemberArrival.class);
- suite.addTestSuite(TestTcpFailureDetector.class);
- return suite;
- }
+ TestMemberImplSerialization.class, TestDomainFilterInterceptor.class,
+ TestGroupChannelMemberArrival.class, TestTcpFailureDetector.class })
+public class TribesTestSuite {
+
}