FileDocCategorySizeDatePackage
TestTcpFailureDetector.javaAPI DocApache Tomcat 6.0.146713Fri Jul 20 04:20:34 BST 2007org.apache.catalina.tribes.test.membership

TestTcpFailureDetector

public class TestTcpFailureDetector extends TestCase

Title:

Description:

Company:

author
not attributable
version
1.0

Fields Summary
private org.apache.catalina.tribes.group.interceptors.TcpFailureDetector
tcpFailureDetector1
private org.apache.catalina.tribes.group.interceptors.TcpFailureDetector
tcpFailureDetector2
private org.apache.catalina.tribes.ManagedChannel
channel1
private org.apache.catalina.tribes.ManagedChannel
channel2
private TestMbrListener
mbrlist1
private TestMbrListener
mbrlist2
Constructors Summary
Methods Summary
public voidclear()

        mbrlist1.members.clear();
        mbrlist2.members.clear();
    
protected voidsetUp()

         
        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);
    
protected voidtearDown()

        tcpFailureDetector1 = null;
        tcpFailureDetector2 = null;
        try { channel1.stop(Channel.DEFAULT);}catch (Exception ignore){}
        channel1 = null;
        try { channel2.stop(Channel.DEFAULT);}catch (Exception ignore){}
        channel2 = null;
        super.tearDown();
    
public voidtestTcpFailureMemberAdd()

        System.out.println("testTcpFailureMemberAdd()");
        clear();
        channel1.start(channel1.DEFAULT);
        channel2.start(channel2.SND_RX_SEQ);
        channel2.start(channel2.SND_TX_SEQ);
        channel2.start(channel2.MBR_RX_SEQ);
        channel2.stop(channel2.SND_RX_SEQ);
        channel2.start(channel2.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 voidtestTcpMcastFail()

        System.out.println("testTcpMcastFail()");
        clear();
        channel1.start(channel1.DEFAULT);
        channel2.start(channel2.DEFAULT);
        //Thread.sleep(1000);
        assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size());
        channel2.stop(channel2.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);
    
public voidtestTcpSendFailureMemberDrop()

        System.out.println("testTcpSendFailureMemberDrop()");
        clear();
        channel1.start(channel1.DEFAULT);
        channel2.start(channel2.DEFAULT);
        //Thread.sleep(1000);
        assertEquals("Expecting member count to be equal",mbrlist1.members.size(),mbrlist2.members.size());
        channel2.stop(channel2.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 ) {
            
        }
        assertEquals("Expecting member count to not be equal",mbrlist1.members.size()+1,mbrlist2.members.size());
        channel1.stop(Channel.DEFAULT);
        channel2.stop(Channel.DEFAULT);