1 package org.opensrf.test;
3 import org.opensrf.util.*;
7 import java.util.ArrayList;
8 import java.io.PrintStream;
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
16 public class TestThread implements Runnable {
20 public TestThread(String args[]) {
28 Sys.bootstrapClient(args[0], "/config/opensrf");
29 ClientSession session = new ClientSession(args[3]);
31 List params = new ArrayList<Object>();
32 for(int i = 5; i < args.length; i++)
33 params.add(new JSONReader(args[3]).read());
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);
40 System.out.println("thread " + Thread.currentThread().getId()+
41 " got result JSON: " + new JSONWriter(result.getContent()).write());
43 System.out.println("* thread " + Thread.currentThread().getId()+ " got NO result");
48 } catch(Exception e) {
49 System.err.println(e);
53 public static void main(String args[]) throws Exception {
56 System.out.println( "usage: org.opensrf.test.TestClient "+
57 "<osrfConfigFile> <numthreads> <numiter> <service> <method> [<JSONparam1>, <JSONparam2>]");
61 int numThreads = Integer.parseInt(args[1]);
62 for(int i = 0; i < numThreads; i++)
63 new Thread(new TestThread(args)).start();