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