Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 1 | package com.facebook.thrift.test; |
| 2 | |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 3 | // Generated code |
| 4 | import thrift.test.*; |
| 5 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 6 | import com.facebook.thrift.transport.TTransport; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 7 | import com.facebook.thrift.transport.TSocket; |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 8 | import com.facebook.thrift.transport.THttpClient; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 9 | import com.facebook.thrift.transport.TFramedTransport; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 10 | import com.facebook.thrift.transport.TTransportException; |
| 11 | import com.facebook.thrift.protocol.TBinaryProtocol; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 12 | |
| 13 | import java.util.HashMap; |
| 14 | import java.util.HashSet; |
| 15 | import java.util.ArrayList; |
| 16 | |
| 17 | /** |
| 18 | * Test Java client for thrift. Essentially just a copy of the C++ version, |
| 19 | * this makes a variety of requests to enable testing for both performance and |
| 20 | * correctness of the output. |
| 21 | * |
| 22 | * @author Mark Slee <mcslee@facebook.com> |
| 23 | */ |
| 24 | public class TestClient { |
| 25 | public static void main(String [] args) { |
| 26 | try { |
| 27 | String host = "localhost"; |
| 28 | int port = 9090; |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 29 | String url = null; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 30 | int numTests = 1; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 31 | boolean framed = false; |
| 32 | boolean framedInput = true; |
| 33 | boolean framedOutput = true; |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 34 | |
| 35 | try { |
| 36 | for (int i = 0; i < args.length; ++i) { |
| 37 | if (args[i].equals("-h")) { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 38 | String[] hostport = (args[++i]).split(":"); |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 39 | host = hostport[0]; |
| 40 | port = Integer.valueOf(hostport[1]); |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 41 | } else if (args[i].equals("-f") || args[i].equals("-framed")) { |
| 42 | framed = true; |
| 43 | } else if (args[i].equals("-fo")) { |
| 44 | framed = true; |
| 45 | framedInput = false; |
| 46 | } else if (args[i].equals("-u")) { |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 47 | url = args[++i]; |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 48 | } else if (args[i].equals("-n")) { |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 49 | numTests = Integer.valueOf(args[++i]); |
| 50 | } |
| 51 | } |
| 52 | } catch (Exception x) { |
| 53 | x.printStackTrace(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 56 | TTransport transport; |
| 57 | |
| 58 | if (url != null) { |
| 59 | transport = new THttpClient(url); |
| 60 | } else { |
Mark Slee | a330265 | 2006-10-25 19:03:32 +0000 | [diff] [blame^] | 61 | TSocket socket = new TSocket(host, port); |
| 62 | socket.setTimeout(1000); |
| 63 | transport = socket; |
| 64 | if (framed) { |
| 65 | transport = new TFramedTransport(transport, |
| 66 | framedInput, |
| 67 | framedOutput); |
| 68 | } |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 71 | TBinaryProtocol binaryProtocol = |
| 72 | new TBinaryProtocol(); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 73 | ThriftTest.Client testClient = |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 74 | new ThriftTest.Client(transport, binaryProtocol); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 75 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 76 | long timeMin = 0; |
| 77 | long timeMax = 0; |
| 78 | long timeTot = 0; |
| 79 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 80 | for (int test = 0; test < numTests; ++test) { |
| 81 | |
| 82 | /** |
| 83 | * CONNECT TEST |
| 84 | */ |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 85 | System.out.println("Test #" + (test+1) + ", " + "connect " + host + ":" + port); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 86 | try { |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 87 | transport.open(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 88 | } catch (TTransportException ttx) { |
| 89 | System.out.println("Connect failed: " + ttx.getMessage()); |
| 90 | continue; |
| 91 | } |
| 92 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 93 | long start = System.nanoTime(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * VOID TEST |
| 97 | */ |
| 98 | System.out.print("testVoid()"); |
| 99 | testClient.testVoid(); |
| 100 | System.out.print(" = void\n"); |
| 101 | |
| 102 | /** |
| 103 | * STRING TEST |
| 104 | */ |
| 105 | System.out.print("testString(\"Test\")"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 106 | String s = testClient.testString("Test"); |
| 107 | System.out.print(" = \"" + s + "\"\n"); |
| 108 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 109 | /** |
| 110 | * BYTE TEST |
| 111 | */ |
| 112 | System.out.print("testByte(1)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 113 | byte i8 = testClient.testByte((byte)1); |
| 114 | System.out.print(" = " + i8 + "\n"); |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 115 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 116 | /** |
| 117 | * I32 TEST |
| 118 | */ |
| 119 | System.out.print("testI32(-1)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 120 | int i32 = testClient.testI32(-1); |
| 121 | System.out.print(" = " + i32 + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 122 | |
| 123 | /** |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 124 | * I64 TEST |
| 125 | */ |
| 126 | System.out.print("testI64(-34359738368)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 127 | long i64 = testClient.testI64(-34359738368L); |
| 128 | System.out.print(" = " + i64 + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 129 | |
| 130 | /** |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 131 | * DOUBLE TEST |
| 132 | */ |
| 133 | System.out.print("testDouble(5.325098235)"); |
| 134 | double dub = testClient.testDouble(5.325098235); |
| 135 | System.out.print(" = " + dub + "\n"); |
| 136 | |
| 137 | /** |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 138 | * STRUCT TEST |
| 139 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 140 | System.out.print("testStruct({\"Zero\", 1, -3, -5})"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 141 | Xtruct out = new Xtruct(); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 142 | out.string_thing = "Zero"; |
| 143 | out.byte_thing = (byte) 1; |
| 144 | out.i32_thing = -3; |
| 145 | out.i64_thing = -5; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 146 | Xtruct in = testClient.testStruct(out); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 147 | System.out.print(" = {" + "\"" + in.string_thing + "\", " + in.byte_thing + ", " + in.i32_thing + ", " + in.i64_thing + "}\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * NESTED STRUCT TEST |
| 151 | */ |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 152 | System.out.print("testNest({1, {\"Zero\", 1, -3, -5}), 5}"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 153 | Xtruct2 out2 = new Xtruct2(); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 154 | out2.byte_thing = (short)1; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 155 | out2.struct_thing = out; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 156 | out2.i32_thing = 5; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 157 | Xtruct2 in2 = testClient.testNest(out2); |
| 158 | in = in2.struct_thing; |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 159 | System.out.print(" = {" + in2.byte_thing + ", {" + "\"" + in.string_thing + "\", " + in.byte_thing + ", " + in.i32_thing + ", " + in.i64_thing + "}, " + in2.i32_thing + "}\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * MAP TEST |
| 163 | */ |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 164 | HashMap<Integer,Integer> mapout = new HashMap<Integer,Integer>(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 165 | for (int i = 0; i < 5; ++i) { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 166 | mapout.put(i, i-10); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 167 | } |
| 168 | System.out.print("testMap({"); |
| 169 | boolean first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 170 | for (int key : mapout.keySet()) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 171 | if (first) { |
| 172 | first = false; |
| 173 | } else { |
| 174 | System.out.print(", "); |
| 175 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 176 | System.out.print(key + " => " + mapout.get(key)); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 177 | } |
| 178 | System.out.print("})"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 179 | HashMap<Integer,Integer> mapin = testClient.testMap(mapout); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 180 | System.out.print(" = {"); |
| 181 | first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 182 | for (int key : mapin.keySet()) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 183 | if (first) { |
| 184 | first = false; |
| 185 | } else { |
| 186 | System.out.print(", "); |
| 187 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 188 | System.out.print(key + " => " + mapout.get(key)); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 189 | } |
| 190 | System.out.print("}\n"); |
| 191 | |
| 192 | /** |
| 193 | * SET TEST |
| 194 | */ |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 195 | HashSet<Integer> setout = new HashSet<Integer>(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 196 | for (int i = -2; i < 3; ++i) { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 197 | setout.add(i); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 198 | } |
| 199 | System.out.print("testSet({"); |
| 200 | first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 201 | for (int elem : setout) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 202 | if (first) { |
| 203 | first = false; |
| 204 | } else { |
| 205 | System.out.print(", "); |
| 206 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 207 | System.out.print(elem); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 208 | } |
| 209 | System.out.print("})"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 210 | HashSet<Integer> setin = testClient.testSet(setout); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 211 | System.out.print(" = {"); |
| 212 | first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 213 | for (int elem : setin) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 214 | if (first) { |
| 215 | first = false; |
| 216 | } else { |
| 217 | System.out.print(", "); |
| 218 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 219 | System.out.print(elem); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 220 | } |
| 221 | System.out.print("}\n"); |
| 222 | |
| 223 | /** |
| 224 | * LIST TEST |
| 225 | */ |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 226 | ArrayList<Integer> listout = new ArrayList<Integer>(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 227 | for (int i = -2; i < 3; ++i) { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 228 | listout.add(i); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 229 | } |
| 230 | System.out.print("testList({"); |
| 231 | first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 232 | for (int elem : listout) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 233 | if (first) { |
| 234 | first = false; |
| 235 | } else { |
| 236 | System.out.print(", "); |
| 237 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 238 | System.out.print(elem); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 239 | } |
| 240 | System.out.print("})"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 241 | ArrayList<Integer> listin = testClient.testList(listout); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 242 | System.out.print(" = {"); |
| 243 | first = true; |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 244 | for (int elem : listin) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 245 | if (first) { |
| 246 | first = false; |
| 247 | } else { |
| 248 | System.out.print(", "); |
| 249 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 250 | System.out.print(elem); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 251 | } |
| 252 | System.out.print("}\n"); |
| 253 | |
| 254 | /** |
| 255 | * ENUM TEST |
| 256 | */ |
| 257 | System.out.print("testEnum(ONE)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 258 | int ret = testClient.testEnum(Numberz.ONE); |
| 259 | System.out.print(" = " + ret + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 260 | |
| 261 | System.out.print("testEnum(TWO)"); |
| 262 | ret = testClient.testEnum(Numberz.TWO); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 263 | System.out.print(" = " + ret + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 264 | |
| 265 | System.out.print("testEnum(THREE)"); |
| 266 | ret = testClient.testEnum(Numberz.THREE); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 267 | System.out.print(" = " + ret + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 268 | |
| 269 | System.out.print("testEnum(FIVE)"); |
| 270 | ret = testClient.testEnum(Numberz.FIVE); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 271 | System.out.print(" = " + ret + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 272 | |
| 273 | System.out.print("testEnum(EIGHT)"); |
| 274 | ret = testClient.testEnum(Numberz.EIGHT); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 275 | System.out.print(" = " + ret + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * TYPEDEF TEST |
| 279 | */ |
| 280 | System.out.print("testTypedef(309858235082523)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 281 | long uid = testClient.testTypedef(309858235082523L); |
| 282 | System.out.print(" = " + uid + "\n"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 283 | |
| 284 | /** |
| 285 | * NESTED MAP TEST |
| 286 | */ |
| 287 | System.out.print("testMapMap(1)"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 288 | HashMap<Integer,HashMap<Integer,Integer>> mm = |
| 289 | testClient.testMapMap(1); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 290 | System.out.print(" = {"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 291 | for (int key : mm.keySet()) { |
| 292 | System.out.print(key + " => {"); |
| 293 | HashMap<Integer,Integer> m2 = mm.get(key); |
| 294 | for (int k2 : m2.keySet()) { |
| 295 | System.out.print(k2 + " => " + m2.get(k2) + ", "); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 296 | } |
| 297 | System.out.print("}, "); |
| 298 | } |
| 299 | System.out.print("}\n"); |
| 300 | |
| 301 | /** |
| 302 | * INSANITY TEST |
| 303 | */ |
| 304 | Insanity insane = new Insanity(); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 305 | insane.userMap.put(Numberz.FIVE, (long)5000); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 306 | Xtruct truck = new Xtruct(); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 307 | truck.string_thing = "Truck"; |
| 308 | truck.byte_thing = (byte)8; |
| 309 | truck.i32_thing = 8; |
| 310 | truck.i64_thing = 8; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 311 | insane.xtructs.add(truck); |
| 312 | System.out.print("testInsanity()"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 313 | HashMap<Long,HashMap<Integer,Insanity>> whoa = |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 314 | testClient.testInsanity(insane); |
| 315 | System.out.print(" = {"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 316 | for (long key : whoa.keySet()) { |
| 317 | HashMap<Integer,Insanity> val = whoa.get(key); |
| 318 | System.out.print(key + " => {"); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 319 | |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 320 | for (int k2 : val.keySet()) { |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 321 | Insanity v2 = val.get(k2); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 322 | System.out.print(k2 + " => {"); |
| 323 | HashMap<Integer, Long> userMap = v2.userMap; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 324 | System.out.print("{"); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 325 | for (int k3 : userMap.keySet()) { |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 326 | System.out.print(k3 + " => " + userMap.get(k3) + ", "); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 327 | } |
| 328 | System.out.print("}, "); |
| 329 | |
| 330 | ArrayList<Xtruct> xtructs = v2.xtructs; |
| 331 | System.out.print("{"); |
| 332 | for (Xtruct x : xtructs) { |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 333 | System.out.print("{" + "\"" + x.string_thing + "\", " + x.byte_thing + ", " + x.i32_thing + ", "+ x.i64_thing + "}, "); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 334 | } |
| 335 | System.out.print("}"); |
| 336 | |
| 337 | System.out.print("}, "); |
| 338 | } |
| 339 | System.out.print("}, "); |
| 340 | } |
| 341 | System.out.print("}\n"); |
| 342 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 343 | long stop = System.nanoTime(); |
| 344 | long tot = stop-start; |
| 345 | |
| 346 | System.out.println("Total time: " + tot/1000 + "us"); |
| 347 | |
| 348 | if (timeMin == 0 || tot < timeMin) { |
| 349 | timeMin = tot; |
| 350 | } |
| 351 | if (tot > timeMax) { |
| 352 | timeMax = tot; |
| 353 | } |
| 354 | timeTot += tot; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 355 | |
Mark Slee | b9acf98 | 2006-10-10 01:57:32 +0000 | [diff] [blame] | 356 | transport.close(); |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 357 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 358 | |
| 359 | long timeAvg = timeTot / numTests; |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 360 | |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 361 | System.out.println("Min time: " + timeMin/1000 + "us"); |
| 362 | System.out.println("Max time: " + timeMax/1000 + "us"); |
| 363 | System.out.println("Avg time: " + timeAvg/1000 + "us"); |
| 364 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 365 | } catch (Exception x) { |
| 366 | x.printStackTrace(); |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 369 | } |
Mark Slee | d788b2e | 2006-09-07 01:26:35 +0000 | [diff] [blame] | 370 | |
Mark Slee | 9577100 | 2006-06-07 06:53:25 +0000 | [diff] [blame] | 371 | } |