]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/MathBench.java
LP1827055 Remove Python libs, install bits, and docs
[OpenSRF.git] / src / java / org / opensrf / test / MathBench.java
1 package org.opensrf.test;
2 import org.opensrf.*;
3 import org.opensrf.util.*;
4 import java.util.Date;
5 import java.util.List;
6 import java.util.ArrayList;
7 import java.io.PrintStream;
8
9
10 public class MathBench {
11
12     public static void main(String args[]) throws Exception {
13
14         PrintStream out = System.out;
15
16         if(args.length < 2) {
17             out.println("usage: java org.opensrf.test.MathBench <osrfConfig> <numIterations>");
18             return;
19         }
20
21         /** connect to the opensrf network */
22         Sys.bootstrapClient(args[0], "/config/opensrf");
23
24         /** how many iterations */
25         int count = Integer.parseInt(args[1]);
26
27         /** create the client session */
28         ClientSession session = new ClientSession("opensrf.math");
29
30         /** params are 1,2 */
31         List<Object> params = new ArrayList<Object>();
32         params.add(new Integer(1));
33         params.add(new Integer(2));
34
35         Request request;
36         Result result;
37         long start;
38         double total = 0;
39
40         for(int i = 0; i < count; i++) {
41
42             start = new Date().getTime();
43
44             /** create (and send) the request */
45             request = session.request("add", params);
46
47             /** wait up to 3 seconds for a response */
48             result = request.recv(3000);
49
50             /** collect the round-trip time */
51             total += new Date().getTime() - start;
52
53             if(result.getStatusCode() == Status.OK) {
54                 out.print("+");
55             } else {
56                 out.println("\nrequest failed");
57                 out.println("status = " + result.getStatus());
58                 out.println("status code = " + result.getStatusCode());
59             }
60
61             /** remove this request from the session's request set */
62             request.cleanup();
63
64             if((i+1) % 100 == 0) /** print 100 responses per line */
65                 out.println(" [" + (i+1) + "]");
66         }
67
68         out.println("\nAverage request time is " + (total/count) + " ms");
69         
70         /** remove this session from the global session cache */
71         session.cleanup();
72
73         /** disconnect from the opensrf network */
74         Sys.shutdown();
75     }
76 }
77
78
79