David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 20 | // Distributed under the Thrift Software License |
| 21 | // |
| 22 | // See accompanying file LICENSE or visit the Thrift site at: |
| 23 | // http://developers.facebook.com/thrift/ |
| 24 | using System; |
| 25 | using System.Collections.Generic; |
Jens Geyer | c1d7943 | 2014-04-22 22:52:43 +0200 | [diff] [blame] | 26 | using System.Security.Cryptography.X509Certificates; |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 27 | using Thrift.Collections; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 28 | using Thrift.Test; //generated code |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 29 | using Thrift.Transport; |
| 30 | using Thrift.Protocol; |
| 31 | using Thrift.Server; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 32 | using Thrift; |
| 33 | using System.Threading; |
| 34 | using System.Text; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 35 | |
| 36 | namespace Test |
| 37 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 38 | public class TestServer |
| 39 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 40 | public static int _clientID = -1; |
| 41 | public delegate void TestLogDelegate(string msg, params object[] values); |
| 42 | |
Randy Abernethy | 0e86f1f | 2014-07-13 09:50:19 -0700 | [diff] [blame] | 43 | public class TradeServerEventHandler : TServerEventHandler |
| 44 | { |
| 45 | public int callCount = 0; |
| 46 | public void preServe() |
| 47 | { |
| 48 | callCount++; |
| 49 | } |
| 50 | public Object createContext(Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 51 | { |
| 52 | callCount++; |
| 53 | return null; |
| 54 | } |
| 55 | public void deleteContext(Object serverContext, Thrift.Protocol.TProtocol input, Thrift.Protocol.TProtocol output) |
| 56 | { |
| 57 | callCount++; |
| 58 | } |
| 59 | public void processContext(Object serverContext, Thrift.Transport.TTransport transport) |
| 60 | { |
| 61 | callCount++; |
| 62 | } |
| 63 | }; |
| 64 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 65 | public class TestHandler : ThriftTest.Iface, Thrift.TControllingHandler |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 66 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 67 | public TServer server { get; set; } |
| 68 | private int handlerID; |
| 69 | private StringBuilder reusableStringBuilder = new StringBuilder(); |
| 70 | private TestLogDelegate testLogDelegate; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 71 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 72 | public TestHandler() |
| 73 | { |
| 74 | handlerID = Interlocked.Increment(ref _clientID); |
| 75 | testLogDelegate += testConsoleLogger; |
| 76 | testLogDelegate.Invoke("New TestHandler instance created"); |
| 77 | } |
| 78 | |
| 79 | public void testConsoleLogger(string msg, params object[] values) |
| 80 | { |
| 81 | reusableStringBuilder.Clear(); |
| 82 | reusableStringBuilder.AppendFormat("handler{0:D3}:",handlerID); |
| 83 | reusableStringBuilder.AppendFormat(msg, values); |
| 84 | reusableStringBuilder.AppendLine(); |
| 85 | Console.Write( reusableStringBuilder.ToString() ); |
| 86 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 87 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 88 | public void testVoid() |
| 89 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 90 | testLogDelegate.Invoke("testVoid()"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 91 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 92 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 93 | public string testString(string thing) |
| 94 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 95 | testLogDelegate.Invoke("testString({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 96 | return thing; |
| 97 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 98 | |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 99 | public bool testBool(bool thing) |
| 100 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 101 | testLogDelegate.Invoke("testBool({0})", thing); |
Nobuaki Sukegawa | a649e74 | 2015-09-21 13:53:25 +0900 | [diff] [blame] | 102 | return thing; |
| 103 | } |
| 104 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 105 | public sbyte testByte(sbyte thing) |
| 106 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 107 | testLogDelegate.Invoke("testByte({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 108 | return thing; |
| 109 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 110 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 111 | public int testI32(int thing) |
| 112 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 113 | testLogDelegate.Invoke("testI32({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 114 | return thing; |
| 115 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 116 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 117 | public long testI64(long thing) |
| 118 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 119 | testLogDelegate.Invoke("testI64({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 120 | return thing; |
| 121 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 122 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 123 | public double testDouble(double thing) |
| 124 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 125 | testLogDelegate.Invoke("testDouble({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 126 | return thing; |
| 127 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 128 | |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 129 | public byte[] testBinary(byte[] thing) |
| 130 | { |
| 131 | string hex = BitConverter.ToString(thing).Replace("-", string.Empty); |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 132 | testLogDelegate.Invoke("testBinary({0:X})", hex); |
Jens Geyer | 71e814a | 2014-12-13 23:40:35 +0100 | [diff] [blame] | 133 | return thing; |
| 134 | } |
| 135 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 136 | public Xtruct testStruct(Xtruct thing) |
| 137 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 138 | testLogDelegate.Invoke("testStruct({{\"{0}\", {1}, {2}, {3}}})", thing.String_thing, thing.Byte_thing, thing.I32_thing, thing.I64_thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 139 | return thing; |
| 140 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 141 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 142 | public Xtruct2 testNest(Xtruct2 nest) |
| 143 | { |
| 144 | Xtruct thing = nest.Struct_thing; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 145 | testLogDelegate.Invoke("testNest({{{0}, {{\"{1}\", {2}, {3}, {4}, {5}}}}})", |
| 146 | nest.Byte_thing, |
| 147 | thing.String_thing, |
| 148 | thing.Byte_thing, |
| 149 | thing.I32_thing, |
| 150 | thing.I64_thing, |
| 151 | nest.I32_thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 152 | return nest; |
| 153 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 154 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 155 | public Dictionary<int, int> testMap(Dictionary<int, int> thing) |
| 156 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 157 | reusableStringBuilder.Clear(); |
| 158 | reusableStringBuilder.Append("testMap({{"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 159 | bool first = true; |
| 160 | foreach (int key in thing.Keys) |
| 161 | { |
| 162 | if (first) |
| 163 | { |
| 164 | first = false; |
| 165 | } |
| 166 | else |
| 167 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 168 | reusableStringBuilder.Append(", "); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 169 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 170 | reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 171 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 172 | reusableStringBuilder.Append("}})"); |
| 173 | testLogDelegate.Invoke(reusableStringBuilder.ToString()); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 174 | return thing; |
| 175 | } |
Jens Geyer | 1c99e70 | 2014-03-17 22:50:39 +0200 | [diff] [blame] | 176 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 177 | public Dictionary<string, string> testStringMap(Dictionary<string, string> thing) |
| 178 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 179 | reusableStringBuilder.Clear(); |
| 180 | reusableStringBuilder.Append("testStringMap({{"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 181 | bool first = true; |
| 182 | foreach (string key in thing.Keys) |
| 183 | { |
| 184 | if (first) |
| 185 | { |
| 186 | first = false; |
| 187 | } |
| 188 | else |
| 189 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 190 | reusableStringBuilder.Append(", "); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 191 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 192 | reusableStringBuilder.AppendFormat("{0} => {1}", key, thing[key]); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 193 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 194 | reusableStringBuilder.Append("}})"); |
| 195 | testLogDelegate.Invoke(reusableStringBuilder.ToString()); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 196 | return thing; |
| 197 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 198 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 199 | public THashSet<int> testSet(THashSet<int> thing) |
| 200 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 201 | reusableStringBuilder.Clear(); |
| 202 | reusableStringBuilder.Append("testSet({{"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 203 | bool first = true; |
| 204 | foreach (int elem in thing) |
| 205 | { |
| 206 | if (first) |
| 207 | { |
| 208 | first = false; |
| 209 | } |
| 210 | else |
| 211 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 212 | reusableStringBuilder.Append(", "); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 213 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 214 | reusableStringBuilder.AppendFormat("{0}", elem); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 215 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 216 | reusableStringBuilder.Append("}})"); |
| 217 | testLogDelegate.Invoke(reusableStringBuilder.ToString()); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 218 | return thing; |
| 219 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 220 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 221 | public List<int> testList(List<int> thing) |
| 222 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 223 | reusableStringBuilder.Clear(); |
| 224 | reusableStringBuilder.Append("testList({{"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 225 | bool first = true; |
| 226 | foreach (int elem in thing) |
| 227 | { |
| 228 | if (first) |
| 229 | { |
| 230 | first = false; |
| 231 | } |
| 232 | else |
| 233 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 234 | reusableStringBuilder.Append(", "); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 235 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 236 | reusableStringBuilder.AppendFormat("{0}", elem); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 237 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 238 | reusableStringBuilder.Append("}})"); |
| 239 | testLogDelegate.Invoke(reusableStringBuilder.ToString()); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 240 | return thing; |
| 241 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 242 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 243 | public Numberz testEnum(Numberz thing) |
| 244 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 245 | testLogDelegate.Invoke("testEnum({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 246 | return thing; |
| 247 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 248 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 249 | public long testTypedef(long thing) |
| 250 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 251 | testLogDelegate.Invoke("testTypedef({0})", thing); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 252 | return thing; |
| 253 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 254 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 255 | public Dictionary<int, Dictionary<int, int>> testMapMap(int hello) |
| 256 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 257 | testLogDelegate.Invoke("testMapMap({0})", hello); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 258 | Dictionary<int, Dictionary<int, int>> mapmap = |
| 259 | new Dictionary<int, Dictionary<int, int>>(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 260 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 261 | Dictionary<int, int> pos = new Dictionary<int, int>(); |
| 262 | Dictionary<int, int> neg = new Dictionary<int, int>(); |
| 263 | for (int i = 1; i < 5; i++) |
| 264 | { |
| 265 | pos[i] = i; |
| 266 | neg[-i] = -i; |
| 267 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 268 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 269 | mapmap[4] = pos; |
| 270 | mapmap[-4] = neg; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 271 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 272 | return mapmap; |
| 273 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 274 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 275 | public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument) |
| 276 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 277 | testLogDelegate.Invoke("testInsanity()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 278 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 279 | Xtruct hello = new Xtruct(); |
| 280 | hello.String_thing = "Hello2"; |
| 281 | hello.Byte_thing = 2; |
| 282 | hello.I32_thing = 2; |
| 283 | hello.I64_thing = 2; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 284 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 285 | Xtruct goodbye = new Xtruct(); |
| 286 | goodbye.String_thing = "Goodbye4"; |
| 287 | goodbye.Byte_thing = (sbyte)4; |
| 288 | goodbye.I32_thing = 4; |
| 289 | goodbye.I64_thing = (long)4; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 290 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 291 | Insanity crazy = new Insanity(); |
| 292 | crazy.UserMap = new Dictionary<Numberz, long>(); |
| 293 | crazy.UserMap[Numberz.EIGHT] = (long)8; |
| 294 | crazy.Xtructs = new List<Xtruct>(); |
| 295 | crazy.Xtructs.Add(goodbye); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 296 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 297 | Insanity looney = new Insanity(); |
| 298 | crazy.UserMap[Numberz.FIVE] = (long)5; |
| 299 | crazy.Xtructs.Add(hello); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 300 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 301 | Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>(); |
| 302 | Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 303 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 304 | first_map[Numberz.TWO] = crazy; |
| 305 | first_map[Numberz.THREE] = crazy; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 306 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 307 | second_map[Numberz.SIX] = looney; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 308 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 309 | Dictionary<long, Dictionary<Numberz, Insanity>> insane = |
| 310 | new Dictionary<long, Dictionary<Numberz, Insanity>>(); |
| 311 | insane[(long)1] = first_map; |
| 312 | insane[(long)2] = second_map; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 313 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 314 | return insane; |
| 315 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 316 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 317 | public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5) |
| 318 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 319 | testLogDelegate.Invoke("testMulti()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 320 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 321 | Xtruct hello = new Xtruct(); ; |
| 322 | hello.String_thing = "Hello2"; |
| 323 | hello.Byte_thing = arg0; |
| 324 | hello.I32_thing = arg1; |
| 325 | hello.I64_thing = arg2; |
| 326 | return hello; |
| 327 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 328 | |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 329 | /** |
| 330 | * Print 'testException(%s)' with arg as '%s' |
| 331 | * @param string arg - a string indication what type of exception to throw |
| 332 | * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 333 | * elsen if arg == "TException" throw TException |
| 334 | * else do not throw anything |
| 335 | */ |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 336 | public void testException(string arg) |
| 337 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 338 | testLogDelegate.Invoke("testException({0})", arg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 339 | if (arg == "Xception") |
| 340 | { |
| 341 | Xception x = new Xception(); |
| 342 | x.ErrorCode = 1001; |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 343 | x.Message = arg; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 344 | throw x; |
| 345 | } |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 346 | if (arg == "TException") |
| 347 | { |
| 348 | throw new Thrift.TException(); |
| 349 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 350 | return; |
| 351 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 352 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 353 | public Xtruct testMultiException(string arg0, string arg1) |
| 354 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 355 | testLogDelegate.Invoke("testMultiException({0}, {1})", arg0,arg1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 356 | if (arg0 == "Xception") |
| 357 | { |
| 358 | Xception x = new Xception(); |
| 359 | x.ErrorCode = 1001; |
| 360 | x.Message = "This is an Xception"; |
| 361 | throw x; |
| 362 | } |
| 363 | else if (arg0 == "Xception2") |
| 364 | { |
| 365 | Xception2 x = new Xception2(); |
| 366 | x.ErrorCode = 2002; |
| 367 | x.Struct_thing = new Xtruct(); |
| 368 | x.Struct_thing.String_thing = "This is an Xception2"; |
| 369 | throw x; |
| 370 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 371 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 372 | Xtruct result = new Xtruct(); |
| 373 | result.String_thing = arg1; |
| 374 | return result; |
| 375 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 376 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 377 | public void testStop() |
| 378 | { |
| 379 | if (server != null) |
| 380 | { |
| 381 | server.Stop(); |
| 382 | } |
| 383 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 384 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 385 | public void testOneway(int arg) |
| 386 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 387 | testLogDelegate.Invoke("testOneway({0}), sleeping...", arg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 388 | System.Threading.Thread.Sleep(arg * 1000); |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 389 | testLogDelegate.Invoke("testOneway finished"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 390 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 391 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 392 | } // class TestHandler |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 393 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 394 | private enum ServerType |
| 395 | { |
| 396 | TSimpleServer, |
| 397 | TThreadedServer, |
| 398 | TThreadPoolServer, |
| 399 | } |
| 400 | |
| 401 | private enum ProcessorFactoryType |
| 402 | { |
| 403 | TSingletonProcessorFactory, |
| 404 | TPrototypeProcessorFactory, |
| 405 | } |
| 406 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 407 | public static bool Execute(string[] args) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 408 | { |
| 409 | try |
| 410 | { |
| 411 | bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 412 | ServerType serverType = ServerType.TSimpleServer; |
| 413 | ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 414 | int port = 9090; |
| 415 | string pipe = null; |
| 416 | for (int i = 0; i < args.Length; i++) |
| 417 | { |
| 418 | if (args[i] == "-pipe") // -pipe name |
| 419 | { |
| 420 | pipe = args[++i]; |
| 421 | } |
| 422 | else if (args[i].Contains("--port=")) |
| 423 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 424 | port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 425 | } |
| 426 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 427 | { |
| 428 | useBufferedSockets = true; |
| 429 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 430 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 431 | { |
| 432 | useFramed = true; |
| 433 | } |
| 434 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 435 | { |
| 436 | compact = true; |
| 437 | } |
| 438 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 439 | { |
| 440 | json = true; |
| 441 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 442 | else if (args[i] == "--threaded" || args[i] == "--server-type=threaded") |
| 443 | { |
| 444 | serverType = ServerType.TThreadedServer; |
| 445 | } |
| 446 | else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool") |
| 447 | { |
| 448 | serverType = ServerType.TThreadPoolServer; |
| 449 | } |
| 450 | else if (args[i] == "--prototype" || args[i] == "--processor=prototype") |
| 451 | { |
| 452 | processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory; |
| 453 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 454 | else if (args[i] == "--ssl") |
| 455 | { |
| 456 | useEncryption = true; |
| 457 | } |
| 458 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 459 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 460 | // Transport |
| 461 | TServerTransport trans; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 462 | if (pipe != null) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 463 | { |
| 464 | trans = new TNamedPipeServerTransport(pipe); |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | if (useEncryption) |
| 469 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 470 | string certPath = "../../../../test/keys/server.p12"; |
| 471 | trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2(certPath, "thrift")); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 472 | } |
| 473 | else |
| 474 | { |
| 475 | trans = new TServerSocket(port, 0, useBufferedSockets); |
| 476 | } |
| 477 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 478 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 479 | TProtocolFactory proto; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 480 | if (compact) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 481 | proto = new TCompactProtocol.Factory(); |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 482 | else if (json) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 483 | proto = new TJSONProtocol.Factory(); |
| 484 | else |
| 485 | proto = new TBinaryProtocol.Factory(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 486 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 487 | TProcessorFactory processorFactory; |
| 488 | if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory) |
| 489 | { |
| 490 | processorFactory = new TPrototypeProcessorFactory<ThriftTest.Processor, TestHandler>(); |
| 491 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 492 | else |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 493 | { |
| 494 | // Processor |
| 495 | TestHandler testHandler = new TestHandler(); |
| 496 | ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler); |
| 497 | processorFactory = new TSingletonProcessorFactory(testProcessor); |
| 498 | } |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 499 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 500 | TTransportFactory transFactory; |
| 501 | if (useFramed) |
| 502 | transFactory = new TFramedTransport.Factory(); |
| 503 | else |
| 504 | transFactory = new TTransportFactory(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 505 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 506 | TServer serverEngine; |
| 507 | switch (serverType) |
| 508 | { |
| 509 | case ServerType.TThreadPoolServer: |
| 510 | serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto); |
| 511 | break; |
| 512 | case ServerType.TThreadedServer: |
| 513 | serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto); |
| 514 | break; |
| 515 | default: |
| 516 | serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto); |
| 517 | break; |
| 518 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 519 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 520 | //Server event handler |
| 521 | TradeServerEventHandler serverEvents = new TradeServerEventHandler(); |
| 522 | serverEngine.setEventHandler(serverEvents); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 523 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 524 | // Run it |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame^] | 525 | string where = (pipe != null ? "on pipe " + pipe : "on port " + port); |
| 526 | Console.WriteLine("Starting the " + serverType.ToString() + " " + where + |
| 527 | (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") + |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 528 | (useBufferedSockets ? " with buffered socket" : "") + |
| 529 | (useFramed ? " with framed transport" : "") + |
| 530 | (useEncryption ? " with encryption" : "") + |
| 531 | (compact ? " with compact protocol" : "") + |
| 532 | (json ? " with json protocol" : "") + |
| 533 | "..."); |
| 534 | serverEngine.Serve(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 535 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 536 | } |
| 537 | catch (Exception x) |
| 538 | { |
| 539 | Console.Error.Write(x); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 540 | return false; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 541 | } |
| 542 | Console.WriteLine("done."); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 543 | return true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 544 | } |
| 545 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 546 | } |