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