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