aboutsummaryrefslogtreecommitdiff
path: root/tests/NewLine.java
diff options
context:
space:
mode:
authorjestin2004-07-27 16:23:00 +0000
committerjestin2004-07-27 16:23:00 +0000
commitd5d548edaf6cf1ffb2d214b2bf0329ec341c42a1 (patch)
tree7bea89fe499bf27ecc37c1c5b0d58e4639c26421 /tests/NewLine.java
parentfd9c3e8ea4c7093bff92ec2162ca0be338024fa2 (diff)
downloadivy-java-d5d548edaf6cf1ffb2d214b2bf0329ec341c42a1.zip
ivy-java-d5d548edaf6cf1ffb2d214b2bf0329ec341c42a1.tar.gz
ivy-java-d5d548edaf6cf1ffb2d214b2bf0329ec341c42a1.tar.bz2
ivy-java-d5d548edaf6cf1ffb2d214b2bf0329ec341c42a1.tar.xz
major test rewrite to abide to the latest API. Updated tests for async msg
handling and protect newline
Diffstat (limited to 'tests/NewLine.java')
-rw-r--r--tests/NewLine.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/NewLine.java b/tests/NewLine.java
new file mode 100644
index 0000000..78835a3
--- /dev/null
+++ b/tests/NewLine.java
@@ -0,0 +1,66 @@
+import fr.dgac.ivy.* ;
+import gnu.getopt.*;
+
+class NewLine {
+
+ Ivy bus;
+
+ public static void main(String[] args) throws IvyException {
+ Getopt opt = new Getopt("NewLine",args,"b:n:");
+ String domain=Ivy.getDomain(null); // default bus
+ 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;
+ default:
+ System.exit(0);
+ }
+ new NewLine(domain,nb);
+ }
+
+ private int recus = 0;
+ private int nbmsg;
+
+ public NewLine(String domain,int n) throws IvyException {
+ 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() {
+ public void receive(IvyClient ic,String[] args) {
+ recus++;
+ if (recus==nbmsg) System.out.println("received "+nbmsg+" ["+args[0]+"]");
+ }
+ });
+ 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");
+ for (int i=0;i<n;i++ ) {
+ try {
+ bus.sendMsg("coucou\nmonde");
+ } catch (IvyException ie) {
+ System.out.println("exception raised. Exitting");
+ bus.stop();
+ System.exit(-1);
+ }
+ }
+ System.out.println("sending "+nbmsg+" unprotected newlines");
+ bus.protectNewlines(false);
+ recus=0;
+ t2=(new java.util.Date()).getTime();
+ 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");
+ bus.stop();
+ }
+
+}