]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/TestThread.java
added multi-threaded client support to the opensrf network/xmpp layer
[OpenSRF.git] / src / java / org / opensrf / test / TestThread.java
1 package org.opensrf.test;
2 import org.opensrf.*;
3 import org.opensrf.util.*;
4 import java.util.Map;
5 import java.util.Date;
6 import java.util.List;
7 import java.util.ArrayList;
8 import java.io.PrintStream;
9
10 /**
11  * Connects to the opensrf network once per thread and runs
12  * and runs a series of request acccross all launched threads.
13  * The purpose is to verify that the java threaded client api 
14  * is functioning as expected
15  */
16 public class TestThread implements Runnable {
17
18     String args[];
19
20     public TestThread(String args[]) {
21         this.args = args;
22     }
23
24     public void run() {
25
26         try {
27
28             Sys.bootstrapClient(args[0], "/config/opensrf");
29             ClientSession session = new ClientSession(args[3]);
30     
31             List params = new ArrayList<Object>();
32             for(int i = 5; i < args.length; i++) 
33                 params.add(new JSONReader(args[3]).read());
34     
35             for(int i = 0; i < Integer.parseInt(args[2]); i++) {
36                 System.out.println("thread " + Thread.currentThread().getId()+" sending request " + i);
37                 Request request = session.request(args[4], params);
38                 Result result = request.recv(3000);
39                 if(result != null) {
40                     System.out.println("thread " + Thread.currentThread().getId()+ 
41                         " got result JSON: " + new JSONWriter(result.getContent()).write());
42                 } else {
43                     System.out.println("* thread " + Thread.currentThread().getId()+ " got NO result");
44                 }
45             }
46     
47             Sys.shutdown();
48         } catch(Exception e) {
49             System.err.println(e);
50         }
51     }
52
53     public static void main(String args[]) throws Exception {
54
55         if(args.length < 5) {
56             System.out.println( "usage: org.opensrf.test.TestClient "+
57                 "<osrfConfigFile> <numthreads> <numiter> <service> <method> [<JSONparam1>, <JSONparam2>]");
58             return;
59         }
60
61         int numThreads = Integer.parseInt(args[1]);
62         for(int i = 0; i < numThreads; i++) 
63             new Thread(new TestThread(args)).start();
64     }
65 }
66
67
68