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