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 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 276 | public Dictionary<long, Dictionary<Numberz, Insanity>> testInsanity(Insanity argument) |
| 277 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 278 | testLogDelegate.Invoke("testInsanity()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 279 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 280 | Xtruct hello = new Xtruct(); |
| 281 | hello.String_thing = "Hello2"; |
| 282 | hello.Byte_thing = 2; |
| 283 | hello.I32_thing = 2; |
| 284 | hello.I64_thing = 2; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 285 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 286 | Xtruct goodbye = new Xtruct(); |
| 287 | goodbye.String_thing = "Goodbye4"; |
| 288 | goodbye.Byte_thing = (sbyte)4; |
| 289 | goodbye.I32_thing = 4; |
| 290 | goodbye.I64_thing = (long)4; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 291 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 292 | Insanity crazy = new Insanity(); |
| 293 | crazy.UserMap = new Dictionary<Numberz, long>(); |
| 294 | crazy.UserMap[Numberz.EIGHT] = (long)8; |
| 295 | crazy.Xtructs = new List<Xtruct>(); |
| 296 | crazy.Xtructs.Add(goodbye); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 297 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 298 | Insanity looney = new Insanity(); |
| 299 | crazy.UserMap[Numberz.FIVE] = (long)5; |
| 300 | crazy.Xtructs.Add(hello); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 301 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 302 | Dictionary<Numberz, Insanity> first_map = new Dictionary<Numberz, Insanity>(); |
| 303 | Dictionary<Numberz, Insanity> second_map = new Dictionary<Numberz, Insanity>(); ; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 304 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 305 | first_map[Numberz.TWO] = crazy; |
| 306 | first_map[Numberz.THREE] = crazy; |
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 | second_map[Numberz.SIX] = looney; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 309 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 310 | Dictionary<long, Dictionary<Numberz, Insanity>> insane = |
| 311 | new Dictionary<long, Dictionary<Numberz, Insanity>>(); |
| 312 | insane[(long)1] = first_map; |
| 313 | insane[(long)2] = second_map; |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 314 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 315 | return insane; |
| 316 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 317 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 318 | public Xtruct testMulti(sbyte arg0, int arg1, long arg2, Dictionary<short, string> arg3, Numberz arg4, long arg5) |
| 319 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 320 | testLogDelegate.Invoke("testMulti()"); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 321 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 322 | Xtruct hello = new Xtruct(); ; |
| 323 | hello.String_thing = "Hello2"; |
| 324 | hello.Byte_thing = arg0; |
| 325 | hello.I32_thing = arg1; |
| 326 | hello.I64_thing = arg2; |
| 327 | return hello; |
| 328 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 329 | |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 330 | /** |
| 331 | * Print 'testException(%s)' with arg as '%s' |
| 332 | * @param string arg - a string indication what type of exception to throw |
| 333 | * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg |
| 334 | * elsen if arg == "TException" throw TException |
| 335 | * else do not throw anything |
| 336 | */ |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 337 | public void testException(string arg) |
| 338 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 339 | testLogDelegate.Invoke("testException({0})", arg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 340 | if (arg == "Xception") |
| 341 | { |
| 342 | Xception x = new Xception(); |
| 343 | x.ErrorCode = 1001; |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 344 | x.Message = arg; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 345 | throw x; |
| 346 | } |
Jens Geyer | 8b14d17 | 2015-02-26 19:36:28 +0100 | [diff] [blame] | 347 | if (arg == "TException") |
| 348 | { |
| 349 | throw new Thrift.TException(); |
| 350 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 351 | return; |
| 352 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 353 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 354 | public Xtruct testMultiException(string arg0, string arg1) |
| 355 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 356 | testLogDelegate.Invoke("testMultiException({0}, {1})", arg0,arg1); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 357 | if (arg0 == "Xception") |
| 358 | { |
| 359 | Xception x = new Xception(); |
| 360 | x.ErrorCode = 1001; |
| 361 | x.Message = "This is an Xception"; |
| 362 | throw x; |
| 363 | } |
| 364 | else if (arg0 == "Xception2") |
| 365 | { |
| 366 | Xception2 x = new Xception2(); |
| 367 | x.ErrorCode = 2002; |
| 368 | x.Struct_thing = new Xtruct(); |
| 369 | x.Struct_thing.String_thing = "This is an Xception2"; |
| 370 | throw x; |
| 371 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 372 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 373 | Xtruct result = new Xtruct(); |
| 374 | result.String_thing = arg1; |
| 375 | return result; |
| 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 | public void testStop() |
| 379 | { |
| 380 | if (server != null) |
| 381 | { |
| 382 | server.Stop(); |
| 383 | } |
| 384 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 385 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 386 | public void testOneway(int arg) |
| 387 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 388 | testLogDelegate.Invoke("testOneway({0}), sleeping...", arg); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 389 | System.Threading.Thread.Sleep(arg * 1000); |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 390 | testLogDelegate.Invoke("testOneway finished"); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 391 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 392 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 393 | } // class TestHandler |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 394 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 395 | private enum ServerType |
| 396 | { |
| 397 | TSimpleServer, |
| 398 | TThreadedServer, |
| 399 | TThreadPoolServer, |
| 400 | } |
| 401 | |
| 402 | private enum ProcessorFactoryType |
| 403 | { |
| 404 | TSingletonProcessorFactory, |
| 405 | TPrototypeProcessorFactory, |
| 406 | } |
| 407 | |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 408 | public static bool Execute(string[] args) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 409 | { |
| 410 | try |
| 411 | { |
| 412 | bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 413 | ServerType serverType = ServerType.TSimpleServer; |
| 414 | ProcessorFactoryType processorFactoryType = ProcessorFactoryType.TSingletonProcessorFactory; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 415 | int port = 9090; |
| 416 | string pipe = null; |
| 417 | for (int i = 0; i < args.Length; i++) |
| 418 | { |
| 419 | if (args[i] == "-pipe") // -pipe name |
| 420 | { |
| 421 | pipe = args[++i]; |
| 422 | } |
| 423 | else if (args[i].Contains("--port=")) |
| 424 | { |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 425 | port = int.Parse(args[i].Substring(args[i].IndexOf("=") + 1)); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 426 | } |
| 427 | else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered") |
| 428 | { |
| 429 | useBufferedSockets = true; |
| 430 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 431 | else if (args[i] == "-f" || args[i] == "--framed" || args[i] == "--transport=framed") |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 432 | { |
| 433 | useFramed = true; |
| 434 | } |
| 435 | else if (args[i] == "--compact" || args[i] == "--protocol=compact") |
| 436 | { |
| 437 | compact = true; |
| 438 | } |
| 439 | else if (args[i] == "--json" || args[i] == "--protocol=json") |
| 440 | { |
| 441 | json = true; |
| 442 | } |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 443 | else if (args[i] == "--threaded" || args[i] == "--server-type=threaded") |
| 444 | { |
| 445 | serverType = ServerType.TThreadedServer; |
| 446 | } |
| 447 | else if (args[i] == "--threadpool" || args[i] == "--server-type=threadpool") |
| 448 | { |
| 449 | serverType = ServerType.TThreadPoolServer; |
| 450 | } |
| 451 | else if (args[i] == "--prototype" || args[i] == "--processor=prototype") |
| 452 | { |
| 453 | processorFactoryType = ProcessorFactoryType.TPrototypeProcessorFactory; |
| 454 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 455 | else if (args[i] == "--ssl") |
| 456 | { |
| 457 | useEncryption = true; |
| 458 | } |
| 459 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 460 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 461 | // Transport |
| 462 | TServerTransport trans; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 463 | if (pipe != null) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 464 | { |
| 465 | trans = new TNamedPipeServerTransport(pipe); |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | if (useEncryption) |
| 470 | { |
Jens Geyer | 178b813 | 2015-09-30 23:16:45 +0200 | [diff] [blame] | 471 | string certPath = "../../../../test/keys/server.p12"; |
Nobuaki Sukegawa | 474ddbd | 2016-02-17 23:44:27 +0900 | [diff] [blame^] | 472 | 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] | 473 | } |
| 474 | else |
| 475 | { |
| 476 | trans = new TServerSocket(port, 0, useBufferedSockets); |
| 477 | } |
| 478 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 479 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 480 | TProtocolFactory proto; |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 481 | if (compact) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 482 | proto = new TCompactProtocol.Factory(); |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 483 | else if (json) |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 484 | proto = new TJSONProtocol.Factory(); |
| 485 | else |
| 486 | proto = new TBinaryProtocol.Factory(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 487 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 488 | TProcessorFactory processorFactory; |
| 489 | if (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory) |
| 490 | { |
| 491 | processorFactory = new TPrototypeProcessorFactory<ThriftTest.Processor, TestHandler>(); |
| 492 | } |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 493 | else |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 494 | { |
| 495 | // Processor |
| 496 | TestHandler testHandler = new TestHandler(); |
| 497 | ThriftTest.Processor testProcessor = new ThriftTest.Processor(testHandler); |
| 498 | processorFactory = new TSingletonProcessorFactory(testProcessor); |
| 499 | } |
David Reiss | d831a21 | 2009-02-13 03:09:52 +0000 | [diff] [blame] | 500 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 501 | TTransportFactory transFactory; |
| 502 | if (useFramed) |
| 503 | transFactory = new TFramedTransport.Factory(); |
| 504 | else |
| 505 | transFactory = new TTransportFactory(); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 506 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 507 | TServer serverEngine; |
| 508 | switch (serverType) |
| 509 | { |
| 510 | case ServerType.TThreadPoolServer: |
| 511 | serverEngine = new TThreadPoolServer(processorFactory, trans, transFactory, proto); |
| 512 | break; |
| 513 | case ServerType.TThreadedServer: |
| 514 | serverEngine = new TThreadedServer(processorFactory, trans, transFactory, proto); |
| 515 | break; |
| 516 | default: |
| 517 | serverEngine = new TSimpleServer(processorFactory, trans, transFactory, proto); |
| 518 | break; |
| 519 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 520 | |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 521 | //Server event handler |
| 522 | TradeServerEventHandler serverEvents = new TradeServerEventHandler(); |
| 523 | serverEngine.setEventHandler(serverEvents); |
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 | // Run it |
Jonathan Heard | 2bfd7df | 2015-10-28 17:34:27 +0000 | [diff] [blame] | 526 | string where = (pipe != null ? "on pipe " + pipe : "on port " + port); |
| 527 | Console.WriteLine("Starting the " + serverType.ToString() + " " + where + |
| 528 | (processorFactoryType == ProcessorFactoryType.TPrototypeProcessorFactory ? " with processor prototype factory " : "") + |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 529 | (useBufferedSockets ? " with buffered socket" : "") + |
| 530 | (useFramed ? " with framed transport" : "") + |
| 531 | (useEncryption ? " with encryption" : "") + |
| 532 | (compact ? " with compact protocol" : "") + |
| 533 | (json ? " with json protocol" : "") + |
| 534 | "..."); |
| 535 | serverEngine.Serve(); |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 536 | |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 537 | } |
| 538 | catch (Exception x) |
| 539 | { |
| 540 | Console.Error.Write(x); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 541 | return false; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 542 | } |
| 543 | Console.WriteLine("done."); |
Roger Meier | 41ad434 | 2015-03-24 22:30:40 +0100 | [diff] [blame] | 544 | return true; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 545 | } |
| 546 | } |
David Reiss | 6319133 | 2009-01-06 19:49:22 +0000 | [diff] [blame] | 547 | } |