From: markt Date: Tue, 5 Jul 2011 12:06:04 +0000 (+0000) Subject: Move working JUnit tests to align with package of class being tested. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7e71adc3d7a50cf3ec9ec34d6d3656081bd32caa;p=tomcat7.0 Move working JUnit tests to align with package of class being tested. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1143016 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java b/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java new file mode 100644 index 000000000..aa6f9a642 --- /dev/null +++ b/test/org/apache/catalina/tribes/group/TestGroupChannelMemberArrival.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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 java.util.ArrayList; + +import junit.framework.TestCase; + +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 { + 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(); + 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]); + + } + } + + public void clear() { + for (int i = 0; i < channels.length; i++) { + listeners[i].members.clear(); + } + } + + 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 + Thread[] threads = new Thread[channels.length]; + for (int i=0; i=0; i-- ) assertEquals("Checking member arrival length",channels.length-1,listeners[i].members.size()); + } + + @Override + protected void tearDown() throws Exception { + + for (int i = 0; i < channels.length; i++) { + try { + channels[i].stop(Channel.DEFAULT); + } catch (Exception ignore) { + // Ignore + } + } + super.tearDown(); + } + + public static class TestMbrListener + implements MembershipListener { + public String name = null; + public TestMbrListener(String name) { + this.name = name; + } + + public ArrayList members = new ArrayList(); + @Override + public void memberAdded(Member member) { + if (!members.contains(member)) { + members.add(member); + try { + System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); + } catch (Exception x) { + System.out.println(name + ":member added[unknown]"); + } + } + } + + @Override + public void memberDisappeared(Member member) { + if (members.contains(member)) { + members.remove(member); + try { + System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); + } catch (Exception x) { + System.out.println(name + ":member disappeared[unknown]"); + } + } + } + + } + +} diff --git a/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java b/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java new file mode 100644 index 000000000..dc855e833 --- /dev/null +++ b/test/org/apache/catalina/tribes/group/TestGroupChannelOptionFlag.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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 org.apache.catalina.tribes.Channel; +import org.apache.catalina.tribes.ChannelException; +import org.apache.catalina.tribes.ChannelInterceptor; + +/** + *

Title:

+ * + *

Description:

+ * + *

Company:

+ * + * @author not attributable + * @version 1.0 + */ +public class TestGroupChannelOptionFlag extends TestCase { + GroupChannel channel = null; + @Override + protected void setUp() throws Exception { + super.setUp(); + channel = new GroupChannel(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + if ( channel != null ) try {channel.stop(Channel.DEFAULT);}catch ( Exception ignore) { /* Ignore */ } + channel = null; + } + + + public void testOptionConflict() throws Exception { + boolean error = false; + channel.setOptionCheck(true); + ChannelInterceptor i = new TestInterceptor(); + i.setOptionFlag(128); + channel.addInterceptor(i); + i = new TestInterceptor(); + i.setOptionFlag(128); + channel.addInterceptor(i); + try { + channel.start(Channel.DEFAULT); + }catch ( ChannelException x ) { + if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true; + } + assertEquals(true,error); + } + + public void testOptionNoConflict() throws Exception { + boolean error = false; + channel.setOptionCheck(true); + ChannelInterceptor i = new TestInterceptor(); + i.setOptionFlag(128); + channel.addInterceptor(i); + i = new TestInterceptor(); + i.setOptionFlag(64); + channel.addInterceptor(i); + i = new TestInterceptor(); + i.setOptionFlag(256); + channel.addInterceptor(i); + try { + channel.start(Channel.DEFAULT); + }catch ( ChannelException x ) { + if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true; + } + assertEquals(false,error); + } + + public static class TestInterceptor extends ChannelInterceptorBase { + // Just use base class + } + + +} diff --git a/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java b/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java new file mode 100644 index 000000000..d32411de9 --- /dev/null +++ b/test/org/apache/catalina/tribes/group/TestGroupChannelSenderConnections.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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 java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Random; + +import junit.framework.TestCase; + +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 extends TestCase { + 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(); + 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() + "]"); + for (int i = 0; i < n; i++) { + channels[0].send(new Member[] {dest}, new TestMsg(), 0); + if ( delay > 0 ) Thread.sleep(delay); + } + System.out.println("Messages sent. Sleeping for "+(sleep/1000)+" seconds to inspect connections"); + if ( sleep > 0 ) Thread.sleep(sleep); + + } + + public void testConnectionLinger() throws Exception { + sendMessages(0,15000); + } + + public void testKeepAliveCount() throws Exception { + System.out.println("Setting keep alive count to 0"); + for (int i = 0; i < channels.length; i++) { + ReplicationTransmitter t = (ReplicationTransmitter)channels[0].getChannelSender(); + t.getTransport().setKeepAliveCount(0); + } + sendMessages(1000,15000); + } + + public void testKeepAliveTime() throws Exception { + System.out.println("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); + } + sendMessages(2000,15000); + } + + @Override + protected void tearDown() throws Exception { + for (int i = 0; i < channels.length; i++) { + channels[i].stop(Channel.DEFAULT); + } + + } + + public static class TestMsg implements Serializable { + private static final long serialVersionUID = 1L; + static Random r = new Random(); + HashMap> map = + new HashMap>(); + public TestMsg() { + int size = Math.abs(r.nextInt() % 200); + for (int i=0; i list = new ArrayList(length); + map.put(Integer.valueOf(i),list); + } + } + } + + public static class TestMsgListener implements ChannelListener { + public String name = null; + 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()); + } + + + @Override + public boolean accept(Serializable msg, Member sender) { + return true; + } + + + } + +} diff --git a/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java b/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java new file mode 100644 index 000000000..070126dbc --- /dev/null +++ b/test/org/apache/catalina/tribes/group/TestGroupChannelStartStop.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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 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(); + channel = new GroupChannel(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + try {channel.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ } + } + + public void testDoubleFullStart() throws Exception { + int count = 0; + try { + channel.start(Channel.DEFAULT); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(Channel.DEFAULT); + count++; + } catch ( Exception x){x.printStackTrace();} + assertEquals(count,2); + channel.stop(Channel.DEFAULT); + } + + public void testScrap() throws Exception { + System.out.println(channel.getChannelReceiver().getClass()); + ((ReceiverBase)channel.getChannelReceiver()).setMaxThreads(1); + } + + + public void testDoublePartialStart() throws Exception { + //try to double start the RX + int count = 0; + try { + channel.start(Channel.SND_RX_SEQ); + channel.start(Channel.MBR_RX_SEQ); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(Channel.MBR_RX_SEQ); + count++; + } catch ( Exception x){/*expected*/} + assertEquals(count,1); + channel.stop(Channel.DEFAULT); + //double the membership sender + count = 0; + try { + channel.start(Channel.SND_RX_SEQ); + channel.start(Channel.MBR_TX_SEQ); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(Channel.MBR_TX_SEQ); + count++; + } catch ( Exception x){/*expected*/} + assertEquals(count,1); + channel.stop(Channel.DEFAULT); + + count = 0; + try { + channel.start(Channel.SND_RX_SEQ); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(Channel.SND_RX_SEQ); + count++; + } catch ( Exception x){/*expected*/} + assertEquals(count,1); + channel.stop(Channel.DEFAULT); + + count = 0; + try { + channel.start(Channel.SND_TX_SEQ); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(Channel.SND_TX_SEQ); + count++; + } catch ( Exception x){/*expected*/} + assertEquals(count,1); + channel.stop(Channel.DEFAULT); + } + + public void testFalseOption() throws Exception { + int flag = 0xFFF0;//should get ignored by the underlying components + int count = 0; + try { + channel.start(flag); + count++; + } catch ( Exception x){x.printStackTrace();} + try { + channel.start(flag); + count++; + } catch ( Exception x){/*expected*/} + assertEquals(count,2); + channel.stop(Channel.DEFAULT); + } + + public void testUdpReceiverStart() throws Exception { + ReceiverBase rb = (ReceiverBase)channel.getChannelReceiver(); + rb.setUdpPort(udpPort); + channel.start(Channel.DEFAULT); + Thread.sleep(1000); + channel.stop(Channel.DEFAULT); + } + +} diff --git a/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java b/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java new file mode 100644 index 000000000..fbf2c472d --- /dev/null +++ b/test/org/apache/catalina/tribes/group/interceptors/TestDomainFilterInterceptor.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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.interceptors; + +import java.util.ArrayList; + +import junit.framework.TestCase; + +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 org.apache.catalina.tribes.util.UUIDGenerator; + +public class TestDomainFilterInterceptor + extends TestCase { + 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(); + 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]); + DomainFilterInterceptor filter = new DomainFilterInterceptor(); + filter.setDomain(UUIDGenerator.randomUUID(false)); + channels[i].addInterceptor(filter); + } + } + + public void clear() { + for (int i = 0; i < channels.length; i++) { + listeners[i].members.clear(); + } + } + + 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 + Thread[] threads = new Thread[channels.length]; + for (int i=0; i=0; i-- ) assertEquals("Checking member arrival length",0,listeners[i].members.size()); + } + + @Override + protected void tearDown() throws Exception { + + for (int i = 0; i < channels.length; i++) { + try { + channels[i].stop(Channel.DEFAULT); + } catch (Exception ignore) { + // Ignore + } + } + super.tearDown(); + } + + public static class TestMbrListener + implements MembershipListener { + public String name = null; + public TestMbrListener(String name) { + this.name = name; + } + + public ArrayList members = new ArrayList(); + @Override + public void memberAdded(Member member) { + if (!members.contains(member)) { + members.add(member); + try { + System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); + } catch (Exception x) { + System.out.println(name + ":member added[unknown]"); + } + } + } + + @Override + public void memberDisappeared(Member member) { + if (members.contains(member)) { + members.remove(member); + try { + System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); + } catch (Exception x) { + System.out.println(name + ":member disappeared[unknown]"); + } + } + } + + } + +} diff --git a/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java b/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java new file mode 100644 index 000000000..828b95cd1 --- /dev/null +++ b/test/org/apache/catalina/tribes/group/interceptors/TestNonBlockingCoordinator.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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.interceptors; + +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +import org.apache.catalina.tribes.Channel; +import org.apache.catalina.tribes.Member; +import org.apache.catalina.tribes.group.GroupChannel; + +public class TestNonBlockingCoordinator extends TestCase { + + GroupChannel[] channels = null; + NonBlockingCoordinator[] coordinators = null; + int channelCount = 10; + Thread[] threads = null; + @Override + protected 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 exceptionQueue = new ConcurrentLinkedQueue(); + Runnable run = new Runnable() { + @Override + public void run() { + for (int i = 0; i < 100; i++) { + try { + synchronized (channels[0]) { + channels[0].send(dest, Integer.valueOf(value.getAndAdd(1)), 0); + } + }catch ( Exception x ) { + exceptionQueue.add(x); + } + } + } + }; + Thread[] threads = new Thread[5]; + for (int i=0;iTitle:

+ * + *

Description:

+ * + *

Company:

+ * + * @author not attributable + * @version 1.0 + */ +public class TestTcpFailureDetector extends TestCase { + 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(); + channel1 = new GroupChannel(); + channel2 = new GroupChannel(); + channel1.getMembershipService().setPayload("Channel-1".getBytes("ASCII")); + channel2.getMembershipService().setPayload("Channel-2".getBytes("ASCII")); + mbrlist1 = new TestMbrListener("Channel-1"); + mbrlist2 = new TestMbrListener("Channel-2"); + tcpFailureDetector1 = new TcpFailureDetector(); + tcpFailureDetector2 = new TcpFailureDetector(); + channel1.addInterceptor(tcpFailureDetector1); + channel2.addInterceptor(tcpFailureDetector2); + channel1.addMembershipListener(mbrlist1); + channel2.addMembershipListener(mbrlist2); + } + + public void clear() { + mbrlist1.members.clear(); + mbrlist2.members.clear(); + } + + public void testTcpSendFailureMemberDrop() throws Exception { + System.out.println("testTcpSendFailureMemberDrop()"); + clear(); + channel1.start(Channel.DEFAULT); + channel2.start(Channel.DEFAULT); + //Thread.sleep(1000); + assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); + channel2.stop(Channel.SND_RX_SEQ); + ByteMessage msg = new ByteMessage(new byte[1024]); + try { + channel1.send(channel1.getMembers(), msg, 0); + assertEquals("Message send should have failed.",true,false); + } 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); + } + + public void testTcpFailureMemberAdd() throws Exception { + System.out.println("testTcpFailureMemberAdd()"); + clear(); + channel1.start(Channel.DEFAULT); + channel2.start(Channel.SND_RX_SEQ); + channel2.start(Channel.SND_TX_SEQ); + channel2.start(Channel.MBR_RX_SEQ); + channel2.stop(Channel.SND_RX_SEQ); + channel2.start(Channel.MBR_TX_SEQ); + //Thread.sleep(1000); + assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size()); + channel1.stop(Channel.DEFAULT); + channel2.stop(Channel.DEFAULT); + } + + public void testTcpMcastFail() throws Exception { + System.out.println("testTcpMcastFail()"); + clear(); + channel1.start(Channel.DEFAULT); + channel2.start(Channel.DEFAULT); + //Thread.sleep(1000); + assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); + channel2.stop(Channel.MBR_TX_SEQ); + ByteMessage msg = new ByteMessage(new byte[1024]); + try { + Thread.sleep(5000); + 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); + } + channel1.stop(Channel.DEFAULT); + channel2.stop(Channel.DEFAULT); + } + + + @Override + protected 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 { + public String name = null; + public TestMbrListener(String name) { + this.name = name; + } + public ArrayList members = new ArrayList(); + @Override + public void memberAdded(Member member) { + if ( !members.contains(member) ) { + members.add(member); + try{ + System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "]"); + }catch ( Exception x ) { + System.out.println(name + ":member added[unknown]"); + } + } + } + + @Override + public void memberDisappeared(Member member) { + if ( members.contains(member) ) { + members.remove(member); + try{ + System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "]"); + }catch ( Exception x ) { + System.out.println(name + ":member disappeared[unknown]"); + } + } + } + + } + +} diff --git a/test/org/apache/catalina/tribes/io/TestXByteBuffer.java b/test/org/apache/catalina/tribes/io/TestXByteBuffer.java new file mode 100644 index 000000000..9704ccf9c --- /dev/null +++ b/test/org/apache/catalina/tribes/io/TestXByteBuffer.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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.io; + +import junit.framework.TestCase; + +public class TestXByteBuffer extends TestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + public void testEmptyArray() throws Exception { + // TODO + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public static void main(String[] args) throws Exception { + //XByteBuffer.deserialize(new byte[0]); + XByteBuffer.deserialize(new byte[] {-84, -19, 0, 5, 115, 114, 0, 17, 106}); + } + +} diff --git a/test/org/apache/catalina/tribes/membership/TestMemberImplSerialization.java b/test/org/apache/catalina/tribes/membership/TestMemberImplSerialization.java new file mode 100644 index 000000000..4d070603d --- /dev/null +++ b/test/org/apache/catalina/tribes/membership/TestMemberImplSerialization.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * 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.membership; + +import java.util.Arrays; + +import junit.framework.TestCase; + +/** + *

Title:

+ * + *

Description:

+ * + *

Company:

+ * + * @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(); + payload = new byte[333]; + Arrays.fill(payload,(byte)1); + m1 = new MemberImpl("localhost",3333,1,payload); + m2 = new MemberImpl("localhost",3333,1); + payload = new byte[333]; + Arrays.fill(payload,(byte)2); + p1 = new MemberImpl("127.0.0.1",3333,1,payload); + p2 = new MemberImpl("localhost",3331,1,payload); + m1.setDomain(new byte[] {1,2,3,4,5,6,7,8,9}); + m2.setDomain(new byte[] {1,2,3,4,5,6,7,8,9}); + m1.setCommand(new byte[] {1,2,4,5,6,7,8,9}); + m2.setCommand(new byte[] {1,2,4,5,6,7,8,9}); + m1.setUdpPort(udpPort); + m2.setUdpPort(m1.getUdpPort()); + } + + public void testCompare() throws Exception { + assertTrue(m1.equals(m2)); + assertTrue(m2.equals(m1)); + assertTrue(p1.equals(m2)); + assertFalse(m1.equals(p2)); + assertFalse(m1.equals(p2)); + assertFalse(m2.equals(p2)); + assertFalse(p1.equals(p2)); + } + + 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); + } + + public void testSerializationOne() throws Exception { + MemberImpl m = m1; + byte[] md1 = m.getData(false,true); + byte[] mda1 = m.getData(false,false); + assertTrue(Arrays.equals(md1,mda1)); + assertTrue(md1==mda1); + mda1 = m.getData(true,true); + MemberImpl ma1 = MemberImpl.getMember(mda1); + assertTrue(compareMembers(m,ma1)); + mda1 = p1.getData(false); + assertFalse(Arrays.equals(md1,mda1)); + ma1 = MemberImpl.getMember(mda1); + assertTrue(compareMembers(p1,ma1)); + + md1 = m.getData(true,true); + Thread.sleep(50); + mda1 = m.getData(true,true); + MemberImpl a1 = MemberImpl.getMember(md1); + MemberImpl a2 = MemberImpl.getMember(mda1); + assertTrue(a1.equals(a2)); + assertFalse(Arrays.equals(md1,mda1)); + + + } + + public boolean compareMembers(MemberImpl impl1, MemberImpl impl2) { + boolean result = true; + result = result && Arrays.equals(impl1.getHost(),impl2.getHost()); + result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload()); + result = result && Arrays.equals(impl1.getUniqueId(),impl2.getUniqueId()); + result = result && impl1.getPort() == impl2.getPort(); + return result; + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/test/org/apache/catalina/tribes/test/TribesTestSuite.java b/test/org/apache/catalina/tribes/test/TribesTestSuite.java index 48b9eebd5..f9bce6591 100644 --- a/test/org/apache/catalina/tribes/test/TribesTestSuite.java +++ b/test/org/apache/catalina/tribes/test/TribesTestSuite.java @@ -20,20 +20,20 @@ import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; -import org.apache.catalina.tribes.test.channel.TestChannelOptionFlag; -import org.apache.catalina.tribes.test.channel.TestChannelStartStop; +import org.apache.catalina.tribes.group.TestGroupChannelMemberArrival; +import org.apache.catalina.tribes.group.TestGroupChannelOptionFlag; +import org.apache.catalina.tribes.group.TestGroupChannelSenderConnections; +import org.apache.catalina.tribes.group.TestGroupChannelStartStop; +import org.apache.catalina.tribes.group.interceptors.TestDomainFilterInterceptor; +import org.apache.catalina.tribes.group.interceptors.TestNonBlockingCoordinator; +import org.apache.catalina.tribes.group.interceptors.TestOrderInterceptor; +import org.apache.catalina.tribes.group.interceptors.TestTcpFailureDetector; +import org.apache.catalina.tribes.io.TestXByteBuffer; +import org.apache.catalina.tribes.membership.TestMemberImplSerialization; import org.apache.catalina.tribes.test.channel.TestDataIntegrity; import org.apache.catalina.tribes.test.channel.TestMulticastPackages; import org.apache.catalina.tribes.test.channel.TestRemoteProcessException; import org.apache.catalina.tribes.test.channel.TestUdpPackages; -import org.apache.catalina.tribes.test.interceptors.TestNonBlockingCoordinator; -import org.apache.catalina.tribes.test.interceptors.TestOrderInterceptor; -import org.apache.catalina.tribes.test.io.TestSenderConnections; -import org.apache.catalina.tribes.test.io.TestSerialization; -import org.apache.catalina.tribes.test.membership.TestDomainFilter; -import org.apache.catalina.tribes.test.membership.TestMemberArrival; -import org.apache.catalina.tribes.test.membership.TestMemberSerialization; -import org.apache.catalina.tribes.test.membership.TestTcpFailureDetector; public class TribesTestSuite extends TestCase { @@ -45,8 +45,8 @@ public class TribesTestSuite public static Test suite() { TestSuite suite = new TestSuite(); // o.a.catalina.tribes.test.channel - suite.addTestSuite(TestChannelStartStop.class); - suite.addTestSuite(TestChannelOptionFlag.class); + suite.addTestSuite(TestGroupChannelStartStop.class); + suite.addTestSuite(TestGroupChannelOptionFlag.class); suite.addTestSuite(TestDataIntegrity.class); suite.addTestSuite(TestMulticastPackages.class); suite.addTestSuite(TestRemoteProcessException.class); @@ -55,12 +55,12 @@ public class TribesTestSuite suite.addTestSuite(TestNonBlockingCoordinator.class); suite.addTestSuite(TestOrderInterceptor.class); // o.a.catalina.tribes.test.io - suite.addTestSuite(TestSenderConnections.class); - suite.addTestSuite(TestSerialization.class); + suite.addTestSuite(TestGroupChannelSenderConnections.class); + suite.addTestSuite(TestXByteBuffer.class); // o.a.catalina.tribes.test.membership - suite.addTestSuite(TestMemberSerialization.class); - suite.addTestSuite(TestDomainFilter.class); - suite.addTestSuite(TestMemberArrival.class); + suite.addTestSuite(TestMemberImplSerialization.class); + suite.addTestSuite(TestDomainFilterInterceptor.class); + suite.addTestSuite(TestGroupChannelMemberArrival.class); suite.addTestSuite(TestTcpFailureDetector.class); return suite; } diff --git a/test/org/apache/catalina/tribes/test/channel/TestChannelOptionFlag.java b/test/org/apache/catalina/tribes/test/channel/TestChannelOptionFlag.java deleted file mode 100644 index 85324ec19..000000000 --- a/test/org/apache/catalina/tribes/test/channel/TestChannelOptionFlag.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.channel; - -import junit.framework.TestCase; - -import org.apache.catalina.tribes.Channel; -import org.apache.catalina.tribes.ChannelException; -import org.apache.catalina.tribes.ChannelInterceptor; -import org.apache.catalina.tribes.group.ChannelInterceptorBase; -import org.apache.catalina.tribes.group.GroupChannel; - -/** - *

Title:

- * - *

Description:

- * - *

Company:

- * - * @author not attributable - * @version 1.0 - */ -public class TestChannelOptionFlag extends TestCase { - GroupChannel channel = null; - @Override - protected void setUp() throws Exception { - super.setUp(); - channel = new GroupChannel(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - if ( channel != null ) try {channel.stop(Channel.DEFAULT);}catch ( Exception ignore) { /* Ignore */ } - channel = null; - } - - - public void testOptionConflict() throws Exception { - boolean error = false; - channel.setOptionCheck(true); - ChannelInterceptor i = new TestInterceptor(); - i.setOptionFlag(128); - channel.addInterceptor(i); - i = new TestInterceptor(); - i.setOptionFlag(128); - channel.addInterceptor(i); - try { - channel.start(Channel.DEFAULT); - }catch ( ChannelException x ) { - if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true; - } - assertEquals(true,error); - } - - public void testOptionNoConflict() throws Exception { - boolean error = false; - channel.setOptionCheck(true); - ChannelInterceptor i = new TestInterceptor(); - i.setOptionFlag(128); - channel.addInterceptor(i); - i = new TestInterceptor(); - i.setOptionFlag(64); - channel.addInterceptor(i); - i = new TestInterceptor(); - i.setOptionFlag(256); - channel.addInterceptor(i); - try { - channel.start(Channel.DEFAULT); - }catch ( ChannelException x ) { - if ( x.getMessage().indexOf("option flag conflict") >= 0 ) error = true; - } - assertEquals(false,error); - } - - public static class TestInterceptor extends ChannelInterceptorBase { - // Just use base class - } - - -} diff --git a/test/org/apache/catalina/tribes/test/channel/TestChannelStartStop.java b/test/org/apache/catalina/tribes/test/channel/TestChannelStartStop.java deleted file mode 100644 index d77f43306..000000000 --- a/test/org/apache/catalina/tribes/test/channel/TestChannelStartStop.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.channel; - -import junit.framework.TestCase; - -import org.apache.catalina.tribes.Channel; -import org.apache.catalina.tribes.group.GroupChannel; -import org.apache.catalina.tribes.transport.ReceiverBase; - -/** - * @author Filip Hanik - * @version 1.0 - */ -public class TestChannelStartStop extends TestCase { - GroupChannel channel = null; - int udpPort = 45543; - @Override - protected void setUp() throws Exception { - super.setUp(); - channel = new GroupChannel(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - try {channel.stop(Channel.DEFAULT);}catch (Exception ignore){ /* Ignore */ } - } - - public void testDoubleFullStart() throws Exception { - int count = 0; - try { - channel.start(Channel.DEFAULT); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(Channel.DEFAULT); - count++; - } catch ( Exception x){x.printStackTrace();} - assertEquals(count,2); - channel.stop(Channel.DEFAULT); - } - - public void testScrap() throws Exception { - System.out.println(channel.getChannelReceiver().getClass()); - ((ReceiverBase)channel.getChannelReceiver()).setMaxThreads(1); - } - - - public void testDoublePartialStart() throws Exception { - //try to double start the RX - int count = 0; - try { - channel.start(Channel.SND_RX_SEQ); - channel.start(Channel.MBR_RX_SEQ); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(Channel.MBR_RX_SEQ); - count++; - } catch ( Exception x){/*expected*/} - assertEquals(count,1); - channel.stop(Channel.DEFAULT); - //double the membership sender - count = 0; - try { - channel.start(Channel.SND_RX_SEQ); - channel.start(Channel.MBR_TX_SEQ); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(Channel.MBR_TX_SEQ); - count++; - } catch ( Exception x){/*expected*/} - assertEquals(count,1); - channel.stop(Channel.DEFAULT); - - count = 0; - try { - channel.start(Channel.SND_RX_SEQ); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(Channel.SND_RX_SEQ); - count++; - } catch ( Exception x){/*expected*/} - assertEquals(count,1); - channel.stop(Channel.DEFAULT); - - count = 0; - try { - channel.start(Channel.SND_TX_SEQ); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(Channel.SND_TX_SEQ); - count++; - } catch ( Exception x){/*expected*/} - assertEquals(count,1); - channel.stop(Channel.DEFAULT); - } - - public void testFalseOption() throws Exception { - int flag = 0xFFF0;//should get ignored by the underlying components - int count = 0; - try { - channel.start(flag); - count++; - } catch ( Exception x){x.printStackTrace();} - try { - channel.start(flag); - count++; - } catch ( Exception x){/*expected*/} - assertEquals(count,2); - channel.stop(Channel.DEFAULT); - } - - public void testUdpReceiverStart() throws Exception { - ReceiverBase rb = (ReceiverBase)channel.getChannelReceiver(); - rb.setUdpPort(udpPort); - channel.start(Channel.DEFAULT); - Thread.sleep(1000); - channel.stop(Channel.DEFAULT); - } - -} diff --git a/test/org/apache/catalina/tribes/test/interceptors/TestNonBlockingCoordinator.java b/test/org/apache/catalina/tribes/test/interceptors/TestNonBlockingCoordinator.java deleted file mode 100644 index f1e2c2796..000000000 --- a/test/org/apache/catalina/tribes/test/interceptors/TestNonBlockingCoordinator.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.interceptors; - -import junit.framework.TestCase; -import junit.framework.TestResult; -import junit.framework.TestSuite; - -import org.apache.catalina.tribes.Channel; -import org.apache.catalina.tribes.Member; -import org.apache.catalina.tribes.group.GroupChannel; -import org.apache.catalina.tribes.group.interceptors.NonBlockingCoordinator; -import org.apache.catalina.tribes.group.interceptors.TcpFailureDetector; - -public class TestNonBlockingCoordinator extends TestCase { - - GroupChannel[] channels = null; - NonBlockingCoordinator[] coordinators = null; - int channelCount = 10; - Thread[] threads = null; - @Override - protected 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 exceptionQueue = new ConcurrentLinkedQueue(); - Runnable run = new Runnable() { - @Override - public void run() { - for (int i = 0; i < 100; i++) { - try { - synchronized (channels[0]) { - channels[0].send(dest, Integer.valueOf(value.getAndAdd(1)), 0); - } - }catch ( Exception x ) { - exceptionQueue.add(x); - } - } - } - }; - Thread[] threads = new Thread[5]; - for (int i=0;i 0 ) Thread.sleep(delay); - } - System.out.println("Messages sent. Sleeping for "+(sleep/1000)+" seconds to inspect connections"); - if ( sleep > 0 ) Thread.sleep(sleep); - - } - - public void testConnectionLinger() throws Exception { - sendMessages(0,15000); - } - - public void testKeepAliveCount() throws Exception { - System.out.println("Setting keep alive count to 0"); - for (int i = 0; i < channels.length; i++) { - ReplicationTransmitter t = (ReplicationTransmitter)channels[0].getChannelSender(); - t.getTransport().setKeepAliveCount(0); - } - sendMessages(1000,15000); - } - - public void testKeepAliveTime() throws Exception { - System.out.println("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); - } - sendMessages(2000,15000); - } - - @Override - protected void tearDown() throws Exception { - for (int i = 0; i < channels.length; i++) { - channels[i].stop(Channel.DEFAULT); - } - - } - - public static class TestMsg implements Serializable { - private static final long serialVersionUID = 1L; - static Random r = new Random(); - HashMap> map = - new HashMap>(); - public TestMsg() { - int size = Math.abs(r.nextInt() % 200); - for (int i=0; i list = new ArrayList(length); - map.put(Integer.valueOf(i),list); - } - } - } - - public static class TestMsgListener implements ChannelListener { - public String name = null; - 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()); - } - - - @Override - public boolean accept(Serializable msg, Member sender) { - return true; - } - - - } - -} diff --git a/test/org/apache/catalina/tribes/test/io/TestSerialization.java b/test/org/apache/catalina/tribes/test/io/TestSerialization.java deleted file mode 100644 index 378bf8a18..000000000 --- a/test/org/apache/catalina/tribes/test/io/TestSerialization.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.io; - -import junit.framework.TestCase; - -import org.apache.catalina.tribes.io.XByteBuffer; - -public class TestSerialization extends TestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - public void testEmptyArray() throws Exception { - // TODO - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public static void main(String[] args) throws Exception { - //XByteBuffer.deserialize(new byte[0]); - XByteBuffer.deserialize(new byte[] {-84, -19, 0, 5, 115, 114, 0, 17, 106}); - } - -} diff --git a/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java b/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java deleted file mode 100644 index 19c5cefd1..000000000 --- a/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.membership; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -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 org.apache.catalina.tribes.group.interceptors.DomainFilterInterceptor; -import org.apache.catalina.tribes.util.UUIDGenerator; - -public class TestDomainFilter - extends TestCase { - 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(); - 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]); - DomainFilterInterceptor filter = new DomainFilterInterceptor(); - filter.setDomain(UUIDGenerator.randomUUID(false)); - channels[i].addInterceptor(filter); - } - } - - public void clear() { - for (int i = 0; i < channels.length; i++) { - listeners[i].members.clear(); - } - } - - 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 - Thread[] threads = new Thread[channels.length]; - for (int i=0; i=0; i-- ) assertEquals("Checking member arrival length",0,listeners[i].members.size()); - } - - @Override - protected void tearDown() throws Exception { - - for (int i = 0; i < channels.length; i++) { - try { - channels[i].stop(Channel.DEFAULT); - } catch (Exception ignore) { - // Ignore - } - } - super.tearDown(); - } - - public static class TestMbrListener - implements MembershipListener { - public String name = null; - public TestMbrListener(String name) { - this.name = name; - } - - public ArrayList members = new ArrayList(); - @Override - public void memberAdded(Member member) { - if (!members.contains(member)) { - members.add(member); - try { - System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); - } catch (Exception x) { - System.out.println(name + ":member added[unknown]"); - } - } - } - - @Override - public void memberDisappeared(Member member) { - if (members.contains(member)) { - members.remove(member); - try { - System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); - } catch (Exception x) { - System.out.println(name + ":member disappeared[unknown]"); - } - } - } - - } - -} diff --git a/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java b/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java deleted file mode 100644 index 3fb99f032..000000000 --- a/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.membership; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -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; - -public class TestMemberArrival - extends TestCase { - 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(); - 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]); - - } - } - - public void clear() { - for (int i = 0; i < channels.length; i++) { - listeners[i].members.clear(); - } - } - - 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 - Thread[] threads = new Thread[channels.length]; - for (int i=0; i=0; i-- ) assertEquals("Checking member arrival length",channels.length-1,listeners[i].members.size()); - } - - @Override - protected void tearDown() throws Exception { - - for (int i = 0; i < channels.length; i++) { - try { - channels[i].stop(Channel.DEFAULT); - } catch (Exception ignore) { - // Ignore - } - } - super.tearDown(); - } - - public static class TestMbrListener - implements MembershipListener { - public String name = null; - public TestMbrListener(String name) { - this.name = name; - } - - public ArrayList members = new ArrayList(); - @Override - public void memberAdded(Member member) { - if (!members.contains(member)) { - members.add(member); - try { - System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); - } catch (Exception x) { - System.out.println(name + ":member added[unknown]"); - } - } - } - - @Override - public void memberDisappeared(Member member) { - if (members.contains(member)) { - members.remove(member); - try { - System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "; Thread:"+Thread.currentThread().getName()+"]"); - } catch (Exception x) { - System.out.println(name + ":member disappeared[unknown]"); - } - } - } - - } - -} diff --git a/test/org/apache/catalina/tribes/test/membership/TestMemberSerialization.java b/test/org/apache/catalina/tribes/test/membership/TestMemberSerialization.java deleted file mode 100644 index c7e842b3a..000000000 --- a/test/org/apache/catalina/tribes/test/membership/TestMemberSerialization.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.membership; - -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.apache.catalina.tribes.membership.MemberImpl; - -/** - *

Title:

- * - *

Description:

- * - *

Company:

- * - * @author not attributable - * @version 1.0 - */ -public class TestMemberSerialization extends TestCase { - MemberImpl m1, m2, p1,p2; - byte[] payload = null; - int udpPort = 3445; - @Override - protected void setUp() throws Exception { - super.setUp(); - payload = new byte[333]; - Arrays.fill(payload,(byte)1); - m1 = new MemberImpl("localhost",3333,1,payload); - m2 = new MemberImpl("localhost",3333,1); - payload = new byte[333]; - Arrays.fill(payload,(byte)2); - p1 = new MemberImpl("127.0.0.1",3333,1,payload); - p2 = new MemberImpl("localhost",3331,1,payload); - m1.setDomain(new byte[] {1,2,3,4,5,6,7,8,9}); - m2.setDomain(new byte[] {1,2,3,4,5,6,7,8,9}); - m1.setCommand(new byte[] {1,2,4,5,6,7,8,9}); - m2.setCommand(new byte[] {1,2,4,5,6,7,8,9}); - m1.setUdpPort(udpPort); - m2.setUdpPort(m1.getUdpPort()); - } - - public void testCompare() throws Exception { - assertTrue(m1.equals(m2)); - assertTrue(m2.equals(m1)); - assertTrue(p1.equals(m2)); - assertFalse(m1.equals(p2)); - assertFalse(m1.equals(p2)); - assertFalse(m2.equals(p2)); - assertFalse(p1.equals(p2)); - } - - 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); - } - - public void testSerializationOne() throws Exception { - MemberImpl m = m1; - byte[] md1 = m.getData(false,true); - byte[] mda1 = m.getData(false,false); - assertTrue(Arrays.equals(md1,mda1)); - assertTrue(md1==mda1); - mda1 = m.getData(true,true); - MemberImpl ma1 = MemberImpl.getMember(mda1); - assertTrue(compareMembers(m,ma1)); - mda1 = p1.getData(false); - assertFalse(Arrays.equals(md1,mda1)); - ma1 = MemberImpl.getMember(mda1); - assertTrue(compareMembers(p1,ma1)); - - md1 = m.getData(true,true); - Thread.sleep(50); - mda1 = m.getData(true,true); - MemberImpl a1 = MemberImpl.getMember(md1); - MemberImpl a2 = MemberImpl.getMember(mda1); - assertTrue(a1.equals(a2)); - assertFalse(Arrays.equals(md1,mda1)); - - - } - - public boolean compareMembers(MemberImpl impl1, MemberImpl impl2) { - boolean result = true; - result = result && Arrays.equals(impl1.getHost(),impl2.getHost()); - result = result && Arrays.equals(impl1.getPayload(),impl2.getPayload()); - result = result && Arrays.equals(impl1.getUniqueId(),impl2.getUniqueId()); - result = result && impl1.getPort() == impl2.getPort(); - return result; - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - -} diff --git a/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java b/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java deleted file mode 100644 index 83f4fe79c..000000000 --- a/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * 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.test.membership; - -import java.util.ArrayList; - -import junit.framework.TestCase; - -import org.apache.catalina.tribes.ByteMessage; -import org.apache.catalina.tribes.Channel; -import org.apache.catalina.tribes.ChannelException; -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 org.apache.catalina.tribes.group.interceptors.TcpFailureDetector; - -/** - *

Title:

- * - *

Description:

- * - *

Company:

- * - * @author not attributable - * @version 1.0 - */ -public class TestTcpFailureDetector extends TestCase { - 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(); - channel1 = new GroupChannel(); - channel2 = new GroupChannel(); - channel1.getMembershipService().setPayload("Channel-1".getBytes("ASCII")); - channel2.getMembershipService().setPayload("Channel-2".getBytes("ASCII")); - mbrlist1 = new TestMbrListener("Channel-1"); - mbrlist2 = new TestMbrListener("Channel-2"); - tcpFailureDetector1 = new TcpFailureDetector(); - tcpFailureDetector2 = new TcpFailureDetector(); - channel1.addInterceptor(tcpFailureDetector1); - channel2.addInterceptor(tcpFailureDetector2); - channel1.addMembershipListener(mbrlist1); - channel2.addMembershipListener(mbrlist2); - } - - public void clear() { - mbrlist1.members.clear(); - mbrlist2.members.clear(); - } - - public void testTcpSendFailureMemberDrop() throws Exception { - System.out.println("testTcpSendFailureMemberDrop()"); - clear(); - channel1.start(Channel.DEFAULT); - channel2.start(Channel.DEFAULT); - //Thread.sleep(1000); - assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); - channel2.stop(Channel.SND_RX_SEQ); - ByteMessage msg = new ByteMessage(new byte[1024]); - try { - channel1.send(channel1.getMembers(), msg, 0); - assertEquals("Message send should have failed.",true,false); - } 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); - } - - public void testTcpFailureMemberAdd() throws Exception { - System.out.println("testTcpFailureMemberAdd()"); - clear(); - channel1.start(Channel.DEFAULT); - channel2.start(Channel.SND_RX_SEQ); - channel2.start(Channel.SND_TX_SEQ); - channel2.start(Channel.MBR_RX_SEQ); - channel2.stop(Channel.SND_RX_SEQ); - channel2.start(Channel.MBR_TX_SEQ); - //Thread.sleep(1000); - assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size()); - channel1.stop(Channel.DEFAULT); - channel2.stop(Channel.DEFAULT); - } - - public void testTcpMcastFail() throws Exception { - System.out.println("testTcpMcastFail()"); - clear(); - channel1.start(Channel.DEFAULT); - channel2.start(Channel.DEFAULT); - //Thread.sleep(1000); - assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size()); - channel2.stop(Channel.MBR_TX_SEQ); - ByteMessage msg = new ByteMessage(new byte[1024]); - try { - Thread.sleep(5000); - 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); - } - channel1.stop(Channel.DEFAULT); - channel2.stop(Channel.DEFAULT); - } - - - @Override - protected 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 { - public String name = null; - public TestMbrListener(String name) { - this.name = name; - } - public ArrayList members = new ArrayList(); - @Override - public void memberAdded(Member member) { - if ( !members.contains(member) ) { - members.add(member); - try{ - System.out.println(name + ":member added[" + new String(member.getPayload(), "ASCII") + "]"); - }catch ( Exception x ) { - System.out.println(name + ":member added[unknown]"); - } - } - } - - @Override - public void memberDisappeared(Member member) { - if ( members.contains(member) ) { - members.remove(member); - try{ - System.out.println(name + ":member disappeared[" + new String(member.getPayload(), "ASCII") + "]"); - }catch ( Exception x ) { - System.out.println(name + ":member disappeared[unknown]"); - } - } - } - - } - -}