From a2d52b943e3064b8ca86a8a59b8970898b373a34 Mon Sep 17 00:00:00 2001 From: jestin Date: Fri, 22 Jul 2011 16:53:52 +0000 Subject: --- tests/BenchLocal.java | 58 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'tests/BenchLocal.java') diff --git a/tests/BenchLocal.java b/tests/BenchLocal.java index 6c11360..ef0e4c7 100644 --- a/tests/BenchLocal.java +++ b/tests/BenchLocal.java @@ -1,9 +1,10 @@ /** * Ivy software bus bench tester * - * @author Yannick Jestin + * @author Yannick Jestin * * (c) CENA 1998-2004 + * (c) ENAC 2005-2011 * * a program with 2 busses testing * - the rendez vous @@ -49,10 +50,15 @@ class BenchLocal { } public BenchLocal(int testtoperform,String domain,int delay) throws IvyException { + System.out.println("test to perform: "+testtoperform); switch (testtoperform) { - case 2: testRegex(domain,delay); break; + case 2: + testRegex(domain,delay); + break; case 1: - default: test2bus(domain,delay); break; + default: + test2bus(domain,delay); + break; } } @@ -67,11 +73,11 @@ class BenchLocal { IAL ial=new IAL(); bus1=new Ivy("BUS1","Bus1 ready",ial); bus2=new Ivy("BUS2","Bus2 ready",ial); - bus1.bindMsg("^Bus2 ready",new RML(bus1,delay)); SuccessStory success=new SuccessStory(bus1,bus2); + bus1.bindMsg("^Bus2 ready",new RML(bus1,delay)); bus2.bindMsg("^([^ ]*) ([^ ]*) ([^ ]*)$",new RMLAnswer1(success)); - bus2.bindMsg("(.*)",new RMLAnswer2(success)); - bus2.bindMsg("y=([^ ]*)",new RMLAnswer3(success)); + bus2.bindMsg("blah(.*)",new RMLAnswer2(success)); + bus2.bindMsg(".*y=([^ ]+).*",new RMLAnswer3(success)); bus1.start(domain); bus2.start(domain); } @@ -84,25 +90,32 @@ class BenchLocal { try { b.sendMsg("a b c"); sleep(delay); - b.sendMsg(""); + b.sendMsg("blah"); sleep(delay); b.sendMsg("x=1 y=2 z=3"); } catch (IvyException ie) { + ie.printStackTrace(); } b.stop(); } } private class SuccessStory { - int i=0; + Object lock = new Object(); + private int i=0; Ivy b1,b2; public SuccessStory(Ivy b1,Ivy b2){this.b1=b1;this.b2=b2;} public void incr(){ - i++; - log("regex "+i+" successful"); - if (i==3) { - log("quitting the bus"); - b1.stop();b2.stop(); + synchronized (lock) { + i++; + log("regex "+i+" successful"); + if (i>=3) { + log("quitting the bus"); + b1.stop(); + b2.stop(); + } else { + log("pas encore, j'ai reçu "+i+" <3"); + } } } } @@ -114,16 +127,21 @@ class BenchLocal { if ( (args.length==3) && (args[0].compareTo("a")==0) && (args[1].compareTo("b")==0) - && (args[2].compareTo("c")==0) - ) ss.incr(); - } + && (args[2].compareTo("c")==0)) { + ss.incr(); + System.out.println("answer 1 ok"); + } + } } private class RMLAnswer2 implements IvyMessageListener { SuccessStory ss; public RMLAnswer2(SuccessStory ss) {this.ss=ss;} public void receive(IvyClient c,String[] args) { - if ( (args.length==1) && (args[0].compareTo("")==0) ) ss.incr(); + if ( (args.length==1) && (args[0].compareTo("")==0) ) { + ss.incr(); + System.out.println("answer 2 ok"); + } } } @@ -132,7 +150,10 @@ class BenchLocal { public RMLAnswer3(SuccessStory ss) {this.ss=ss;} public void receive(IvyClient c,String[] args) { if ( (args.length==1) && (args[0].compareTo("2")==0) - ) ss.incr(); + ) { + ss.incr(); + System.out.println("answer 3 ok"); + } } } @@ -159,6 +180,7 @@ class BenchLocal { try { b.sendMsg("out"); } catch (IvyException ie) { + ie.printStackTrace(); } b.stop(); } -- cgit v1.1