From 1c5d4da0b5be2f8532c96e9bc477c34e5687ae19 Mon Sep 17 00:00:00 2001 From: jestin Date: Wed, 2 Aug 2006 16:23:18 +0000 Subject: ibid --- tests/AsyncAPI.java | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/StopStart.java | 30 +++++++++++ 2 files changed, 180 insertions(+) create mode 100644 tests/AsyncAPI.java create mode 100644 tests/StopStart.java (limited to 'tests') diff --git a/tests/AsyncAPI.java b/tests/AsyncAPI.java new file mode 100644 index 0000000..eca9ddc --- /dev/null +++ b/tests/AsyncAPI.java @@ -0,0 +1,150 @@ +/** + * Ivy java Async API tester: bindAsyncMsg, sendAsyncMsg. + * + * @author Yannick Jestin + * + * (c) CENA + * + * usage: java AsyncAPI -h + * + * this program tests the Asynchronous reception of messages ( each callback + * is performed in a separate threads ). It also exhibits the behaviour of the + * library with regards to concurrent connections ! To stress the test, try it + * with different JVM ( kaffe is especially hard to pass ), and on SMP + * machines ... + * + * changelog + * + * 1.2.6 : async sending seems utterly buggy ... + * + */ +import fr.dgac.ivy.*; +import gnu.getopt.*; + +class AsyncAPI { + + public static final int MSGSIZE = 10; + 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 RECEIVENAME = "MSreceive"; + public static final String SENDNAME = "MSsend"; + private static long epoch = System.currentTimeMillis(); + + private Ivy bus; + DelayAnswer delay; + int re; + private String name; + boolean verbose; + private int nbpacket; + private int count=0,total=0; + protected Integer truc = new Integer(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.start(domain); + } + + private static java.text.DateFormat df = java.text.DateFormat.getTimeInstance(); + private static String date() { + return "["+df.format(new java.util.Date())+"] "; + } + + class DelayAnswer implements IvyMessageListener { + int delay; + public DelayAnswer(int delay) { + this.delay=delay; + } + 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