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