aboutsummaryrefslogtreecommitdiff
path: root/tests/NewLine.java
blob: 82ccdd1647bc4935a1fec23c0df10c2173d19fd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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=null;
    int c;
    int nb = 10000;
    while ((c = opt.getopt()) != -1) switch (c) {
    case 'b':
      domain=opt.getOptarg();
      break;
    case 'n':
      nb=Integer.parseInt(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);
    bus.protectNewlines(true);
    bus.sendToSelf(true);
    bus.bindMsg("^coucou([^m])monde",new IvyMessageListener() {
      public void receive(IvyClient ic,String[] a) {
	recus++;
	if (recus==nbmsg) System.out.println("received "+nbmsg+" ["+a[0]+"]");
      }
    });
    bus.start(domain);
    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();
  }

}