aboutsummaryrefslogtreecommitdiff
path: root/tests/AsyncAPI.java
diff options
context:
space:
mode:
authorjestin2011-07-22 16:53:52 +0000
committerjestin2011-07-22 16:53:52 +0000
commita2d52b943e3064b8ca86a8a59b8970898b373a34 (patch)
tree8a52265d63c6873ff95fb12d7482284591bbb7fb /tests/AsyncAPI.java
parentfc9a1e00e64dfbfc4b9d7abf9b1660f2abbdc3ba (diff)
downloadivy-java-a2d52b943e3064b8ca86a8a59b8970898b373a34.zip
ivy-java-a2d52b943e3064b8ca86a8a59b8970898b373a34.tar.gz
ivy-java-a2d52b943e3064b8ca86a8a59b8970898b373a34.tar.bz2
ivy-java-a2d52b943e3064b8ca86a8a59b8970898b373a34.tar.xz
Diffstat (limited to 'tests/AsyncAPI.java')
-rw-r--r--tests/AsyncAPI.java83
1 files changed, 49 insertions, 34 deletions
diff --git a/tests/AsyncAPI.java b/tests/AsyncAPI.java
index eca9ddc..2b85745 100644
--- a/tests/AsyncAPI.java
+++ b/tests/AsyncAPI.java
@@ -27,7 +27,7 @@ class AsyncAPI {
public static final int NBITER = 100;
public static final int DELAYMS = 1000;
public static final String HEADER = "ASYNCPACKET";
- public static final String TOSUBSCRIBE = "^"+HEADER+"([0-9]*) (.*)";
+ public static final String TOSUBSCRIBE = "^"+HEADER+"([0-9]+) (.*)";
public static final String RECEIVENAME = "MSreceive";
public static final String SENDNAME = "MSsend";
private static long epoch = System.currentTimeMillis();
@@ -38,19 +38,17 @@ class AsyncAPI {
private String name;
boolean verbose;
private int nbpacket;
- private int count=0,total=0;
- protected Integer truc = new Integer(0);
+ private int wait=0;
public AsyncAPI(int nb,String domain,int d, boolean v,boolean async) throws IvyException {
verbose=v;
nbpacket=nb;
name = "MSreceive";
- bus = new Ivy(name,name+" Ready", null);
- delay=new DelayAnswer(d);
- if (async)
- re = bus.bindAsyncMsg(TOSUBSCRIBE,delay);
- else
- re = bus.bindMsg(TOSUBSCRIBE,delay);
+ bus = new Ivy(name,null, null);
+ wait = d;
+ delay=new DelayAnswer();
+ if (async) re = bus.bindAsyncMsg(TOSUBSCRIBE,delay,BindType.ASYNC);
+ else re = bus.bindMsg(TOSUBSCRIBE,delay);
bus.start(domain);
}
@@ -59,29 +57,46 @@ class AsyncAPI {
return "["+df.format(new java.util.Date())+"] ";
}
- class DelayAnswer implements IvyMessageListener {
- int delay;
- public DelayAnswer(int delay) {
- this.delay=delay;
+
+ static Object truc = new Object();
+ int count=0,total=0;
+ int status = 0;
+
+ synchronized void huh(IvyClient ic, String[] args) {
+ count++;
+ if (verbose) {
+ System.out.println(date()+"RECEIVE "+ count+"/"+nbpacket+" packets received arg:("+args[0]+")");
+ int nb = Integer.parseInt(args[0]);
+ total+=nb;
+ if (nb!=count) {
+ System.out.println("RECEIVE *** ERROR *** "+count+"!="+nb+ " - probable double connexion");
+ for (IvyClient i : bus.getIvyClients() ) System.out.println("client: "+i);
+ ic.sendDie("nok, bye");
+ bus.stop();
+ System.exit(-1);
+ }
}
+ if (count<nbpacket) return;
+ if (total==(((nbpacket+1)*nbpacket)/2)) {
+ System.out.println("RECEIVE receiver quitting the bus normally");
+ ic.sendDie("ok, bye");
+ bus.stop();
+ } else {
+ System.out.println("RECEIVE wrong count and total, hit ^C to exit");
+ //System.exit(-1);
+ }
+ }
+
+ class DelayAnswer implements IvyMessageListener {
public void receive(IvyClient ic, String[] args) {
- synchronized(truc) {
- count++;
- if (verbose) {
- System.out.println(date()+count+"/"+nbpacket+" packets received ("+args[0]+")");
- total+=Integer.parseInt(args[0]);
- }
- if (count<nbpacket) return;
- if (total==(((nbpacket+1)*nbpacket)/2)) {
- System.out.println("receiver quitting the bus normally");
- ic.sendDie("ok, bye");
- bus.stop();
- } else {
- System.out.println("wrong count and total, hit ^C to exit");
- //System.exit(-1);
- }
+ huh(ic,args);
+ try {
+ System.out.println("RECEIVE Sleeping "+wait+"ms");
+ Thread.sleep(wait);
+ System.out.println("RECEIVE Finished Sleeping");
+ } catch (InterruptedException ie) {
+ ie.printStackTrace();
}
- try { Thread.sleep(delay); } catch (InterruptedException ie) { }
}
}
@@ -127,21 +142,21 @@ class AsyncAPI {
doasyncBind+" asyncSend:"+doasyncSend+" msgsize:"+size);
AsyncAPI receiver = new AsyncAPI(nb,domain,delay,verbose,doasyncBind);
- Ivy mainbus = new Ivy(SENDNAME,SENDNAME+" Ready", null);
+ Ivy mainbus = new Ivy(SENDNAME,null, null);
mainbus.start(domain);
if ((mainbus.waitForClient(RECEIVENAME,5000))==null) {
System.out.println(RECEIVENAME+" did not join the bus. Quitting");
- System.exit(0);
+ System.exit(-1);
}
System.out.println(RECEIVENAME+" is here, sending packets");
StringBuffer tosend = new StringBuffer(size);
for (int i=0;i<size;i++) tosend.append("a");
for (int i=1;i<=nb;i++) {
- if (verbose) System.out.println(date()+"sending packet "+i);
+ if (verbose) System.out.println(date()+"SENDER sending packet "+i);
mainbus.sendMsg(HEADER+i+" "+tosend.toString());
- // mainbus.sendMsg(HEADER+i+" "+tosend.toString(),doasyncSend);
+ // TODO mainbus.sendMsg(HEADER+i+" "+tosend.toString(),doasyncSend);
}
- System.out.println(date()+"sender has sent all its packets, waiting for a die message");
+ System.out.println(date()+"SENDER sender has sent all its packets, waiting for a die message");
// i won't stop the sender's bus here, otherwise the all the packet
// can still be unprocessed
// TODO regession test for Ivy.stop()