blob: 7048a208e3055ff452e9465ef35860e0c5c65c29 [file] [log] [blame]
Jake Farrell27274222011-11-10 20:32:44 +00001(*
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
20unit TestServer;
21
Roger Meier3bef8c22012-10-06 06:58:00 +000022{$WARN SYMBOL_PLATFORM OFF}
23
Jake Farrell27274222011-11-10 20:32:44 +000024interface
25
26uses
Roger Meier3bef8c22012-10-06 06:58:00 +000027 Windows, SysUtils,
Jake Farrell27274222011-11-10 20:32:44 +000028 Generics.Collections,
29 Thrift.Console,
30 Thrift.Server,
31 Thrift.Transport,
Roger Meier3bef8c22012-10-06 06:58:00 +000032 Thrift.Transport.Pipes,
Jake Farrell27274222011-11-10 20:32:44 +000033 Thrift.Protocol,
34 Thrift.Protocol.JSON,
35 Thrift.Collections,
36 Thrift.Utils,
37 Thrift.Test,
38 Thrift,
39 TestConstants,
40 Contnrs;
41
42type
43 TTestServer = class
44 public
45 type
46
47 ITestHandler = interface( TThriftTest.Iface )
Roger Meier333bbf32012-01-08 21:51:08 +000048 procedure SetServer( const AServer : IServer );
Jake Farrell27274222011-11-10 20:32:44 +000049 end;
50
51 TTestHandlerImpl = class( TInterfacedObject, ITestHandler )
52 private
53 FServer : IServer;
54 protected
55 procedure testVoid();
Roger Meier333bbf32012-01-08 21:51:08 +000056 function testString(const thing: string): string;
Jake Farrell7ae13e12011-10-18 14:35:26 +000057 function testByte(thing: ShortInt): ShortInt;
58 function testI32(thing: Integer): Integer;
Roger Meier333bbf32012-01-08 21:51:08 +000059 function testI64(const thing: Int64): Int64;
60 function testDouble(const thing: Double): Double;
61 function testStruct(const thing: IXtruct): IXtruct;
62 function testNest(const thing: IXtruct2): IXtruct2;
63 function testMap(const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>;
64 function testStringMap(const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>;
65 function testSet(const thing: IHashSet<Integer>): IHashSet<Integer>;
66 function testList(const thing: IThriftList<Integer>): IThriftList<Integer>;
Jake Farrell7ae13e12011-10-18 14:35:26 +000067 function testEnum(thing: TNumberz): TNumberz;
Roger Meier333bbf32012-01-08 21:51:08 +000068 function testTypedef(const thing: Int64): Int64;
Jake Farrell7ae13e12011-10-18 14:35:26 +000069 function testMapMap(hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>;
Roger Meier333bbf32012-01-08 21:51:08 +000070 function testInsanity(const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
71 function testMulti(arg0: ShortInt; arg1: Integer; const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>; arg4: TNumberz; const arg5: Int64): IXtruct;
72 procedure testException(const arg: string);
73 function testMultiException(const arg0: string; const arg1: string): IXtruct;
Jake Farrell7ae13e12011-10-18 14:35:26 +000074 procedure testOneway(secondsToSleep: Integer);
Jake Farrell27274222011-11-10 20:32:44 +000075
76 procedure testStop;
77
Roger Meier333bbf32012-01-08 21:51:08 +000078 procedure SetServer( const AServer : IServer );
Jake Farrell27274222011-11-10 20:32:44 +000079 end;
80
Roger Meier79655fb2012-10-20 20:59:41 +000081 class procedure LaunchAnonPipeChild( const app : string; const transport : IAnonymousServerPipe);
Roger Meier333bbf32012-01-08 21:51:08 +000082 class procedure Execute( const args: array of string);
Jake Farrell27274222011-11-10 20:32:44 +000083 end;
84
85implementation
86
87{ TTestServer.TTestHandlerImpl }
88
Roger Meier333bbf32012-01-08 21:51:08 +000089procedure TTestServer.TTestHandlerImpl.SetServer( const AServer: IServer);
Jake Farrell27274222011-11-10 20:32:44 +000090begin
91 FServer := AServer;
92end;
93
94function TTestServer.TTestHandlerImpl.testByte(thing: ShortInt): ShortInt;
95begin
96 Console.WriteLine('testByte("' + IntToStr( thing) + '")');
97 Result := thing;
98end;
99
Roger Meier333bbf32012-01-08 21:51:08 +0000100function TTestServer.TTestHandlerImpl.testDouble( const thing: Double): Double;
Jake Farrell27274222011-11-10 20:32:44 +0000101begin
102 Console.WriteLine('testDouble("' + FloatToStr( thing ) + '")');
103 Result := thing;
104end;
105
106function TTestServer.TTestHandlerImpl.testEnum(thing: TNumberz): TNumberz;
107begin
108 Console.WriteLine('testEnum(' + IntToStr( Integer( thing)) + ')');
109 Result := thing;
110end;
111
Roger Meier333bbf32012-01-08 21:51:08 +0000112procedure TTestServer.TTestHandlerImpl.testException(const arg: string);
Jake Farrell27274222011-11-10 20:32:44 +0000113begin
114 Console.WriteLine('testException(' + arg + ')');
115 if ( arg = 'Xception') then
116 begin
Roger Meierbb6de7a2012-05-04 23:35:45 +0000117 raise TXception.Create( 1001, arg);
Jake Farrell27274222011-11-10 20:32:44 +0000118 end;
Roger Meierbb6de7a2012-05-04 23:35:45 +0000119
120 if (arg = 'TException') then
121 begin
122 raise TException.Create('');
123 end;
124
125 // else do not throw anything
Jake Farrell27274222011-11-10 20:32:44 +0000126end;
127
128function TTestServer.TTestHandlerImpl.testI32(thing: Integer): Integer;
129begin
130 Console.WriteLine('testI32("' + IntToStr( thing) + '")');
131 Result := thing;
132end;
133
Roger Meier333bbf32012-01-08 21:51:08 +0000134function TTestServer.TTestHandlerImpl.testI64( const thing: Int64): Int64;
Jake Farrell27274222011-11-10 20:32:44 +0000135begin
136 Console.WriteLine('testI64("' + IntToStr( thing) + '")');
137 Result := thing;
138end;
139
140function TTestServer.TTestHandlerImpl.testInsanity(
Roger Meier333bbf32012-01-08 21:51:08 +0000141 const argument: IInsanity): IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
Jake Farrell27274222011-11-10 20:32:44 +0000142var
143 hello, goodbye : IXtruct;
144 crazy : IInsanity;
145 looney : IInsanity;
146 first_map : IThriftDictionary<TNumberz, IInsanity>;
147 second_map : IThriftDictionary<TNumberz, IInsanity>;
148 insane : IThriftDictionary<Int64, IThriftDictionary<TNumberz, IInsanity>>;
149
150begin
151
152 Console.WriteLine('testInsanity()');
153 hello := TXtructImpl.Create;
Roger Meierbb6de7a2012-05-04 23:35:45 +0000154 hello.String_thing := 'Hello2';
Jake Farrell27274222011-11-10 20:32:44 +0000155 hello.Byte_thing := 2;
156 hello.I32_thing := 2;
157 hello.I64_thing := 2;
158
159 goodbye := TXtructImpl.Create;
160 goodbye.String_thing := 'Goodbye4';
161 goodbye.Byte_thing := 4;
162 goodbye.I32_thing := 4;
163 goodbye.I64_thing := 4;
164
165 crazy := TInsanityImpl.Create;
166 crazy.UserMap := TThriftDictionaryImpl<TNumberz, Int64>.Create;
167 crazy.UserMap.AddOrSetValue( TNumberz.EIGHT, 8);
168 crazy.Xtructs := TThriftListImpl<IXtruct>.Create;
169 crazy.Xtructs.Add(goodbye);
170
171 looney := TInsanityImpl.Create;
172 crazy.UserMap.AddOrSetValue( TNumberz.FIVE, 5);
173 crazy.Xtructs.Add(hello);
174
175 first_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create;
176 second_map := TThriftDictionaryImpl<TNumberz, IInsanity>.Create;
177
Roger Meierbb6de7a2012-05-04 23:35:45 +0000178 first_map.AddOrSetValue( TNumberz.TWO, crazy);
Jake Farrell27274222011-11-10 20:32:44 +0000179 first_map.AddOrSetValue( TNumberz.THREE, crazy);
180
181 second_map.AddOrSetValue( TNumberz.SIX, looney);
182
183 insane := TThriftDictionaryImpl<Int64, IThriftDictionary<TNumberz, IInsanity>>.Create;
184
185 insane.AddOrSetValue( 1, first_map);
186 insane.AddOrSetValue( 2, second_map);
187
188 Result := insane;
189end;
190
191function TTestServer.TTestHandlerImpl.testList(
Roger Meier333bbf32012-01-08 21:51:08 +0000192 const thing: IThriftList<Integer>): IThriftList<Integer>;
Jake Farrell27274222011-11-10 20:32:44 +0000193var
194 first : Boolean;
195 elem : Integer;
196begin
197 Console.Write('testList({');
198 first := True;
199 for elem in thing do
200 begin
201 if first then
202 begin
203 first := False;
204 end else
205 begin
206 Console.Write(', ');
207 end;
208 Console.Write( IntToStr( elem));
209 end;
210 Console.WriteLine('})');
211 Result := thing;
212end;
213
214function TTestServer.TTestHandlerImpl.testMap(
Roger Meier333bbf32012-01-08 21:51:08 +0000215 const thing: IThriftDictionary<Integer, Integer>): IThriftDictionary<Integer, Integer>;
Jake Farrell27274222011-11-10 20:32:44 +0000216var
217 first : Boolean;
218 key : Integer;
219begin
220 Console.Write('testMap({');
221 first := True;
222 for key in thing.Keys do
223 begin
224 if (first) then
225 begin
226 first := false;
227 end else
228 begin
229 Console.Write(', ');
230 end;
231 Console.Write(IntToStr(key) + ' => ' + IntToStr( thing[key]));
232 end;
233 Console.WriteLine('})');
234 Result := thing;
235end;
236
237function TTestServer.TTestHandlerImpl.TestMapMap(
238 hello: Integer): IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>;
239var
240 mapmap : IThriftDictionary<Integer, IThriftDictionary<Integer, Integer>>;
241 pos : IThriftDictionary<Integer, Integer>;
242 neg : IThriftDictionary<Integer, Integer>;
243 i : Integer;
244begin
245 Console.WriteLine('testMapMap(' + IntToStr( hello) + ')');
246 mapmap := TThriftDictionaryImpl<Integer, IThriftDictionary<Integer, Integer>>.Create;
247 pos := TThriftDictionaryImpl<Integer, Integer>.Create;
248 neg := TThriftDictionaryImpl<Integer, Integer>.Create;
249
250 for i := 1 to 4 do
251 begin
252 pos.AddOrSetValue( i, i);
253 neg.AddOrSetValue( -i, -i);
254 end;
255
256 mapmap.AddOrSetValue(4, pos);
257 mapmap.AddOrSetValue( -4, neg);
258
259 Result := mapmap;
260end;
261
262function TTestServer.TTestHandlerImpl.testMulti(arg0: ShortInt; arg1: Integer;
Roger Meier333bbf32012-01-08 21:51:08 +0000263 const arg2: Int64; const arg3: IThriftDictionary<SmallInt, string>;
264 arg4: TNumberz; const arg5: Int64): IXtruct;
Jake Farrell27274222011-11-10 20:32:44 +0000265var
266 hello : IXtruct;
267begin
268 Console.WriteLine('testMulti()');
269 hello := TXtructImpl.Create;
270 hello.String_thing := 'Hello2';
271 hello.Byte_thing := arg0;
272 hello.I32_thing := arg1;
273 hello.I64_thing := arg2;
274 Result := hello;
275end;
276
Roger Meier333bbf32012-01-08 21:51:08 +0000277function TTestServer.TTestHandlerImpl.testMultiException( const arg0, arg1: string): IXtruct;
Jake Farrell27274222011-11-10 20:32:44 +0000278var
Jake Farrell27274222011-11-10 20:32:44 +0000279 x2 : TXception2;
280begin
281 Console.WriteLine('testMultiException(' + arg0 + ', ' + arg1 + ')');
282 if ( arg0 = 'Xception') then
283 begin
Jake Farrell343c61d2011-12-09 02:29:56 +0000284 raise TXception.Create( 1001, 'This is an Xception'); // test the new rich CTOR
Jake Farrell27274222011-11-10 20:32:44 +0000285 end else
286 if ( arg0 = 'Xception2') then
287 begin
Jake Farrell343c61d2011-12-09 02:29:56 +0000288 x2 := TXception2.Create; // the old way still works too?
Jake Farrell27274222011-11-10 20:32:44 +0000289 x2.ErrorCode := 2002;
290 x2.Struct_thing := TXtructImpl.Create;
291 x2.Struct_thing.String_thing := 'This is an Xception2';
Jake Farrellac102562011-11-23 14:30:41 +0000292 x2.UpdateMessageProperty;
Jake Farrell27274222011-11-10 20:32:44 +0000293 raise x2;
294 end;
295
296 Result := TXtructImpl.Create;
297 Result.String_thing := arg1;
298end;
299
Roger Meier333bbf32012-01-08 21:51:08 +0000300function TTestServer.TTestHandlerImpl.testNest( const thing: IXtruct2): IXtruct2;
Jake Farrell27274222011-11-10 20:32:44 +0000301var
302 temp : IXtruct;
303begin
304 temp := thing.Struct_thing;
305 Console.WriteLine('testNest({' +
306 IntToStr( thing.Byte_thing) + ', {' +
307 '"' + temp.String_thing + '", ' +
308 IntToStr( temp.Byte_thing) + ', ' +
309 IntToStr( temp.I32_thing) + ', ' +
310 IntToStr( temp.I64_thing) + '}, ' +
311 IntToStr( temp.I32_thing) + '})');
312 Result := thing;
313end;
314
315procedure TTestServer.TTestHandlerImpl.testOneway(secondsToSleep: Integer);
316begin
317 Console.WriteLine('testOneway(' + IntToStr( secondsToSleep )+ '), sleeping...');
318 Sleep(secondsToSleep * 1000);
319 Console.WriteLine('testOneway finished');
320end;
321
322function TTestServer.TTestHandlerImpl.testSet(
Roger Meier333bbf32012-01-08 21:51:08 +0000323 const thing: IHashSet<Integer>):IHashSet<Integer>;
Jake Farrell27274222011-11-10 20:32:44 +0000324var
325 first : Boolean;
326 elem : Integer;
327begin
328 Console.Write('testSet({');
329 first := True;
330
331 for elem in thing do
332 begin
333 if first then
334 begin
335 first := False;
336 end else
337 begin
338 Console.Write( ', ');
339 end;
340 Console.Write( IntToStr( elem));
341 end;
342 Console.WriteLine('})');
343 Result := thing;
344end;
345
346procedure TTestServer.TTestHandlerImpl.testStop;
347begin
348 if FServer <> nil then
349 begin
350 FServer.Stop;
351 end;
352end;
353
Roger Meier333bbf32012-01-08 21:51:08 +0000354function TTestServer.TTestHandlerImpl.testString( const thing: string): string;
Jake Farrell27274222011-11-10 20:32:44 +0000355begin
356 Console.WriteLine('teststring("' + thing + '")');
357 Result := thing;
358end;
359
360function TTestServer.TTestHandlerImpl.testStringMap(
Roger Meier333bbf32012-01-08 21:51:08 +0000361 const thing: IThriftDictionary<string, string>): IThriftDictionary<string, string>;
Roger Meierbb6de7a2012-05-04 23:35:45 +0000362var
363 first : Boolean;
364 key : string;
Jake Farrell27274222011-11-10 20:32:44 +0000365begin
Roger Meierbb6de7a2012-05-04 23:35:45 +0000366 Console.Write('testStringMap({');
367 first := True;
368 for key in thing.Keys do
369 begin
370 if (first) then
371 begin
372 first := false;
373 end else
374 begin
375 Console.Write(', ');
376 end;
377 Console.Write(key + ' => ' + thing[key]);
378 end;
379 Console.WriteLine('})');
380 Result := thing;
Jake Farrell27274222011-11-10 20:32:44 +0000381end;
382
Roger Meier333bbf32012-01-08 21:51:08 +0000383function TTestServer.TTestHandlerImpl.testTypedef( const thing: Int64): Int64;
Jake Farrell27274222011-11-10 20:32:44 +0000384begin
385 Console.WriteLine('testTypedef(' + IntToStr( thing) + ')');
386 Result := thing;
387end;
388
389procedure TTestServer.TTestHandlerImpl.TestVoid;
390begin
391 Console.WriteLine('testVoid()');
392end;
393
Roger Meier333bbf32012-01-08 21:51:08 +0000394function TTestServer.TTestHandlerImpl.testStruct( const thing: IXtruct): IXtruct;
Jake Farrell27274222011-11-10 20:32:44 +0000395begin
396 Console.WriteLine('testStruct({' +
397 '"' + thing.String_thing + '", ' +
398 IntToStr( thing.Byte_thing) + ', ' +
399 IntToStr( thing.I32_thing) + ', ' +
400 IntToStr( thing.I64_thing));
401 Result := thing;
402end;
403
Roger Meier3bef8c22012-10-06 06:58:00 +0000404
Jake Farrell27274222011-11-10 20:32:44 +0000405{ TTestServer }
406
Roger Meier3bef8c22012-10-06 06:58:00 +0000407
Roger Meier79655fb2012-10-20 20:59:41 +0000408class procedure TTestServer.LaunchAnonPipeChild( const app : string; const transport : IAnonymousServerPipe);
Roger Meier3bef8c22012-10-06 06:58:00 +0000409//Launch child process and pass R/W anonymous pipe handles on cmd line.
410//This is a simple example and does not include elevation or other
411//advanced features.
412var pi : PROCESS_INFORMATION;
413 si : STARTUPINFO;
414 sArg, sHandles, sCmdLine : string;
415 i : Integer;
416begin
417 GetStartupInfo( si); //set startupinfo for the spawned process
418
419 // preformat handles args
420 sHandles := Format( '%d %d',
421 [ Integer(transport.ClientAnonRead),
422 Integer(transport.ClientAnonWrite)]);
423
424 // pass all settings to client
425 sCmdLine := app;
426 for i := 1 to ParamCount do begin
427 sArg := ParamStr(i);
428
429 // add anonymous handles and quote strings where appropriate
430 if sArg = '-anon'
431 then sArg := sArg +' '+ sHandles
432 else begin
433 if Pos(' ',sArg) > 0
434 then sArg := '"'+sArg+'"';
435 end;;
436
437 sCmdLine := sCmdLine +' '+ sArg;
438 end;
439
440 // spawn the child process
441 Console.WriteLine('Starting client '+sCmdLine);
442 Win32Check( CreateProcess( nil, PChar(sCmdLine), nil,nil,TRUE,0,nil,nil,si,pi));
443
444 CloseHandle( pi.hThread);
445 CloseHandle( pi.hProcess);
446end;
447
448
Roger Meier333bbf32012-01-08 21:51:08 +0000449class procedure TTestServer.Execute( const args: array of string);
Jake Farrell27274222011-11-10 20:32:44 +0000450var
451 UseBufferedSockets : Boolean;
452 UseFramed : Boolean;
453 Port : Integer;
Roger Meier3bef8c22012-10-06 06:58:00 +0000454 AnonPipe : Boolean;
455 sPipeName : string;
Jake Farrell27274222011-11-10 20:32:44 +0000456 testHandler : ITestHandler;
457 testProcessor : IProcessor;
Roger Meier3bef8c22012-10-06 06:58:00 +0000458 ServerTrans : IServerTransport;
Jake Farrell27274222011-11-10 20:32:44 +0000459 ServerEngine : IServer;
Roger Meier79655fb2012-10-20 20:59:41 +0000460 anonymouspipe : IAnonymousServerPipe;
461 namedpipe : INamedServerPipe;
Jake Farrell27274222011-11-10 20:32:44 +0000462 TransportFactory : ITransportFactory;
463 ProtocolFactory : IProtocolFactory;
464 i : Integer;
465 s : string;
466 protType, p : TKnownProtocol;
467begin
468 try
469 UseBufferedSockets := False;
470 UseFramed := False;
Roger Meier3bef8c22012-10-06 06:58:00 +0000471 AnonPipe := FALSE;
Jake Farrell27274222011-11-10 20:32:44 +0000472 protType := prot_Binary;
473 Port := 9090;
Roger Meier3bef8c22012-10-06 06:58:00 +0000474 sPipeName := '';
Jake Farrell27274222011-11-10 20:32:44 +0000475
476 i := 0;
477 while ( i < Length(args) ) do begin
478 s := args[i];
479 Inc(i);
480
481 if StrToIntDef( s, -1) > 0 then
482 begin
483 Port := StrToIntDef( s, Port);
Roger Meier3bef8c22012-10-06 06:58:00 +0000484 end
485 else if ( s = 'raw' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000486 begin
487 // as default
Roger Meier3bef8c22012-10-06 06:58:00 +0000488 end
489 else if ( s = 'buffered' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000490 begin
491 UseBufferedSockets := True;
Roger Meier3bef8c22012-10-06 06:58:00 +0000492 end
493 else if ( s = 'framed' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000494 begin
495 UseFramed := True;
Roger Meier3bef8c22012-10-06 06:58:00 +0000496 end
497 else if (s = '-pipe') then
498 begin
499 sPipeName := args[i]; // -pipe <name>
500 Inc( i );
501 end
502 else if (s = '-anon') then
503 begin
504 AnonPipe := TRUE;
505 end
506 else if (s = '-prot') then // -prot JSON|binary
Jake Farrell27274222011-11-10 20:32:44 +0000507 begin
508 s := args[i];
509 Inc( i );
510 for p:= Low(TKnownProtocol) to High(TKnownProtocol) do begin
511 if SameText( s, KNOWN_PROTOCOLS[p]) then begin
512 protType := p;
513 Break;
514 end;
515 end;
516 end else
517 begin
518 // Fall back to the older boolean syntax
519 UseBufferedSockets := StrToBoolDef( args[1], UseBufferedSockets);
520 end
521 end;
522
Roger Meier3bef8c22012-10-06 06:58:00 +0000523
524 Console.WriteLine('Server configuration: ');
525
Jake Farrell27274222011-11-10 20:32:44 +0000526 // create protocol factory, default to BinaryProtocol
527 case protType of
528 prot_Binary: ProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
529 prot_JSON : ProtocolFactory := TJSONProtocolImpl.TFactory.Create;
530 else
531 ASSERT( FALSE); // unhandled case!
532 ProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
533 end;
Roger Meier3bef8c22012-10-06 06:58:00 +0000534 ASSERT( ProtocolFactory <> nil);
535 Console.WriteLine('- '+KNOWN_PROTOCOLS[protType]+' protocol');
Jake Farrell27274222011-11-10 20:32:44 +0000536
Jake Farrell27274222011-11-10 20:32:44 +0000537
Roger Meier3bef8c22012-10-06 06:58:00 +0000538 if sPipeName <> '' then begin
539 Console.WriteLine('- named pipe ('+sPipeName+')');
Roger Meier79655fb2012-10-20 20:59:41 +0000540 namedpipe := TNamedServerPipeImpl.Create( sPipeName);
541 servertrans := namedpipe;
Roger Meier3bef8c22012-10-06 06:58:00 +0000542 end
543 else if AnonPipe then begin
544 Console.WriteLine('- anonymous pipes');
Roger Meier79655fb2012-10-20 20:59:41 +0000545 anonymouspipe := TAnonymousServerPipeImpl.Create;
546 servertrans := anonymouspipe;
Roger Meier3bef8c22012-10-06 06:58:00 +0000547 end
548 else begin
549 Console.WriteLine('- sockets (port '+IntToStr(port)+')');
550 if UseBufferedSockets then Console.WriteLine('- buffered sockets');
551 servertrans := TServerSocketImpl.Create( Port, 0, UseBufferedSockets);
552 end;
553 ASSERT( servertrans <> nil);
554
555 if UseFramed then begin
556 Console.WriteLine('- framed transport');
557 TransportFactory := TFramedTransportImpl.TFactory.Create
558 end
559 else begin
560 TransportFactory := TTransportFactoryImpl.Create;
561 end;
562 ASSERT( TransportFactory <> nil);
563
564 testHandler := TTestHandlerImpl.Create;
Jake Farrell27274222011-11-10 20:32:44 +0000565 testProcessor := TThriftTest.TProcessorImpl.Create( testHandler );
Jake Farrell27274222011-11-10 20:32:44 +0000566
567 ServerEngine := TSimpleServer.Create( testProcessor,
Roger Meier3bef8c22012-10-06 06:58:00 +0000568 ServerTrans,
Jake Farrell27274222011-11-10 20:32:44 +0000569 TransportFactory,
570 ProtocolFactory);
571
572 testHandler.SetServer( ServerEngine);
573
Roger Meier3bef8c22012-10-06 06:58:00 +0000574 // start the client now when we have the anon handles, but before the server starts
575 if AnonPipe
Roger Meier79655fb2012-10-20 20:59:41 +0000576 then LaunchAnonPipeChild( ExtractFilePath(ParamStr(0))+'client.exe', anonymouspipe);
Jake Farrell27274222011-11-10 20:32:44 +0000577
Roger Meier3bef8c22012-10-06 06:58:00 +0000578
579 Console.WriteLine('');
580 Console.WriteLine('Starting the server ...');
Jake Farrell27274222011-11-10 20:32:44 +0000581 serverEngine.Serve;
582 testHandler.SetServer( nil);
583
584 except
585 on E: Exception do
586 begin
587 Console.Write( E.Message);
588 end;
589 end;
590 Console.WriteLine( 'done.');
591end;
592
593end.