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