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