tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r441543 [2/2] - in /tomcat/tc6.0.x/trunk: java/org/apache/catalina/tribes/ java/org/apache/catalina/tribes/membership/ java/org/apache/catalina/tribes/transport/ test/ test/org/ test/org/apache/ test/org/apache/catalina/ test/org/apache/cat...
Date Fri, 08 Sep 2006 15:42:10 GMT
Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestDomainFilter.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,104 @@
+package org.apache.catalina.tribes.test.membership;
+
+import java.util.ArrayList;
+
+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 junit.framework.TestCase;
+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];
+
+    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<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();
+        System.out.println("All channels started.");
+        for (int i=listeners.length-1; i>=0; i-- ) assertEquals("Checking member arrival
length",0,listeners[i].members.size());
+    }
+
+    protected void tearDown() throws Exception {
+
+        for (int i = 0; i < channels.length; i++) {
+            try {
+                channels[i].stop(Channel.DEFAULT);
+            } catch (Exception ignore) {}
+        }
+        super.tearDown();
+    }
+
+    public class TestMbrListener
+        implements MembershipListener {
+        public String name = null;
+        public TestMbrListener(String name) {
+            this.name = name;
+        }
+
+        public ArrayList members = new ArrayList();
+        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]");
+                }
+            }
+        }
+
+        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]");
+                }
+            }
+        }
+
+    }
+
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestMemberArrival.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,100 @@
+package org.apache.catalina.tribes.test.membership;
+
+import java.util.ArrayList;
+
+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 junit.framework.TestCase;
+
+public class TestMemberArrival
+    extends TestCase {
+    private static int count = 10;
+    private ManagedChannel[] channels = new ManagedChannel[count];
+    private TestMbrListener[] listeners = new TestMbrListener[count];
+
+    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<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();
+        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());
+    }
+
+    protected void tearDown() throws Exception {
+
+        for (int i = 0; i < channels.length; i++) {
+            try {
+                channels[i].stop(Channel.DEFAULT);
+            } catch (Exception ignore) {}
+        }
+        super.tearDown();
+    }
+
+    public class TestMbrListener
+        implements MembershipListener {
+        public String name = null;
+        public TestMbrListener(String name) {
+            this.name = name;
+        }
+
+        public ArrayList members = new ArrayList();
+        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]");
+                }
+            }
+        }
+
+        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]");
+                }
+            }
+        }
+
+    }
+
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/membership/TestTcpFailureDetector.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,151 @@
+package org.apache.catalina.tribes.test.membership;
+
+import java.util.ArrayList;
+
+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;
+import junit.framework.TestCase;
+
+/**
+ * <p>Title: </p> 
+ * 
+ * <p>Description: </p> 
+ * 
+ * <p>Copyright: Copyright (c) 2005</p> 
+ * 
+ * <p>Company: </p>
+ * 
+ * @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;
+    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(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);
+    }
+    
+    public void testTcpFailureMemberAdd() throws Exception {
+        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 void testTcpMcastFail() throws Exception {
+        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);
+    }
+
+
+    protected void tearDown() throws Exception {
+        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 class TestMbrListener implements MembershipListener {
+        public String name = null;
+        public TestMbrListener(String name) {
+            this.name = name;
+        }
+        public ArrayList members = new ArrayList();
+        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]");
+                }
+            }
+        }
+        
+        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]");
+                }
+            }
+        }
+        
+    }
+
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioReceive.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,76 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.text.DecimalFormat;
+
+import org.apache.catalina.tribes.ChannelMessage;
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.MessageListener;
+import org.apache.catalina.tribes.io.ChannelData;
+import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.membership.MemberImpl;
+import org.apache.catalina.tribes.transport.nio.NioReceiver;
+
+public class SocketNioReceive {
+    static int count = 0;
+    static int accept = 0;
+    static long start = 0;
+    static double mb = 0;
+    static int len = 0;
+    static DecimalFormat df = new DecimalFormat("##.00");
+    static double seconds = 0;
+
+    protected static Object mutex = new Object();
+    public static void main(String[] args) throws Exception {
+        Member mbr = new MemberImpl("localhost", 9999, 0);
+        ChannelData data = new ChannelData();
+        data.setAddress(mbr);
+        byte[] buf = new byte[8192 * 4];
+        data.setMessage(new XByteBuffer(buf, false));
+        buf = XByteBuffer.createDataPackage(data);
+        len = buf.length;
+        NioReceiver receiver = new NioReceiver();
+        receiver.setPort(9999);
+        receiver.setHost("localhost");
+        MyList list = new MyList();
+        receiver.setMessageListener(list);
+        receiver.start();
+        System.out.println("Listening on 9999");
+        while (true) {
+            try {
+                synchronized (mutex) {
+                    mutex.wait(5000);
+                    if ( start != 0 ) {
+                        System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds,
messages "+count+" accepts "+accept+", total "+mb+" MB.");
+                    }
+                }
+            }catch (Throwable x) {
+                x.printStackTrace();
+            }
+        }
+    }
+    
+    public static class MyList implements MessageListener {
+        boolean first = true;
+        
+        
+        public void messageReceived(ChannelMessage msg) {
+            if (first) {
+                first = false;
+                start = System.currentTimeMillis();
+            }
+            mb += ( (double) len) / 1024 / 1024;
+            synchronized (this) {count++;}
+            if ( ( (count) % 10000) == 0) {
+                long time = System.currentTimeMillis();
+                seconds = ( (double) (time - start)) / 1000;
+                System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds,
messages "+count+", total "+mb+" MB.");
+            }
+        }        
+
+        public boolean accept(ChannelMessage msg) {
+            synchronized (this) {accept++;}
+            return true;
+        }
+
+    }
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioSend.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioSend.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioSend.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioSend.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,91 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.io.OutputStream;
+import java.net.Socket;
+import java.text.DecimalFormat;
+import org.apache.catalina.tribes.transport.nio.NioSender;
+import org.apache.catalina.tribes.membership.MemberImpl;
+import java.nio.channels.Selector;
+import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.Member;
+import java.nio.channels.SelectionKey;
+import java.util.Iterator;
+import org.apache.catalina.tribes.Channel;
+import org.apache.catalina.tribes.io.ChannelData;
+import java.math.BigDecimal;
+
+public class SocketNioSend {
+
+    public static void main(String[] args) throws Exception {
+        Selector selector = Selector.open();
+        Member mbr = new MemberImpl("localhost", 9999, 0);
+        ChannelData data = new ChannelData();
+        data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE);
+        data.setAddress(mbr);
+        byte[] buf = new byte[8192 * 4];
+        data.setMessage(new XByteBuffer(buf,false));
+        buf = XByteBuffer.createDataPackage(data);
+        int len = buf.length;
+        BigDecimal total = new BigDecimal((double)0);
+        BigDecimal bytes = new BigDecimal((double)len);
+        NioSender sender = new NioSender();
+        sender.setDestination(mbr);
+        sender.setDirectBuffer(true);
+        sender.setSelector(selector);
+        sender.setTxBufSize(1024*1024);
+        sender.connect();
+        sender.setMessage(buf);
+        System.out.println("Writing to 9999");
+        long start = 0;
+        double mb = 0;
+        boolean first = true;
+        int count = 0;
+        DecimalFormat df = new DecimalFormat("##.00");
+        while (count<100000) {
+            if (first) {
+                first = false;
+                start = System.currentTimeMillis();
+            }
+            sender.setMessage(buf);
+            int selectedKeys = 0;
+            try {
+                selectedKeys = selector.select(0);
+            } catch (Exception e) {
+                e.printStackTrace();
+                continue;
+            }
+
+            if (selectedKeys == 0) {
+                continue;
+            }
+
+            Iterator it = selector.selectedKeys().iterator();
+            while (it.hasNext()) {
+                SelectionKey sk = (SelectionKey) it.next();
+                it.remove();
+                try {
+                    int readyOps = sk.readyOps();
+                    sk.interestOps(sk.interestOps() & ~readyOps);
+                    if (sender.process(sk, false)) {
+                        total = total.add(bytes);
+                        sender.reset();
+                        sender.setMessage(buf);
+                        mb += ( (double) len) / 1024 / 1024;
+                        if ( ( (++count) % 10000) == 0) {
+                            long time = System.currentTimeMillis();
+                            double seconds = ( (double) (time - start)) / 1000;
+                            System.out.println("Throughput " + df.format(mb / seconds) +
" MB/seconds, total "+mb+" MB, total "+total+" bytes.");
+                        }
+                    }
+
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                    return;
+                }
+            }
+            selector.selectedKeys().clear();
+        }
+        System.out.println("Complete, sleeping 15 seconds");
+        Thread.sleep(15000);
+    }
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,90 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.io.OutputStream;
+import java.net.Socket;
+import java.text.DecimalFormat;
+import org.apache.catalina.tribes.transport.nio.NioSender;
+import org.apache.catalina.tribes.membership.MemberImpl;
+import java.nio.channels.Selector;
+import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.Member;
+import java.nio.channels.SelectionKey;
+import java.util.Iterator;
+import org.apache.catalina.tribes.Channel;
+import org.apache.catalina.tribes.io.ChannelData;
+import java.math.BigDecimal;
+import java.util.Arrays;
+
+public class SocketNioValidateSend {
+
+    public static void main(String[] args) throws Exception {
+        Selector selector = Selector.open();
+        Member mbr = new MemberImpl("localhost", 9999, 0);
+        byte seq = 0;
+        byte[] buf = new byte[50000];
+        Arrays.fill(buf,seq);
+        int len = buf.length;
+        BigDecimal total = new BigDecimal((double)0);
+        BigDecimal bytes = new BigDecimal((double)len);
+        NioSender sender = new NioSender();
+        sender.setDestination(mbr);
+        sender.setDirectBuffer(true);
+        sender.setSelector(selector);
+        sender.connect();
+        sender.setMessage(buf);
+        System.out.println("Writing to 9999");
+        long start = 0;
+        double mb = 0;
+        boolean first = true;
+        int count = 0;
+        
+        DecimalFormat df = new DecimalFormat("##.00");
+        while (count<100000) {
+            if (first) {
+                first = false;
+                start = System.currentTimeMillis();
+            }
+            sender.setMessage(buf);
+            int selectedKeys = 0;
+            try {
+                selectedKeys = selector.select(0);
+            } catch (Exception e) {
+                e.printStackTrace();
+                continue;
+            }
+
+            if (selectedKeys == 0) {
+                continue;
+            }
+
+            Iterator it = selector.selectedKeys().iterator();
+            while (it.hasNext()) {
+                SelectionKey sk = (SelectionKey) it.next();
+                it.remove();
+                try {
+                    int readyOps = sk.readyOps();
+                    sk.interestOps(sk.interestOps() & ~readyOps);
+                    if (sender.process(sk, false)) {
+                        total = total.add(bytes);
+                        sender.reset();
+                        seq++;
+                        Arrays.fill(buf,seq);
+                        sender.setMessage(buf);
+                        mb += ( (double) len) / 1024 / 1024;
+                        if ( ( (++count) % 10000) == 0) {
+                            long time = System.currentTimeMillis();
+                            double seconds = ( (double) (time - start)) / 1000;
+                            System.out.println("Throughput " + df.format(mb / seconds) +
" MB/seconds, total "+mb+" MB, total "+total+" bytes.");
+                        }
+                    }
+
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                    return;
+                }
+            }
+        }
+        System.out.println("Complete, sleeping 15 seconds");
+        Thread.sleep(15000);
+    }
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketReceive.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,62 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.math.BigDecimal;
+
+public class SocketReceive {
+    static long start = 0;
+    static double mb = 0;
+    static byte[] buf = new byte[8192 * 4];
+    static boolean first = true;
+    static int count = 0;
+    static DecimalFormat df = new DecimalFormat("##.00");
+    static BigDecimal total = new BigDecimal(0);
+    static BigDecimal bytes = new BigDecimal(32871);
+
+    
+    public static void main(String[] args) throws Exception {
+    
+        ServerSocket srvSocket = new ServerSocket(9999);
+        System.out.println("Listening on 9999");
+        Socket socket = srvSocket.accept();
+        socket.setReceiveBufferSize(43800);
+        InputStream in = socket.getInputStream();
+        Thread t = new Thread() {
+            public void run() {
+                while ( true ) {
+                    try {
+                        Thread.sleep(1000);
+                        printStats(start, mb, count, df, total);
+                    }catch ( Exception x ) {}
+                }
+            }
+        };
+        t.setDaemon(true);
+        t.start();
+
+        while ( true ) {
+            if ( first ) { first = false; start = System.currentTimeMillis();}
+            int len = in.read(buf);
+            if ( len == -1 ) {
+                printStats(start, mb, count, df, total);
+                System.exit(1);
+            }
+            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
+            total = total.add(bytes);
+            mb += ( (double) len) / 1024 / 1024;
+            if ( ((++count) % 10000) == 0 ) {
+                printStats(start, mb, count, df, total);
+            }
+        }
+        
+    }
+
+    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+        long time = System.currentTimeMillis();
+        double seconds = ((double)(time-start))/1000;
+        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+    }
+}
\ No newline at end of file

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java (added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketSend.java Fri
Sep  8 08:42:08 2006
@@ -0,0 +1,53 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.io.OutputStream;
+import java.net.Socket;
+import java.text.DecimalFormat;
+import org.apache.catalina.tribes.membership.MemberImpl;
+import org.apache.catalina.tribes.io.XByteBuffer;
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.io.ChannelData;
+import org.apache.catalina.tribes.Channel;
+import java.math.BigDecimal;
+
+public class SocketSend {
+
+    public static void main(String[] args) throws Exception {
+        
+        
+        Member mbr = new MemberImpl("localhost", 9999, 0);
+        ChannelData data = new ChannelData();
+        data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE);
+        data.setAddress(mbr);
+        byte[] buf = new byte[8192 * 4];
+        data.setMessage(new XByteBuffer(buf,false));
+        buf = XByteBuffer.createDataPackage(data);
+        int len = buf.length;
+        System.out.println("Message size:"+len+" bytes");
+        BigDecimal total = new BigDecimal((double)0);
+        BigDecimal bytes = new BigDecimal((double)len);
+        Socket socket = new Socket("localhost",9999);
+        System.out.println("Writing to 9999");
+        OutputStream out = socket.getOutputStream();
+        long start = 0;
+        double mb = 0;
+        boolean first = true;
+        int count = 0;
+        DecimalFormat df = new DecimalFormat("##.00");
+        while ( count<100000 ) {
+            if ( first ) { first = false; start = System.currentTimeMillis();}
+            out.write(buf,0,buf.length);
+            mb += ( (double) buf.length) / 1024 / 1024;
+            total = total.add(bytes);
+            if ( ((++count) % 10000) == 0 ) {
+                long time = System.currentTimeMillis();
+                double seconds = ((double)(time-start))/1000;
+                System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages
"+count+", total "+mb+" MB, total "+total+" bytes.");
+            }
+        }
+        out.flush(); 
+        System.out.println("Complete, sleeping 5 seconds");
+        Thread.sleep(5000);
+
+    }
+}

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,71 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.math.BigDecimal;
+import org.apache.catalina.tribes.io.XByteBuffer;
+
+public class SocketTribesReceive {
+    static long start = 0;
+    static double mb = 0;
+    //static byte[] buf = new byte[32871];
+    static byte[] buf = new byte[32871];
+    static boolean first = true;
+    static int count = 0;
+    static DecimalFormat df = new DecimalFormat("##.00");
+    static BigDecimal total = new BigDecimal((double)0);
+    static BigDecimal bytes = new BigDecimal((double)32871);
+
+    
+    public static void main(String[] args) throws Exception {
+        int size = 43800;
+        if (args.length > 0 ) try {size=Integer.parseInt(args[0]);}catch(Exception x){}
+        XByteBuffer xbuf = new XByteBuffer(43800,true);
+        ServerSocket srvSocket = new ServerSocket(9999);
+        System.out.println("Listening on 9999");
+        Socket socket = srvSocket.accept();
+        socket.setReceiveBufferSize(size);
+        InputStream in = socket.getInputStream();
+        Thread t = new Thread() {
+            public void run() {
+                while ( true ) {
+                    try {
+                        Thread.sleep(1000);
+                        printStats(start, mb, count, df, total);
+                    }catch ( Exception x ) {}
+                }
+            }
+        };
+        t.setDaemon(true);
+        t.start();
+
+        while ( true ) {
+            if ( first ) { first = false; start = System.currentTimeMillis();}
+            int len = in.read(buf);
+            if ( len == -1 ) {
+                printStats(start, mb, count, df, total);
+                System.exit(1);
+            }
+            xbuf.append(buf,0,len);
+            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
+            total = total.add(bytes);
+            while ( xbuf.countPackages(true) > 0 ) {
+                xbuf.extractPackage(true);
+                count++;
+            }
+            mb += ( (double) len) / 1024 / 1024;
+            if ( ((count) % 10000) == 0 ) {
+                printStats(start, mb, count, df, total);
+            }
+        }
+        
+    }
+
+    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+        long time = System.currentTimeMillis();
+        double seconds = ((double)(time-start))/1000;
+        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+    }
+}
\ No newline at end of file

Added: tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java?view=auto&rev=441543
==============================================================================
--- tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
(added)
+++ tomcat/tc6.0.x/trunk/test/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java
Fri Sep  8 08:42:08 2006
@@ -0,0 +1,91 @@
+package org.apache.catalina.tribes.test.transport;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.io.InputStream;
+import java.text.DecimalFormat;
+import java.math.BigDecimal;
+
+public class SocketValidateReceive {
+    static long start = 0;
+    static double mb = 0;
+    static byte[] buf = new byte[8192 * 4];
+    static boolean first = true;
+    static int count = 0;
+    static DecimalFormat df = new DecimalFormat("##.00");
+    static BigDecimal total = new BigDecimal(0);
+    static BigDecimal bytes = new BigDecimal(32871);
+
+    
+    public static void main(String[] args) throws Exception {
+        int size = 43800;
+        if (args.length > 0 ) try {size=Integer.parseInt(args[0]);}catch(Exception x){}
+   
+        ServerSocket srvSocket = new ServerSocket(9999);
+        System.out.println("Listening on 9999");
+        Socket socket = srvSocket.accept();
+        socket.setReceiveBufferSize(size);
+        InputStream in = socket.getInputStream();
+        MyDataReader reader = new MyDataReader(50000);
+        Thread t = new Thread() {
+            public void run() {
+                while ( true ) {
+                    try {
+                        Thread.sleep(1000);
+                        printStats(start, mb, count, df, total);
+                    }catch ( Exception x ) {}
+                }
+            }
+        };
+        t.setDaemon(true);
+        t.start();
+
+        while ( true ) {
+            if ( first ) { first = false; start = System.currentTimeMillis();}
+            int len = in.read(buf);
+            if ( len == -1 ) {
+                printStats(start, mb, count, df, total);
+                System.exit(1);
+            }
+            count += reader.append(buf,0,len);
+            
+            if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len);
+            total = total.add(bytes);
+            mb += ( (double) len) / 1024 / 1024;
+            if ( ((count) % 10000) == 0 ) {
+                printStats(start, mb, count, df, total);
+            }
+        }
+        
+    }
+
+    private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal
total) {
+        long time = System.currentTimeMillis();
+        double seconds = ((double)(time-start))/1000;
+        System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+",
total "+mb+" MB, total "+total+" bytes.");
+    }
+    
+    public static class MyDataReader {
+        byte[] data = new byte[43800];
+        int length = 10;
+        int cur = 0;
+        byte seq = 0;
+        public MyDataReader(int len) {
+            length = len;
+        }
+        
+        public int append(byte[] b, int off, int len) throws Exception {
+            int packages = 0;
+            for ( int i=off; i<len; i++ ) { 
+                if ( cur == length ) {
+                    cur = 0;
+                    seq++;
+                    packages++;
+                }
+                if ( b[i] != seq ) throw new Exception("mismatch on seq:"+seq+" and byte
nr:"+cur+" count:"+count+" packages:"+packages);
+                cur++;
+            }
+            return packages;
+        }
+    }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message