FileDocCategorySizeDatePackage
TestDataIntegrity.javaAPI DocApache Tomcat 6.0.148488Fri Jul 20 04:20:36 BST 2007org.apache.catalina.tribes.test.channel

TestDataIntegrity

public class TestDataIntegrity extends TestCase

Title:

Description:

Company:

author
not attributable
version
1.0

Fields Summary
int
msgCount
int
threadCount
org.apache.catalina.tribes.group.GroupChannel
channel1
org.apache.catalina.tribes.group.GroupChannel
channel2
Listener
listener1
int
threadCounter
Constructors Summary
Methods Summary
protected voidsetUp()

         
        super.setUp();
        channel1 = new GroupChannel();
        channel1.addInterceptor(new MessageDispatch15Interceptor());
        channel2 = new GroupChannel();
        channel2.addInterceptor(new MessageDispatch15Interceptor());
        listener1 = new Listener();
        channel2.addChannelListener(listener1);
        channel1.start(GroupChannel.DEFAULT);
        channel2.start(GroupChannel.DEFAULT);
    
protected voidtearDown()

        super.tearDown();
        channel1.stop(GroupChannel.DEFAULT);
        channel2.stop(GroupChannel.DEFAULT);
    
public voidtestDataSendACK()

        System.err.println("Starting ACK");
        for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(),GroupChannel.SEND_OPTIONS_USE_ACK);
        Thread.sleep(250);
        System.err.println("Finished ACK");
        assertEquals("Checking success messages.",msgCount,listener1.count);
    
public voidtestDataSendASYNC()

        System.err.println("Starting ASYNC");
        for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(),GroupChannel.SEND_OPTIONS_ASYNCHRONOUS);
        //sleep for 50 sec, let the other messages in
        long start = System.currentTimeMillis();
        while ( (System.currentTimeMillis()-start)<5000 && msgCount!=listener1.count) Thread.sleep(500);
        System.err.println("Finished ASYNC");
        assertEquals("Checking success messages.",msgCount,listener1.count);
    
public voidtestDataSendASYNCM()

            System.err.println("Starting ASYNC MULTI THREAD");
            Thread[] threads = new Thread[threadCount];
            for (int x=0; x<threads.length; x++ ) {
                threads[x] = new Thread() {
                    public void run() {
                        try {
                            long start = System.currentTimeMillis();
                            for (int i = 0; i < msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)}, Data.createRandomData(),GroupChannel.SEND_OPTIONS_ASYNCHRONOUS);
                            System.out.println("Thread["+this.getName()+"] sent "+msgCount+" messages in "+(System.currentTimeMillis()-start)+" ms.");
                        }catch ( Exception x ) {
                            x.printStackTrace();
                            return;
                        } finally {
                            threadCounter++;
                        }
                    }
                };
            }
            for (int x=0; x<threads.length; x++ ) { threads[x].start();}
            for (int x=0; x<threads.length; x++ ) { threads[x].join();}
            //sleep for 50 sec, let the other messages in
            long start = System.currentTimeMillis();
            while ( (System.currentTimeMillis()-start)<15000 && msgCount*threadCount!=listener1.count) Thread.sleep(500);
            System.err.println("Finished ASYNC MULTI THREAD ["+listener1.count+"]");
            assertEquals("Checking success messages.",msgCount*threadCount,listener1.count);
    
public voidtestDataSendNO_ACK()

        System.err.println("Starting NO_ACK");
        Thread[] threads = new Thread[threadCount];
        for (int x=0; x<threads.length; x++ ) {
            threads[x] = new Thread() {
                public void run() {
                    try {
                        long start = System.currentTimeMillis();
                        for (int i = 0; i < msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)}, Data.createRandomData(),0);
                        System.out.println("Thread["+this.getName()+"] sent "+msgCount+" messages in "+(System.currentTimeMillis()-start)+" ms.");
                    }catch ( Exception x ) {
                        x.printStackTrace();
                        return;
                    } finally {
                        threadCounter++;
                    }
                }
            };
        }
        for (int x=0; x<threads.length; x++ ) { threads[x].start();}
        for (int x=0; x<threads.length; x++ ) { threads[x].join();}
        //sleep for 50 sec, let the other messages in
        long start = System.currentTimeMillis();
        while ( (System.currentTimeMillis()-start)<15000 && msgCount*threadCount!=listener1.count) Thread.sleep(500);
        System.err.println("Finished NO_ACK ["+listener1.count+"]");
        assertEquals("Checking success messages.",msgCount*threadCount,listener1.count);
    
public voidtestDataSendSYNCACK()

        System.err.println("Starting SYNC_ACK");
        for (int i=0; i<msgCount; i++) channel1.send(new Member[] {channel2.getLocalMember(false)},Data.createRandomData(),GroupChannel.SEND_OPTIONS_SYNCHRONIZED_ACK|GroupChannel.SEND_OPTIONS_USE_ACK);
        Thread.sleep(250);
        System.err.println("Finished SYNC_ACK");
        assertEquals("Checking success messages.",msgCount,listener1.count);