Jake Farrell | 2727422 | 2011-11-10 20:32:44 +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 | |
| 20 | unit TestServer; |
| 21 | |
Jens Geyer | 9f7f11e | 2016-04-14 21:37:11 +0200 | [diff] [blame] | 22 | {$I ../src/Thrift.Defines.inc} |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 23 | {$WARN SYMBOL_PLATFORM OFF} |
| 24 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 25 | {.$DEFINE RunEndless} // activate to interactively stress-test the server stop routines via Ctrl+C |
| 26 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 27 | interface |
| 28 | |
| 29 | uses |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 30 | Windows, SysUtils, |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 31 | Generics.Collections, |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 32 | Thrift.Server, |
| 33 | Thrift.Transport, |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 34 | Thrift.Transport.Pipes, |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 35 | Thrift.Protocol, |
| 36 | Thrift.Protocol.JSON, |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 37 | Thrift.Protocol.Compact, |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 38 | Thrift.Collections, |
| 39 | Thrift.Utils, |
| 40 | Thrift.Test, |
| 41 | Thrift, |
| 42 | TestConstants, |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 43 | TestServerEvents, |
Jens Geyer | 3d55624 | 2018-01-24 19:14:32 +0100 | [diff] [blame] | 44 | ConsoleHelper, |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 45 | Contnrs; |
| 46 | |
| 47 | type |
| 48 | TTestServer = class |
| 49 | public |
| 50 | type |
| 51 | |
| 52 | ITestHandler = interface( TThriftTest.Iface ) |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 53 | procedure SetServer( const AServer : IServer ); |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 54 | procedure TestStop; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 55 | end; |
| 56 | |
| 57 | TTestHandlerImpl = class( TInterfacedObject, ITestHandler ) |
| 58 | private |
| 59 | FServer : IServer; |
| 60 | protected |
| 61 | procedure testVoid(); |
Jens Geyer | 39ba6b7 | 2015-09-22 00:00:49 +0200 | [diff] [blame] | 62 | function testBool(thing: Boolean): Boolean; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 63 | function testString(const thing: string): string; |
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 64 | function testByte(thing: ShortInt): ShortInt; |
| 65 | function testI32(thing: Integer): Integer; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 66 | function testI64(const thing: Int64): Int64; |
| 67 | function testDouble(const thing: Double): Double; |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 68 | function testBinary(const thing: TBytes): TBytes; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 69 | function testStruct(const thing: IXtruct): IXtruct; |
| 70 | function testNest(const thing: IXtruct2): IXtruct2; |
| 71 | function testMap(const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>; |
| 72 | function testStringMap(const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>; |
| 73 | function testSet(const thing: IHashSet<Integer>): IHashSet<Integer>; |
| 74 | function testList(const thing: IThriftList<Integer>): IThriftList<Integer>; |
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 75 | function testEnum(thing: TNumberz): TNumberz; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 76 | function testTypedef(const thing: Int64): Int64; |
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 77 | function testMapMap(hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 78 | function testInsanity(const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; |
| 79 | function testMulti(arg0: ShortInt; arg1: Integer; const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>; arg4: TNumberz; const arg5: Int64): IXtruct; |
| 80 | procedure testException(const arg: string); |
| 81 | function testMultiException(const arg0: string; const arg1: string): IXtruct; |
Jake Farrell | 7ae13e1 | 2011-10-18 14:35:26 +0000 | [diff] [blame] | 82 | procedure testOneway(secondsToSleep: Integer); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 83 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 84 | procedure TestStop; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 85 | procedure SetServer( const AServer : IServer ); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 86 | end; |
| 87 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 88 | class procedure PrintCmdLineHelp; |
| 89 | class procedure InvalidArgs; |
| 90 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 91 | class procedure LaunchAnonPipeChild( const app : string; const transport : IAnonymousPipeServerTransport); |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 92 | class procedure Execute( const args: array of string); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 93 | end; |
| 94 | |
| 95 | implementation |
| 96 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 97 | |
| 98 | var g_Handler : TTestServer.ITestHandler = nil; |
| 99 | |
| 100 | |
| 101 | function MyConsoleEventHandler( dwCtrlType : DWORD) : BOOL; stdcall; |
| 102 | // Note that this Handler procedure is called from another thread |
| 103 | var handler : TTestServer.ITestHandler; |
| 104 | begin |
| 105 | result := TRUE; |
| 106 | try |
| 107 | case dwCtrlType of |
| 108 | CTRL_C_EVENT : Console.WriteLine( 'Ctrl+C pressed'); |
| 109 | CTRL_BREAK_EVENT : Console.WriteLine( 'Ctrl+Break pressed'); |
| 110 | CTRL_CLOSE_EVENT : Console.WriteLine( 'Received CloseTask signal'); |
| 111 | CTRL_LOGOFF_EVENT : Console.WriteLine( 'Received LogOff signal'); |
| 112 | CTRL_SHUTDOWN_EVENT : Console.WriteLine( 'Received Shutdown signal'); |
| 113 | else |
| 114 | Console.WriteLine( 'Received console event #'+IntToStr(Integer(dwCtrlType))); |
| 115 | end; |
| 116 | |
| 117 | handler := g_Handler; |
| 118 | if handler <> nil then handler.TestStop; |
| 119 | |
| 120 | except |
| 121 | // catch all |
| 122 | end; |
| 123 | end; |
| 124 | |
| 125 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 126 | { TTestServer.TTestHandlerImpl } |
| 127 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 128 | procedure TTestServer.TTestHandlerImpl.SetServer( const AServer: IServer); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 129 | begin |
| 130 | FServer := AServer; |
| 131 | end; |
| 132 | |
| 133 | function TTestServer.TTestHandlerImpl.testByte(thing: ShortInt): ShortInt; |
| 134 | begin |
| 135 | Console.WriteLine('testByte("' + IntToStr( thing) + '")'); |
| 136 | Result := thing; |
| 137 | end; |
| 138 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 139 | function TTestServer.TTestHandlerImpl.testDouble( const thing: Double): Double; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 140 | begin |
| 141 | Console.WriteLine('testDouble("' + FloatToStr( thing ) + '")'); |
| 142 | Result := thing; |
| 143 | end; |
| 144 | |
Jens Geyer | fd1b358 | 2014-12-13 23:42:58 +0100 | [diff] [blame] | 145 | function TTestServer.TTestHandlerImpl.testBinary(const thing: TBytes): TBytes; |
| 146 | begin |
| 147 | Console.WriteLine('testBinary("' + BytesToHex( thing ) + '")'); |
| 148 | Result := thing; |
| 149 | end; |
| 150 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 151 | function TTestServer.TTestHandlerImpl.testEnum(thing: TNumberz): TNumberz; |
| 152 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 153 | Console.WriteLine('testEnum(' + EnumUtils<TNumberz>.ToString(Ord(thing)) + ')'); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 154 | Result := thing; |
| 155 | end; |
| 156 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 157 | procedure TTestServer.TTestHandlerImpl.testException(const arg: string); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 158 | begin |
| 159 | Console.WriteLine('testException(' + arg + ')'); |
| 160 | if ( arg = 'Xception') then |
| 161 | begin |
Roger Meier | bb6de7a | 2012-05-04 23:35:45 +0000 | [diff] [blame] | 162 | raise TXception.Create( 1001, arg); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 163 | end; |
Roger Meier | bb6de7a | 2012-05-04 23:35:45 +0000 | [diff] [blame] | 164 | |
| 165 | if (arg = 'TException') then |
| 166 | begin |
Jens Geyer | 92d8062 | 2018-05-02 22:28:44 +0200 | [diff] [blame] | 167 | raise TException.Create('TException'); |
Roger Meier | bb6de7a | 2012-05-04 23:35:45 +0000 | [diff] [blame] | 168 | end; |
| 169 | |
| 170 | // else do not throw anything |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 171 | end; |
| 172 | |
| 173 | function TTestServer.TTestHandlerImpl.testI32(thing: Integer): Integer; |
| 174 | begin |
| 175 | Console.WriteLine('testI32("' + IntToStr( thing) + '")'); |
| 176 | Result := thing; |
| 177 | end; |
| 178 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 179 | function TTestServer.TTestHandlerImpl.testI64( const thing: Int64): Int64; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 180 | begin |
| 181 | Console.WriteLine('testI64("' + IntToStr( thing) + '")'); |
| 182 | Result := thing; |
| 183 | end; |
| 184 | |
| 185 | function TTestServer.TTestHandlerImpl.testInsanity( |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 186 | const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 187 | var |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 188 | looney : IInsanity; |
| 189 | first_map : IThriftDictionary<TNumberz, IInsanity>; |
| 190 | second_map : IThriftDictionary<TNumberz, IInsanity>; |
| 191 | insane : IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>; |
| 192 | |
| 193 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 194 | Console.Write('testInsanity('); |
| 195 | if argument <> nil then Console.Write(argument.ToString); |
| 196 | Console.WriteLine(')'); |
| 197 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 198 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 199 | (** |
| 200 | * So you think you've got this all worked, out eh? |
| 201 | * |
| 202 | * Creates a the returned map with these values and prints it out: |
| 203 | * { 1 => { 2 => argument, |
| 204 | * 3 => argument, |
| 205 | * }, |
| 206 | * 2 => { 6 => <empty Insanity struct>, }, |
| 207 | * } |
| 208 | * @return map<UserId, map<Numberz,Insanity>> - a map with the above values |
| 209 | *) |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 210 | |
| 211 | first_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create; |
| 212 | second_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create; |
| 213 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 214 | first_map.AddOrSetValue( TNumberz.TWO, argument); |
| 215 | first_map.AddOrSetValue( TNumberz.THREE, argument); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 216 | |
Jens Geyer | 540e346 | 2016-12-28 14:25:41 +0100 | [diff] [blame] | 217 | looney := TInsanityImpl.Create; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 218 | second_map.AddOrSetValue( TNumberz.SIX, looney); |
| 219 | |
| 220 | insane := TThriftDictionaryImpl<Int64, IThriftDictionary<TNumberz, IInsanity>>.Create; |
| 221 | |
| 222 | insane.AddOrSetValue( 1, first_map); |
| 223 | insane.AddOrSetValue( 2, second_map); |
| 224 | |
| 225 | Result := insane; |
| 226 | end; |
| 227 | |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 228 | function TTestServer.TTestHandlerImpl.testList( const thing: IThriftList<Integer>): IThriftList<Integer>; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 229 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 230 | Console.Write('testList('); |
| 231 | if thing <> nil then Console.Write(thing.ToString); |
| 232 | Console.WriteLine(')'); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 233 | Result := thing; |
| 234 | end; |
| 235 | |
| 236 | function TTestServer.TTestHandlerImpl.testMap( |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 237 | const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 238 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 239 | Console.Write('testMap('); |
| 240 | if thing <> nil then Console.Write(thing.ToString); |
| 241 | Console.WriteLine(')'); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 242 | Result := thing; |
| 243 | end; |
| 244 | |
| 245 | function TTestServer.TTestHandlerImpl.TestMapMap( |
| 246 | hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>; |
| 247 | var |
| 248 | mapmap : IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>; |
| 249 | pos : IThriftDictionary<Integer, Integer>; |
| 250 | neg : IThriftDictionary<Integer, Integer>; |
| 251 | i : Integer; |
| 252 | begin |
| 253 | Console.WriteLine('testMapMap(' + IntToStr( hello) + ')'); |
| 254 | mapmap := TThriftDictionaryImpl<Integer, IThriftDictionary<Integer, Integer>>.Create; |
| 255 | pos := TThriftDictionaryImpl<Integer, Integer>.Create; |
| 256 | neg := TThriftDictionaryImpl<Integer, Integer>.Create; |
| 257 | |
| 258 | for i := 1 to 4 do |
| 259 | begin |
| 260 | pos.AddOrSetValue( i, i); |
| 261 | neg.AddOrSetValue( -i, -i); |
| 262 | end; |
| 263 | |
| 264 | mapmap.AddOrSetValue(4, pos); |
| 265 | mapmap.AddOrSetValue( -4, neg); |
| 266 | |
| 267 | Result := mapmap; |
| 268 | end; |
| 269 | |
| 270 | function TTestServer.TTestHandlerImpl.testMulti(arg0: ShortInt; arg1: Integer; |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 271 | const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>; |
| 272 | arg4: TNumberz; const arg5: Int64): IXtruct; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 273 | var |
| 274 | hello : IXtruct; |
| 275 | begin |
| 276 | Console.WriteLine('testMulti()'); |
| 277 | hello := TXtructImpl.Create; |
| 278 | hello.String_thing := 'Hello2'; |
| 279 | hello.Byte_thing := arg0; |
| 280 | hello.I32_thing := arg1; |
| 281 | hello.I64_thing := arg2; |
| 282 | Result := hello; |
| 283 | end; |
| 284 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 285 | function TTestServer.TTestHandlerImpl.testMultiException( const arg0, arg1: string): IXtruct; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 286 | var |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 287 | x2 : TXception2; |
| 288 | begin |
| 289 | Console.WriteLine('testMultiException(' + arg0 + ', ' + arg1 + ')'); |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 290 | if ( arg0 = 'Xception') then begin |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 291 | raise TXception.Create( 1001, 'This is an Xception'); // test the new rich CTOR |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 292 | end; |
| 293 | |
| 294 | if ( arg0 = 'Xception2') then begin |
Jake Farrell | 343c61d | 2011-12-09 02:29:56 +0000 | [diff] [blame] | 295 | x2 := TXception2.Create; // the old way still works too? |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 296 | x2.ErrorCode := 2002; |
| 297 | x2.Struct_thing := TXtructImpl.Create; |
| 298 | x2.Struct_thing.String_thing := 'This is an Xception2'; |
Jake Farrell | ac10256 | 2011-11-23 14:30:41 +0000 | [diff] [blame] | 299 | x2.UpdateMessageProperty; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 300 | raise x2; |
| 301 | end; |
| 302 | |
| 303 | Result := TXtructImpl.Create; |
| 304 | Result.String_thing := arg1; |
| 305 | end; |
| 306 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 307 | function TTestServer.TTestHandlerImpl.testNest( const thing: IXtruct2): IXtruct2; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 308 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 309 | Console.Write('testNest('); |
| 310 | if thing <> nil then Console.Write(thing.ToString); |
| 311 | Console.WriteLine(')'); |
| 312 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 313 | Result := thing; |
| 314 | end; |
| 315 | |
| 316 | procedure TTestServer.TTestHandlerImpl.testOneway(secondsToSleep: Integer); |
| 317 | begin |
| 318 | Console.WriteLine('testOneway(' + IntToStr( secondsToSleep )+ '), sleeping...'); |
| 319 | Sleep(secondsToSleep * 1000); |
| 320 | Console.WriteLine('testOneway finished'); |
| 321 | end; |
| 322 | |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 323 | function TTestServer.TTestHandlerImpl.testSet( const thing: IHashSet<Integer>):IHashSet<Integer>; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 324 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 325 | Console.Write('testSet('); |
| 326 | if thing <> nil then Console.Write(thing.ToString); |
| 327 | Console.WriteLine(')');; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 328 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 329 | Result := thing; |
| 330 | end; |
| 331 | |
| 332 | procedure TTestServer.TTestHandlerImpl.testStop; |
| 333 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 334 | if FServer <> nil then begin |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 335 | FServer.Stop; |
| 336 | end; |
| 337 | end; |
| 338 | |
Jens Geyer | 39ba6b7 | 2015-09-22 00:00:49 +0200 | [diff] [blame] | 339 | function TTestServer.TTestHandlerImpl.testBool(thing: Boolean): Boolean; |
| 340 | begin |
| 341 | Console.WriteLine('testBool(' + BoolToStr(thing,true) + ')'); |
| 342 | Result := thing; |
| 343 | end; |
| 344 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 345 | function TTestServer.TTestHandlerImpl.testString( const thing: string): string; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 346 | begin |
| 347 | Console.WriteLine('teststring("' + thing + '")'); |
| 348 | Result := thing; |
| 349 | end; |
| 350 | |
| 351 | function TTestServer.TTestHandlerImpl.testStringMap( |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 352 | const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 353 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 354 | Console.Write('testStringMap('); |
| 355 | if thing <> nil then Console.Write(thing.ToString); |
| 356 | Console.WriteLine(')'); |
| 357 | |
Roger Meier | bb6de7a | 2012-05-04 23:35:45 +0000 | [diff] [blame] | 358 | Result := thing; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 359 | end; |
| 360 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 361 | function TTestServer.TTestHandlerImpl.testTypedef( const thing: Int64): Int64; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 362 | begin |
| 363 | Console.WriteLine('testTypedef(' + IntToStr( thing) + ')'); |
| 364 | Result := thing; |
| 365 | end; |
| 366 | |
| 367 | procedure TTestServer.TTestHandlerImpl.TestVoid; |
| 368 | begin |
| 369 | Console.WriteLine('testVoid()'); |
| 370 | end; |
| 371 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 372 | function TTestServer.TTestHandlerImpl.testStruct( const thing: IXtruct): IXtruct; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 373 | begin |
Jens Geyer | 8f7487e | 2019-05-09 22:21:32 +0200 | [diff] [blame^] | 374 | Console.Write('testStruct('); |
| 375 | if thing <> nil then Console.Write(thing.ToString); |
| 376 | Console.WriteLine(')'); |
| 377 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 378 | Result := thing; |
| 379 | end; |
| 380 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 381 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 382 | { TTestServer } |
| 383 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 384 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 385 | class procedure TTestServer.PrintCmdLineHelp; |
| 386 | const HELPTEXT = ' [options]'#10 |
| 387 | + #10 |
| 388 | + 'Allowed options:'#10 |
| 389 | + ' -h [ --help ] produce help message'#10 |
| 390 | + ' --port arg (=9090) Port number to listen'#10 |
| 391 | + ' --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift)'#10 |
| 392 | + ' --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe)'#10 |
| 393 | + ' --server-type arg (=simple) type of server, "simple", "thread-pool",'#10 |
| 394 | + ' "threaded", or "nonblocking"'#10 |
| 395 | + ' --transport arg (=socket) transport: buffered, framed, http, anonpipe'#10 |
| 396 | + ' --protocol arg (=binary) protocol: binary, compact, json'#10 |
| 397 | + ' --ssl Encrypted Transport using SSL'#10 |
| 398 | + ' --processor-events processor-events'#10 |
| 399 | + ' -n [ --workers ] arg (=4) Number of thread pools workers. Only valid for'#10 |
| 400 | + ' thread-pool server type'#10 |
| 401 | ; |
| 402 | begin |
| 403 | Console.WriteLine( ChangeFileExt(ExtractFileName(ParamStr(0)),'') + HELPTEXT); |
| 404 | end; |
| 405 | |
| 406 | class procedure TTestServer.InvalidArgs; |
| 407 | begin |
| 408 | Console.WriteLine( 'Invalid args.'); |
| 409 | Console.WriteLine( ChangeFileExt(ExtractFileName(ParamStr(0)),'') + ' -h for more information'); |
| 410 | Abort; |
| 411 | end; |
| 412 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 413 | class procedure TTestServer.LaunchAnonPipeChild( const app : string; const transport : IAnonymousPipeServerTransport); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 414 | //Launch child process and pass R/W anonymous pipe handles on cmd line. |
| 415 | //This is a simple example and does not include elevation or other |
| 416 | //advanced features. |
| 417 | var pi : PROCESS_INFORMATION; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 418 | si : STARTUPINFO; |
| 419 | sArg, sHandles, sCmdLine : string; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 420 | i : Integer; |
| 421 | begin |
| 422 | GetStartupInfo( si); //set startupinfo for the spawned process |
| 423 | |
| 424 | // preformat handles args |
| 425 | sHandles := Format( '%d %d', |
| 426 | [ Integer(transport.ClientAnonRead), |
| 427 | Integer(transport.ClientAnonWrite)]); |
| 428 | |
| 429 | // pass all settings to client |
| 430 | sCmdLine := app; |
| 431 | for i := 1 to ParamCount do begin |
| 432 | sArg := ParamStr(i); |
| 433 | |
| 434 | // add anonymous handles and quote strings where appropriate |
| 435 | if sArg = '-anon' |
| 436 | then sArg := sArg +' '+ sHandles |
| 437 | else begin |
| 438 | if Pos(' ',sArg) > 0 |
| 439 | then sArg := '"'+sArg+'"'; |
| 440 | end;; |
| 441 | |
| 442 | sCmdLine := sCmdLine +' '+ sArg; |
| 443 | end; |
| 444 | |
| 445 | // spawn the child process |
| 446 | Console.WriteLine('Starting client '+sCmdLine); |
| 447 | Win32Check( CreateProcess( nil, PChar(sCmdLine), nil,nil,TRUE,0,nil,nil,si,pi)); |
| 448 | |
| 449 | CloseHandle( pi.hThread); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 450 | CloseHandle( pi.hProcess); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 451 | end; |
| 452 | |
| 453 | |
Roger Meier | 333bbf3 | 2012-01-08 21:51:08 +0000 | [diff] [blame] | 454 | class procedure TTestServer.Execute( const args: array of string); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 455 | var |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 456 | Port : Integer; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 457 | ServerEvents : Boolean; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 458 | sPipeName : string; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 459 | testHandler : ITestHandler; |
| 460 | testProcessor : IProcessor; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 461 | ServerTrans : IServerTransport; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 462 | ServerEngine : IServer; |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 463 | anonymouspipe : IAnonymousPipeServerTransport; |
| 464 | namedpipe : INamedPipeServerTransport; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 465 | TransportFactory : ITransportFactory; |
| 466 | ProtocolFactory : IProtocolFactory; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 467 | i, numWorker : Integer; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 468 | s : string; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 469 | protType : TKnownProtocol; |
| 470 | servertype : TServerType; |
| 471 | endpoint : TEndpointTransport; |
| 472 | layered : TLayeredTransports; |
| 473 | UseSSL : Boolean; // include where appropriate (TLayeredTransport?) |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 474 | begin |
| 475 | try |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 476 | ServerEvents := FALSE; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 477 | protType := prot_Binary; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 478 | servertype := srv_Simple; |
| 479 | endpoint := trns_Sockets; |
| 480 | layered := []; |
| 481 | UseSSL := FALSE; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 482 | Port := 9090; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 483 | sPipeName := ''; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 484 | numWorker := 4; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 485 | |
| 486 | i := 0; |
| 487 | while ( i < Length(args) ) do begin |
| 488 | s := args[i]; |
| 489 | Inc(i); |
| 490 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 491 | // Allowed options: |
| 492 | if (s = '-h') or (s = '--help') then begin |
| 493 | // -h [ --help ] produce help message |
| 494 | PrintCmdLineHelp; |
| 495 | Exit; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 496 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 497 | else if (s = '--port') then begin |
| 498 | // --port arg (=9090) Port number to listen |
| 499 | s := args[i]; |
| 500 | Inc(i); |
| 501 | Port := StrToIntDef( s, Port); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 502 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 503 | else if (s = '--domain-socket') then begin |
| 504 | // --domain-socket arg Unix Domain Socket (e.g. /tmp/ThriftTest.thrift) |
| 505 | raise Exception.Create('domain-socket not supported'); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 506 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 507 | else if (s = '--named-pipe') then begin |
| 508 | // --named-pipe arg Windows Named Pipe (e.g. MyThriftPipe) |
| 509 | endpoint := trns_NamedPipes; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 510 | sPipeName := args[i]; // -pipe <name> |
| 511 | Inc( i ); |
| 512 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 513 | else if (s = '--server-type') then begin |
| 514 | // --server-type arg (=simple) type of server, |
| 515 | // arg = "simple", "thread-pool", "threaded", or "nonblocking" |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 516 | s := args[i]; |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 517 | Inc(i); |
| 518 | |
| 519 | if s = 'simple' then servertype := srv_Simple |
| 520 | else if s = 'thread-pool' then servertype := srv_Threadpool |
| 521 | else if s = 'threaded' then servertype := srv_Threaded |
| 522 | else if s = 'nonblocking' then servertype := srv_Nonblocking |
| 523 | else InvalidArgs; |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 524 | end |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 525 | else if (s = '--transport') then begin |
| 526 | // --transport arg (=buffered) transport: buffered, framed, http |
| 527 | s := args[i]; |
| 528 | Inc(i); |
| 529 | |
| 530 | if s = 'buffered' then Include( layered, trns_Buffered) |
| 531 | else if s = 'framed' then Include( layered, trns_Framed) |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 532 | else if s = 'http' then endpoint := trns_MsxmlHttp |
| 533 | else if s = 'winhttp' then endpoint := trns_WinHttp |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 534 | else if s = 'anonpipe' then endpoint := trns_AnonPipes |
| 535 | else InvalidArgs; |
| 536 | end |
| 537 | else if (s = '--protocol') then begin |
| 538 | // --protocol arg (=binary) protocol: binary, compact, json |
| 539 | s := args[i]; |
| 540 | Inc(i); |
| 541 | |
| 542 | if s = 'binary' then protType := prot_Binary |
| 543 | else if s = 'compact' then protType := prot_Compact |
| 544 | else if s = 'json' then protType := prot_JSON |
| 545 | else InvalidArgs; |
| 546 | end |
| 547 | else if (s = '--ssl') then begin |
| 548 | // --ssl Encrypted Transport using SSL |
| 549 | UseSSL := TRUE; |
| 550 | end |
| 551 | else if (s = '--processor-events') then begin |
| 552 | // --processor-events processor-events |
| 553 | ServerEvents := TRUE; |
| 554 | end |
| 555 | else if (s = '-n') or (s = '--workers') then begin |
| 556 | // -n [ --workers ] arg (=4) Number of thread pools workers. |
| 557 | // Only valid for thread-pool server type |
| 558 | s := args[i]; |
| 559 | numWorker := StrToIntDef(s,0); |
| 560 | if numWorker > 0 |
| 561 | then Inc(i) |
| 562 | else numWorker := 4; |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 563 | end |
| 564 | else begin |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 565 | InvalidArgs; |
| 566 | end; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 567 | end; |
| 568 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 569 | |
| 570 | Console.WriteLine('Server configuration: '); |
| 571 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 572 | // create protocol factory, default to BinaryProtocol |
| 573 | case protType of |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 574 | prot_Binary : ProtocolFactory := TBinaryProtocolImpl.TFactory.Create( BINARY_STRICT_READ, BINARY_STRICT_WRITE); |
| 575 | prot_JSON : ProtocolFactory := TJSONProtocolImpl.TFactory.Create; |
Jens Geyer | f0e6331 | 2015-03-01 18:47:49 +0100 | [diff] [blame] | 576 | prot_Compact : ProtocolFactory := TCompactProtocolImpl.TFactory.Create; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 577 | else |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 578 | raise Exception.Create('Unhandled protocol'); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 579 | end; |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 580 | ASSERT( ProtocolFactory <> nil); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 581 | Console.WriteLine('- '+THRIFT_PROTOCOLS[protType]+' protocol'); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 582 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 583 | case endpoint of |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 584 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 585 | trns_Sockets : begin |
| 586 | Console.WriteLine('- sockets (port '+IntToStr(port)+')'); |
| 587 | if (trns_Buffered in layered) then Console.WriteLine('- buffered'); |
| 588 | servertrans := TServerSocketImpl.Create( Port, 0, (trns_Buffered in layered)); |
| 589 | end; |
| 590 | |
Jens Geyer | 0223091 | 2019-04-03 01:12:51 +0200 | [diff] [blame] | 591 | trns_MsxmlHttp, |
| 592 | trns_WinHttp : begin |
| 593 | raise Exception.Create('HTTP server transport not implemented'); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 594 | end; |
| 595 | |
| 596 | trns_NamedPipes : begin |
| 597 | Console.WriteLine('- named pipe ('+sPipeName+')'); |
Jens Geyer | 2ad6c30 | 2015-02-26 19:38:53 +0100 | [diff] [blame] | 598 | namedpipe := TNamedPipeServerTransportImpl.Create( sPipeName, 4096, PIPE_UNLIMITED_INSTANCES); |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 599 | servertrans := namedpipe; |
| 600 | end; |
| 601 | |
| 602 | trns_AnonPipes : begin |
| 603 | Console.WriteLine('- anonymous pipes'); |
| 604 | anonymouspipe := TAnonymousPipeServerTransportImpl.Create; |
| 605 | servertrans := anonymouspipe; |
| 606 | end |
| 607 | |
| 608 | else |
| 609 | raise Exception.Create('Unhandled endpoint transport'); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 610 | end; |
| 611 | ASSERT( servertrans <> nil); |
| 612 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 613 | if UseSSL then begin |
| 614 | raise Exception.Create('SSL not implemented'); |
| 615 | end; |
| 616 | |
| 617 | if (trns_Framed in layered) then begin |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 618 | Console.WriteLine('- framed transport'); |
| 619 | TransportFactory := TFramedTransportImpl.TFactory.Create |
| 620 | end |
| 621 | else begin |
| 622 | TransportFactory := TTransportFactoryImpl.Create; |
| 623 | end; |
| 624 | ASSERT( TransportFactory <> nil); |
| 625 | |
| 626 | testHandler := TTestHandlerImpl.Create; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 627 | testProcessor := TThriftTest.TProcessorImpl.Create( testHandler ); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 628 | |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 629 | case servertype of |
| 630 | srv_Simple : begin |
| 631 | ServerEngine := TSimpleServer.Create( testProcessor, ServerTrans, TransportFactory, ProtocolFactory); |
| 632 | end; |
| 633 | |
| 634 | srv_Nonblocking : begin |
| 635 | raise Exception.Create(SERVER_TYPES[servertype]+' server not implemented'); |
| 636 | end; |
| 637 | |
| 638 | srv_Threadpool, |
| 639 | srv_Threaded: begin |
| 640 | if numWorker > 1 then {use here}; |
| 641 | raise Exception.Create(SERVER_TYPES[servertype]+' server not implemented'); |
| 642 | end; |
| 643 | |
| 644 | else |
| 645 | raise Exception.Create('Unhandled server type'); |
| 646 | end; |
| 647 | ASSERT( ServerEngine <> nil); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 648 | |
| 649 | testHandler.SetServer( ServerEngine); |
| 650 | |
Jens Geyer | 0164040 | 2013-09-25 21:12:21 +0200 | [diff] [blame] | 651 | // test events? |
| 652 | if ServerEvents then begin |
| 653 | Console.WriteLine('- server events test enabled'); |
| 654 | ServerEngine.ServerEvents := TServerEventsImpl.Create; |
| 655 | end; |
| 656 | |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 657 | // start the client now when we have the anon handles, but before the server starts |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 658 | if endpoint = trns_AnonPipes |
Roger Meier | 79655fb | 2012-10-20 20:59:41 +0000 | [diff] [blame] | 659 | then LaunchAnonPipeChild( ExtractFilePath(ParamStr(0))+'client.exe', anonymouspipe); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 660 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 661 | // install Ctrl+C handler before the server starts |
| 662 | g_Handler := testHandler; |
| 663 | SetConsoleCtrlHandler( @MyConsoleEventHandler, TRUE); |
Roger Meier | 3bef8c2 | 2012-10-06 06:58:00 +0000 | [diff] [blame] | 664 | |
| 665 | Console.WriteLine(''); |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 666 | repeat |
| 667 | Console.WriteLine('Starting the server ...'); |
| 668 | serverEngine.Serve; |
| 669 | until {$IFDEF RunEndless} FALSE {$ELSE} TRUE {$ENDIF}; |
| 670 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 671 | testHandler.SetServer( nil); |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 672 | g_Handler := nil; |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 673 | |
| 674 | except |
Jens Geyer | f8a1b7a | 2014-09-24 00:26:46 +0200 | [diff] [blame] | 675 | on E: EAbort do raise; |
| 676 | on E: Exception do begin |
| 677 | Console.WriteLine( E.Message + #10 + E.StackTrace ); |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 678 | end; |
| 679 | end; |
| 680 | Console.WriteLine( 'done.'); |
| 681 | end; |
| 682 | |
Jens Geyer | 06045cf | 2013-03-27 20:26:25 +0200 | [diff] [blame] | 683 | |
Jake Farrell | 2727422 | 2011-11-10 20:32:44 +0000 | [diff] [blame] | 684 | end. |