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