FileDocCategorySizeDatePackage
TestMemberArrival.javaAPI DocApache Tomcat 6.0.144601Fri Jul 20 04:20:36 BST 2007org.apache.catalina.tribes.test.membership

TestMemberArrival

public class TestMemberArrival extends TestCase

Fields Summary
private static int
count
private org.apache.catalina.tribes.ManagedChannel[]
channels
private TestMbrListener[]
listeners
Constructors Summary
Methods Summary
public voidclear()

        for (int i = 0; i < channels.length; i++) {
            listeners[i].members.clear();
        }
    
protected voidsetUp()


         
        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]);

        }
    
protected voidtearDown()


        for (int i = 0; i < channels.length; i++) {
            try {
                channels[i].stop(Channel.DEFAULT);
            } catch (Exception ignore) {}
        }
        super.tearDown();
    
public voidtestMemberArrival()

        //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<channels.length; i++ ) {
            final Channel channel = channels[i];
            Thread t = new Thread() {
                public void run() {
                    try {
                        channel.start(Channel.DEFAULT);
                    }catch ( Exception x ) {
                        throw new RuntimeException(x);
                    }
                }
            };
            threads[i] = t;
        }
        for (int i=0; i<threads.length; i++ ) threads[i].start();
        for (int i=0; i<threads.length; i++ ) threads[i].join();
        Thread.sleep(2000);
        System.out.println("All channels started.");
        for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking member arrival length",channels.length-1,listeners[i].members.size());