aboutsummaryrefslogtreecommitdiff
path: root/tests/BenchLocal.java
diff options
context:
space:
mode:
Diffstat (limited to 'tests/BenchLocal.java')
-rw-r--r--tests/BenchLocal.java111
1 files changed, 54 insertions, 57 deletions
diff --git a/tests/BenchLocal.java b/tests/BenchLocal.java
index f8dc6ac..f0b6863 100644
--- a/tests/BenchLocal.java
+++ b/tests/BenchLocal.java
@@ -1,21 +1,33 @@
-import gnu.regexp.*;
-import gnu.getopt.*;
-import fr.dgac.ivy.*;
-import java.io.*;
-
-/*
+/**
+ * Ivy software bus bench tester
+ *
+ * @author Yannick Jestin <jestin@cena.fr>
+ *
+ * (c) CENA 1998-2004
+ *
* a program with 2 busses testing
* - the rendez vous
* - the IvyMessageListener interface
* - disconnect part of the IvyApplicationListener interface
+ *
+ * CHANGELOG
+ * 1.2.6
+ * - added a timestamp to facilitate the batch processing
+ * - no more necessary to invoque system.exit() when both busses have left.
+ * it used to produce an Exception ...
+ *
*/
+import gnu.getopt.*;
+import fr.dgac.ivy.*;
+import java.io.*;
+
class BenchLocal {
public static final String helpmsg = "usage: java TestLocal [options]\n\t-b domain\n\t-d delay (in ms)\n\t-t test number\n\t-h\thelp\n\n";
- public static void main(String[] args) {
+ public static void main(String[] args) throws IvyException {
Getopt opt = new Getopt("BenchLocal",args,"t:b:d:h");
- String domain=Ivy.getDomain(null); // default bus
+ String domain=Ivy.getDomain(null);
int delay=2000;
int c;
int testtoperform=1;
@@ -37,25 +49,16 @@ class BenchLocal {
new BenchLocal(testtoperform,domain,delay);
}
- public BenchLocal(int testtoperform,String domain,int delay) {
- try {
- switch (testtoperform) {
- case 2: testRegex(domain,delay); break;
- case 1:
- default: test2bus(domain,delay); break;
- }
- } catch (IvyException ie) {
- fail(ie.getMessage());
+ public BenchLocal(int testtoperform,String domain,int delay) throws IvyException {
+ switch (testtoperform) {
+ case 2: testRegex(domain,delay); break;
+ case 1:
+ default: test2bus(domain,delay); break;
}
}
- void fail(String msg) {
- System.out.println("failed: "+msg);
- System.exit(-1);
- }
-
void sleep(int delay) {
- System.out.println("waiting "+delay+" ms");
+ log("waiting "+delay+" ms");
try { Thread.sleep(delay); } catch (InterruptedException ie) { }
}
@@ -64,7 +67,6 @@ class BenchLocal {
IAL ial=new IAL();
bus1=new Ivy("BUS1","Bus1 ready",ial);
bus2=new Ivy("BUS2","Bus2 ready",ial);
- ial.setBusses(bus1,bus2);
bus1.bindMsg("^Bus2 ready",new RML(bus1,delay));
SuccessStory success=new SuccessStory(bus1,bus2);
bus2.bindMsg("^([^ ]*) ([^ ]*) ([^ ]*)$",new RMLAnswer1(success));
@@ -79,11 +81,14 @@ class BenchLocal {
int delay;
public RML(Ivy b,int delay) { this.b=b;this.delay=delay; }
public void receive(IvyClient c,String[] args) {
- b.sendMsg("a b c");
- sleep(delay);
- b.sendMsg("");
- sleep(delay);
- b.sendMsg("x=1 y=2 z=3");
+ try {
+ b.sendMsg("a b c");
+ sleep(delay);
+ b.sendMsg("");
+ sleep(delay);
+ b.sendMsg("x=1 y=2 z=3");
+ } catch (IvyException ie) {
+ }
b.stop();
}
}
@@ -94,9 +99,9 @@ class BenchLocal {
public SuccessStory(Ivy b1,Ivy b2){this.b1=b1;this.b2=b2;}
public void incr(){
i++;
- System.out.println("regex "+i+" successful");
+ log("regex "+i+" successful");
if (i==3) {
- System.out.println("quitting the bus");
+ log("quitting the bus");
b1.stop();b2.stop();
}
}
@@ -134,16 +139,15 @@ class BenchLocal {
public void test2bus(String domain,int delay) throws IvyException {
Ivy bus1,bus2;
IAL ial=new IAL();
- System.out.println("starting with delay="+delay+" ms between the two starts");
+ log("starting with delay="+delay+" ms between the two starts");
bus1=new Ivy("BUS1","Bus1 ready",ial);
bus2=new Ivy("BUS2","Bus2 ready",ial);
- ial.setBusses(bus1,bus2);
bus1.bindMsg("^Bus2 ready",new SENDOUT(bus1));
bus2.bindMsg("^out$",new DIE(bus2));
- System.out.println("starting Bus1");
+ log("starting Bus1");
bus1.start(domain);
sleep(delay);
- System.out.println("starting Bus2");
+ log("starting Bus2");
bus2.start(domain);
}
@@ -151,39 +155,32 @@ class BenchLocal {
Ivy b;
public SENDOUT(Ivy b) {this.b=b;}
public void receive(IvyClient client,String[] arg) {
- System.out.println("received ready message");
- b.sendMsg("out");
+ log("received ready message");
+ try {
+ b.sendMsg("out");
+ } catch (IvyException ie) {
+ }
b.stop();
}
}
- private class IAL implements IvyApplicationListener {
- Ivy b1,b2;
- int count=0;
- public void setBusses(Ivy b1,Ivy b2) {
- this.b1=b1;
- this.b2=b2;
- }
- public void disconnect(IvyClient c) {
- if ( (c.getApplicationName().compareTo("BUS1")==0)
- ||(c.getApplicationName().compareTo("BUS2")==0) ) {
- count++;
- System.out.println(c.getApplicationName()+" left");
- if (count==2) {System.exit(0);}
- }
- }
- public void connect(IvyClient c) { }
- public void directMessage(IvyClient c,int id,String arg) { }
- public void die(IvyClient c,int id) { }
+ private class IAL extends IvyApplicationAdapter {
+ public void disconnect(IvyClient c) { log(c.getApplicationName()+" left"); }
}
private class DIE implements IvyMessageListener {
Ivy b;
public DIE(Ivy b) {this.b=b; }
public void receive(IvyClient client,String[] arg) {
- System.out.println("received out message");
- b.stop();
+ log("received out message");
+ b.stop(); // I leave the bus
}
}
+ private static java.text.DateFormat df = java.text.DateFormat.getTimeInstance();
+ private void log(String s) {
+ java.util.Date d = new java.util.Date();
+ System.out.println("* ["+df.format(d)+"] "+s);
+ }
+
}