diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BenchLocal.java | 1 | ||||
-rw-r--r-- | tests/Makefile | 110 | ||||
-rw-r--r-- | tests/NewLine.java | 12 | ||||
-rw-r--r-- | tests/TestApi.java | 24 | ||||
-rw-r--r-- | tests/TestNetSwing.java | 189 | ||||
-rw-r--r-- | tests/build.xml | 65 |
6 files changed, 175 insertions, 226 deletions
diff --git a/tests/BenchLocal.java b/tests/BenchLocal.java index f0b6863..6a21599 100644 --- a/tests/BenchLocal.java +++ b/tests/BenchLocal.java @@ -59,6 +59,7 @@ class BenchLocal { void sleep(int delay) { log("waiting "+delay+" ms"); + if (delay==0) return; // a Kaffe bug ? try { Thread.sleep(delay); } catch (InterruptedException ie) { } } diff --git a/tests/Makefile b/tests/Makefile index 9c002f0..4e13679 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,101 +1,27 @@ -.SUFFIXES: .java .class -SRC = TestNet.java Bug.java BugTok.java BenchLocal.java ProbeBench.java \ - DieSender.java TestApi.java NewLine.java AsyncAPI.java -OBJ = $(SRC:.java=.class) -#BUS= -#BUS=-DIVYBUS=224.5.6.7:8910 +# Makefile for Ivy test class suite -#GNUPATH=$(HOME)/JavaFactory -GNUPATH=/usr/share/java/gnu.getopt.jar:/usr/share/java/regexp.jar -#GNUPATH=/usr/share/java/regexp.jar:/usr/share/java/gnu-getopt.jar -#GNUPATH=/usr/share/java/repository:/usr/share/java/gnu.getopt.0.9.jar:/usr/share/java/gnu-regexp-1.1.3.jar -#GNUPATH= -BUILDPATH=../lib/ivy-java.jar -#BUILDPATH=../src:../bundle -ADD=$(BUILDPATH):$(GNUPATH) -#ADD=$(BUILDPATH) +include ../java.mk +IVYPATH=../lib/ivy-java.jar +CLASSPATH=-classpath classes:$(IVYPATH) -#JAVAOPTS = -DIVY_PING -# DONOTBUILD = TestNetSwing.java # Color(r,g,b,a) doesn't exist in jdk1.1 +SRC = *.java +# Warning TestNetSwing.java cant build with jdk1.1 +# as Color(r,g,b,a) doesn't exist in jdk1.1 -###################################### -# generic setup -###################################### -#RTPATH = /usr/lib/j2se/1.4/jre/lib/rt.jar -#CLASSPATH=-classpath .:$(ADD):$(RTPATH) -#CLASSPATH=-classpath .:$(ADD) -#JAVACOPTS= -deprecation -#JAVAOPTS = $(BUS) -#JAVAOPTS = $(BUS) -DIVY_DEBUG -#JAVAC= jikes -#JAVAC= javac -#JAVA = java - -###################################### -# generic setup -###################################### -CLASSPATH=-classpath .:$(ADD) -JAVACOPTS= -deprecation -JAVAOPTS = $(BUS) -JAVAC= javac -JAVA = java - -###################################### -# Kaffe (debian woody) -###################################### -#CLASSPATH=-classpath .:$(ADD):/usr/share/kaffe/Klasses.jar -#JAVACOPTS= -deprecation -#JAVAOPTS = $(BUS) -#JAVAC= javac -#JAVA = kaffe - -###################################### -# SUN 1.4.0 -###################################### -#CLASSPATH=-classpath .:$(ADD) -#JAVACOPTS= -deprecation -#JAVAOPTS = $(BUS) -#JAVAC= /opt/Java/j2sdk1.4.0_01/bin/javac -#JAVA = /opt/Java/j2sdk1.4.0_01/bin/java - -###################################### -# local Blackdown linux 118_v3 system -###################################### -#CLASSPATH = -classpath .:/usr/local/jdk118_v3/lib/classes.zip:/home/jestin/java/Jars/swingall.jar:$(ADD) -#JAVACOPTS = -#JAVAOPTS = $(BUS) -#JAVA = /usr/local/jdk118_v3/bin/java -#JAVAC = /usr/local/jdk118_v3/bin/javac - -###################################### -# local Blackdown linux 1.2.2 -###################################### -#CLASSPATH = -classpath .:$(ADD) -#JAVACOPTS = -deprecation -#JAVAOPTS = $(BUS) -#JAVA = /usr/local/jdk1.2.2/bin/java -#JAVAC = /usr/local/jdk1.2.2/bin/javac - -###################################### -# local Blackdown linux 1.3.1 -###################################### -#CLASSPATH = -classpath .:$(ADD) -#JAVACOPTS = -deprecation -#JAVAOPTS = $(BUS) -#JAVA = /usr/local/j2sdk1.3.1/bin/java -#JAVAC = /usr/local/j2sdk1.3.1/bin/javac +#LOCALNET=10.192.36.255:3456 #LOCALNET=10.0.0.255:3456 LOCALNET=$(MULTICAST) -#LOCALNET=10.192.36.255:3456 MULTICAST=228.1.2.3:4567 -.java.class: - $(JAVAC) $(JAVACOPTS) $(CLASSPATH) $< -all: $(OBJ) +all: + $(JAVAC) -d classes $(JAVACOPTS) $(CLASSPATH) $(SRC) @echo "all modules built. run make run" -run: $(OBJ) nl api unitaires test1 test2 probe async +run: nl api unitaires test1 test2 probe async stop request + +request: + $(JAVA) $(JAVAOPTS) $(CLASSPATH) Request nl: $(JAVA) $(JAVAOPTS) $(CLASSPATH) NewLine -n 100000 @@ -106,9 +32,12 @@ probe: api: $(JAVA) $(JAVAOPTS) $(CLASSPATH) TestApi -async: AsyncAPI.class +async: $(JAVA) $(JAVAOPTS) $(CLASSPATH) AsyncAPI -r -l 5 -d 1 -s 10 +stop: + $(JAVA) $(JAVAOPTS) $(CLASSPATH) StopStart + unitaires: $(JAVA) $(JAVAOPTS) $(CLASSPATH) fr.dgac.ivy.Ivy @@ -124,4 +53,5 @@ test2: $(OBJ) $(JAVA) $(JAVAOPTS) $(CLASSPATH) BenchLocal -t 2 -d 0 clean: - /bin/rm -f $(OBJ) *.class + /bin/rm -fR $(OBJ) *.class classes + @mkdir classes diff --git a/tests/NewLine.java b/tests/NewLine.java index 78835a3..ac4dc43 100644 --- a/tests/NewLine.java +++ b/tests/NewLine.java @@ -7,16 +7,16 @@ class NewLine { public static void main(String[] args) throws IvyException { Getopt opt = new Getopt("NewLine",args,"b:n:"); - String domain=Ivy.getDomain(null); // default bus + String domain=Ivy.getDomain(null); int c; int nb = 10000; while ((c = opt.getopt()) != -1) switch (c) { - case 'n': - nb=Integer.parseInt(opt.getOptarg()); - break; case 'b': domain=opt.getOptarg(); break; + case 'n': + nb=Integer.parseInt(opt.getOptarg()); + break; default: System.exit(0); } @@ -30,7 +30,6 @@ class NewLine { System.out.println("trying Newline on " + n + " tests"); nbmsg=n; bus = new Ivy("NewLine","NewLine ready", null); - // System.out.println("protectnewline is OFF in 1.2.4 !!!"); bus.protectNewlines(true); bus.sendToSelf(true); bus.bindMsg("^coucou(.)monde$",new IvyMessageListener() { @@ -40,7 +39,6 @@ class NewLine { } }); bus.start(domain); - // try { Thread.sleep(2000); } catch (InterruptedException ie) { } long t1,t2,t3; t1=(new java.util.Date()).getTime(); System.out.println("sending "+nbmsg+" protected newlines"); @@ -60,7 +58,9 @@ class NewLine { for (int i=0;i<n;i++ ) bus.sendMsg("coucou monde"); t3=(new java.util.Date()).getTime(); System.out.println("with protection " + (t2-t1) +"ms, without "+(t3-t2)+"ms"); + System.out.println("DEBUUUUUUG stopping the bus"); bus.stop(); + System.out.println("DEBUUUUUUG end stopping the bus"); } } diff --git a/tests/TestApi.java b/tests/TestApi.java index 3fa936a..00c2f29 100644 --- a/tests/TestApi.java +++ b/tests/TestApi.java @@ -93,32 +93,12 @@ class TestApi implements IvyMessageListener, IvyApplicationListener { System.out.println("Sender leaving the bus"); sbus.stop(); System.out.println("Sender has left the bus"); - new Killer(domain); - } - } - - class Killer implements IvyMessageListener { - private Ivy kbus; - public Killer(String domain) { - try { - System.out.println("Killer joining the bus"); - kbus = new Ivy("Killer","Killer ready", null); - kbus.bindMsg("^"+TestApiReadyMsg+"$",this); - kbus.start(domain); - } catch (IvyException ie) { - ie.printStackTrace(); - } - } - public void receive(IvyClient c,String[] args) { - c.sendDie("bye bye"); - System.out.println("Killer leaving the bus"); - kbus.stop(); - System.out.println("Killer has left the bus"); + new Killer(domain,("^"+TestApiReadyMsg+"$")); } } public static void main(String[] args) throws IvyException { - new TestApi(Ivy.getDomain(null)); + new TestApi(Ivy.getDomainArgs("TestApi",args)); } } diff --git a/tests/TestNetSwing.java b/tests/TestNetSwing.java index 3154457..7afbb0a 100644 --- a/tests/TestNetSwing.java +++ b/tests/TestNetSwing.java @@ -1,25 +1,29 @@ /** * TestNetSwing , a network Ivy domain checker. * @author Yannick Jestin <mailto:jestin@cena.fr> + * * (c) CENA - * A simple Swing application in order to check whether the chosen network is - * OK + * A simple Swing application in order to check a network + * + * Changelog: + * 1.2.8 + * - apache regexp instead of gnu regexp */ import java.net.*; import java.io.*; import java.util.*; -import gnu.regexp.*; -import gnu.getopt.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; +import fr.dgac.ivy.*; +import org.apache.regexp.*; +import gnu.getopt.*; class TestNetSwing implements Runnable { private JFrame frame; private JLabel receive; private JButton send; - private JComboBox domainBox; private int alpha=0; private Color color; private static int FADINGSTEP = 20; @@ -31,59 +35,33 @@ class TestNetSwing implements Runnable { private static Color DEFAULT_COLOR = new Color(DEFAULT_RED,DEFAULT_GREEN,DEFAULT_BLUE,DEFAULT_ALPHA); - private static String[] domainList = { - "127.255.255.255:2010", - "10.0.0.255:2010", - "10.192.36.255:2010", - "227.1.2.3:4567" - }; - - private Thread server; private Ageing age; - private String domain; + private String domainAddr="none"; + private int port=0; + private int serial=1; private boolean watcherrunning = false; + private volatile Thread watcherThread; private boolean isMulticastAddress = false; private Thread broadcastListener ; private DatagramSocket broadcast; /* supervision socket */ // it can also be a MulticastSocket, which inherits from the previous - public TestNetSwing(String d) { - if (d==null) { d = domainList[0]; }; - domain=d; - server = createBroadcastListener(domain); - server.start(); - frame = new JFrame("TestNet"); - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); + public TestNetSwing(String da,int p) { + this.domainAddr=da; + this.port=p; + createBroadcastListener(); + frame = new JFrame("TestNet "+domainAddr+":"+port); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp = frame.getContentPane(); cp.setLayout(new GridLayout(0,1)); - cp.add(send = new JButton("send packet")); + cp.add(send = new JButton("send packet to "+domainAddr+":"+port)); send.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { - send("hello",domain); + send("hello",domainAddr,port); } }); cp.add(receive = new JLabel("")); - domainBox = new JComboBox(); - domainBox.setEditable(true); boolean sel = false; - int index=0; - for (;index<domainList.length;index++) { - domainBox.addItem(domainList[index]); - if (domainList[index]==d) { - domainBox.setSelectedIndex(index); - sel=true; - } - } - if (!sel) { - domainBox.addItem(domain); - domainBox.setSelectedIndex(index); - } - cp.add(domainBox); - domainBox.addActionListener(new ComboCB()); frame.pack(); age=new Ageing(); frame.setVisible(true); @@ -91,21 +69,21 @@ class TestNetSwing implements Runnable { public void run() { byte buf[] = new byte[256]; + Thread thisThread=Thread.currentThread(); for (int i=0;i<buf.length;i++) { buf[i]=10; } DatagramPacket packet=new DatagramPacket(buf, 256); - int port; - String s = "Server waiting for Broadcast on "+domain; + String s = "Server waiting for Broadcast on "+domainAddr+":"+port; s+=(isMulticastAddress)?" (TCP multicast)":" (UDP broadcast)"; System.out.println(s); - while( watcherrunning ) try { + while( watcherThread==thisThread) try { broadcast.receive(packet); String msg = new String(buf) ; // clean up the buffer after each message for (int i=0;i<buf.length;i++) { buf[i]=10; } InetAddress remotehost = packet.getAddress(); - updateLabel(remotehost.getHostName()+":"+msg); + updateLabel("("+(serial++)+") "+ remotehost.getHostName()+":"+msg); } catch (java.io.InterruptedIOException jii ){ - if (!watcherrunning) break; + if (watcherThread!=thisThread) break; } catch (java.io.IOException ioe ){ System.err.println("IvyWatcher IOException "+ ioe.getMessage() ); } @@ -113,7 +91,11 @@ class TestNetSwing implements Runnable { System.out.println("Server normal shutdown"); } - void stop() { watcherrunning=false; } + synchronized void stop() { + Thread t = watcherThread; + watcherThread = null; + if (t!=null) { t.interrupt(); } + } private void updateLabel(String text) { if (text==null) return; @@ -125,39 +107,10 @@ class TestNetSwing implements Runnable { receive.setForeground(color); } - private static String getDomain(String net) { - int sep_index = net.lastIndexOf( ":" ); - if ( sep_index != -1 ) { net = net.substring(0,sep_index); } - try { - net += ".255.255.255"; - RE exp = new RE( "^(\\d+\\.\\d+\\.\\d+\\.\\d+).*"); - net = exp.substitute( net , "$1" ); - } catch ( REException e ){ - System.out.println("Bad broascat addr " + net); - return null; - } - //System.out.println("net: "+net); - return net; - } - - private static int getPort(String net) { - int port; - int sep_index = net.lastIndexOf( ":" ); - if ( sep_index == -1 ) { - port = -1; - } else { - port = Integer.parseInt( net.substring( sep_index +1 )); - } - //System.out.println("port: "+port); - return port; - } - - private static void send(String data, String net) { - int port = getPort(net); - net=getDomain(net); + private static void send(String data, String domain,int port) { try { DatagramSocket send; - InetAddress group = InetAddress.getByName(net); + InetAddress group = InetAddress.getByName(domain); send = new MulticastSocket(port); if (group.isMulticastAddress()) { ((MulticastSocket)send).joinGroup(group); } DatagramPacket packet = new DatagramPacket( @@ -174,31 +127,28 @@ class TestNetSwing implements Runnable { } } - private Thread createBroadcastListener(String domain) { - String domainaddr=getDomain(domain); - int port=getPort(domain); - this.domain=domainaddr+":"+port; + private void createBroadcastListener() { try { - InetAddress group = InetAddress.getByName(domainaddr); + InetAddress group = InetAddress.getByName(domainAddr); if (group.isMulticastAddress()) { isMulticastAddress = true; - broadcast = new MulticastSocket(port ); // create the UDP socket + broadcast = new MulticastSocket(port); // create the UDP socket ((MulticastSocket)broadcast).joinGroup(group); } else { - broadcast = new MulticastSocket(port ); // create the UDP socket + broadcast = new MulticastSocket(port); // create the UDP socket } } catch ( IOException e ) { System.out.println("MulticastSocket I/O error" + e ); - return null; + e.printStackTrace(); + System.exit(0); } try { - broadcast.setSoTimeout(100); + broadcast.setSoTimeout(Ivy.TIMEOUTLENGTH); } catch ( java.net.SocketException jns ) { System.out.println("IvyWatcher setSoTimeout error" + jns.getMessage() ); } - // starts a Thread listening on the socket - watcherrunning=true; - return new Thread(this); + watcherThread = new Thread(this); + watcherThread.start(); } private class Ageing implements Runnable { @@ -225,35 +175,58 @@ class TestNetSwing implements Runnable { public void stop(){ encore=false; } } - private class ComboCB implements ActionListener { - public void actionPerformed(ActionEvent e) { - String newDomain=(String)domainBox.getSelectedItem(); - System.out.println("coucou "+ domainBox.getEditor().getItem()); - // if it's the same domain, don't do anything - if (newDomain == domain) { return; } - domain=newDomain; - watcherrunning=false; - server.stop(); - server = createBroadcastListener(domain); - server.start(); + /* + * copied verbatim from IvyWatcher , I should put TestNetSwing *in* the + * distribution itself ... + */ + static String getDomain(String net) throws IvyException { + // System.out.println("debug: net=[" + net+ "]"); + int sep_index = net.lastIndexOf( ":" ); + if ( sep_index != -1 ) { net = net.substring(0,sep_index); } + try { + RE numbersPoint = new RE("([0-9]|\\.)+"); + if (!numbersPoint.match(net)) { + // traceDebug("should only have numbers and point ? I won't add anything... " + net); + return net; + } + net += ".255.255.255"; + RE exp = new RE( "^(\\d+\\.\\d+\\.\\d+\\.\\d+).*"); + if (!exp.match(net)) { + System.out.println("Bad broascat addr " + net); + throw new IvyException("bad broadcast addr"); + } + net=exp.getParen(1); + } catch ( RESyntaxException e ){ + System.out.println(e); + System.exit(0); } - } // ComboCB + // System.out.println("debug: returning net=[" + net+ "]"); + return net; + } + + static int getPort(String net) { // returns 0 if no port is set + int sep_index = net.lastIndexOf( ":" ); + int port= ( sep_index == -1 ) ? 0 :Integer.parseInt( net.substring( sep_index +1 )); + // System.out.println("net: ["+net+"]\nsep_index: "+sep_index+"\nport: "+port); + return port; + } + public static final String helpmsg = "usage: java TestNetSwing [options]\n\t-b BUS\tspecifies the Ivy bus domain\n\t-h\thelp\n\n"; - public static void main(String[] args) { + public static void main(String[] args) throws IvyException { Getopt opt = new Getopt("TestNetSwing",args,"b:h"); - String domain = null; int c; + String domainstring = Ivy.getDomain(null); while ((c = opt.getopt()) != -1) switch (c) { case 'b': - domain=opt.getOptarg(); + domainstring=opt.getOptarg(); break; case 'h': default: System.out.println(helpmsg); System.exit(0); } // getopt - new TestNetSwing(domain); + new TestNetSwing(getDomain(domainstring),getPort(domainstring)); } } // class TestNetSwing diff --git a/tests/build.xml b/tests/build.xml new file mode 100644 index 0000000..03a18b2 --- /dev/null +++ b/tests/build.xml @@ -0,0 +1,65 @@ +<project default="run" basedir="."> + + <!-- Help on usage --> + <target name="usage"> + <echo message="Ivy test suite"/> + <echo message="-------------------------------------------------------------"/> + <echo message=" available targets are:"/> + <echo message=" compile : Generate classes"/> + <echo message=" run : Runs the tests"/> + <echo message="-------------------------------------------------------------"/> + <echo message=""/> + </target> + + <property name="build.compiler" value="gcj -C --encoding=ISO8859_1" /> + + <property name="ivy.home" value=".." /> + <path id="testivy-jars"> + <pathelement location="${ivy.home}/lib/ivy-java.jar"/> + <pathelement location="/usr/share/java/gnu.getopt.jar"/> + <pathelement location="/usr/share/java/regexp.jar"/> + </path> + <property name="testivy-jars" refid="testivy-jars"/> + + <target name="run" depends="compile"> + <echo message="runs the different tests..." /> + <java classpath="${testivy-jars}:classes" fork="true" classname="NewLine"> + <arg line="-n 100000"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="TestApi"></java> + <java classpath="${testivy-jars}:classes" fork="true" classname="fr.dgac.ivy.Ivy"></java> + <java classpath="${testivy-jars}:classes" fork="true" classname="fr.dgac.ivy.Probe"></java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"></java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"> + <arg line="-b 228.1.2.4:4567"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"> + <arg line="-d 100"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"> + <arg line="-d 0"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"> + <arg line="-t 2 -d 100"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="BenchLocal"> + <arg line="-t 2 -d 0"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="AsyncAPI"> + <arg line="-r -l 5 -d 1 -s 10"/> + </java> + <java classpath="${testivy-jars}:classes" fork="true" classname="StopStart"></java> + </target> + + <target name="compile"> + <mkdir dir="classes"/> + <javac classpath="${testivy-jars}" + debug="true" + deprecation="on" + destdir="classes" + includes="**/*.java" + optimize="on" + srcdir="."/> + </target> + +</project> |