blob: 5d003dac49743dd7b7e484e61d1472806f2a9cd7 [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 Meier3bef8c22012-10-06 06:58:00 +000081 class procedure LaunchAnonPipeChild( const app : string; const transport : IPipeServer);
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
408class procedure TTestServer.LaunchAnonPipeChild( const app : string; const transport : IPipeServer);
409//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 Meier3bef8c22012-10-06 06:58:00 +0000460 pipeserver : IPipeServer;
Jake Farrell27274222011-11-10 20:32:44 +0000461 TransportFactory : ITransportFactory;
462 ProtocolFactory : IProtocolFactory;
463 i : Integer;
464 s : string;
465 protType, p : TKnownProtocol;
466begin
467 try
468 UseBufferedSockets := False;
469 UseFramed := False;
Roger Meier3bef8c22012-10-06 06:58:00 +0000470 AnonPipe := FALSE;
Jake Farrell27274222011-11-10 20:32:44 +0000471 protType := prot_Binary;
472 Port := 9090;
Roger Meier3bef8c22012-10-06 06:58:00 +0000473 sPipeName := '';
Jake Farrell27274222011-11-10 20:32:44 +0000474
475 i := 0;
476 while ( i < Length(args) ) do begin
477 s := args[i];
478 Inc(i);
479
480 if StrToIntDef( s, -1) > 0 then
481 begin
482 Port := StrToIntDef( s, Port);
Roger Meier3bef8c22012-10-06 06:58:00 +0000483 end
484 else if ( s = 'raw' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000485 begin
486 // as default
Roger Meier3bef8c22012-10-06 06:58:00 +0000487 end
488 else if ( s = 'buffered' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000489 begin
490 UseBufferedSockets := True;
Roger Meier3bef8c22012-10-06 06:58:00 +0000491 end
492 else if ( s = 'framed' ) then
Jake Farrell27274222011-11-10 20:32:44 +0000493 begin
494 UseFramed := True;
Roger Meier3bef8c22012-10-06 06:58:00 +0000495 end
496 else if (s = '-pipe') then
497 begin
498 sPipeName := args[i]; // -pipe <name>
499 Inc( i );
500 end
501 else if (s = '-anon') then
502 begin
503 AnonPipe := TRUE;
504 end
505 else if (s = '-prot') then // -prot JSON|binary
Jake Farrell27274222011-11-10 20:32:44 +0000506 begin
507 s := args[i];
508 Inc( i );
509 for p:= Low(TKnownProtocol) to High(TKnownProtocol) do begin
510 if SameText( s, KNOWN_PROTOCOLS[p]) then begin
511 protType := p;
512 Break;
513 end;
514 end;
515 end else
516 begin
517 // Fall back to the older boolean syntax
518 UseBufferedSockets := StrToBoolDef( args[1], UseBufferedSockets);
519 end
520 end;
521
Roger Meier3bef8c22012-10-06 06:58:00 +0000522
523 Console.WriteLine('Server configuration: ');
524
Jake Farrell27274222011-11-10 20:32:44 +0000525 // create protocol factory, default to BinaryProtocol
526 case protType of
527 prot_Binary: ProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
528 prot_JSON : ProtocolFactory := TJSONProtocolImpl.TFactory.Create;
529 else
530 ASSERT( FALSE); // unhandled case!
531 ProtocolFactory := TBinaryProtocolImpl.TFactory.Create;
532 end;
Roger Meier3bef8c22012-10-06 06:58:00 +0000533 ASSERT( ProtocolFactory <> nil);
534 Console.WriteLine('- '+KNOWN_PROTOCOLS[protType]+' protocol');
Jake Farrell27274222011-11-10 20:32:44 +0000535
Jake Farrell27274222011-11-10 20:32:44 +0000536
Roger Meier3bef8c22012-10-06 06:58:00 +0000537 if sPipeName <> '' then begin
538 Console.WriteLine('- named pipe ('+sPipeName+')');
539 pipeserver := TServerPipeImpl.Create( sPipeName);
540 servertrans := pipeserver;
541 end
542 else if AnonPipe then begin
543 Console.WriteLine('- anonymous pipes');
544 pipeserver := TServerPipeImpl.Create;
545 servertrans := pipeserver;
546 end
547 else begin
548 Console.WriteLine('- sockets (port '+IntToStr(port)+')');
549 if UseBufferedSockets then Console.WriteLine('- buffered sockets');
550 servertrans := TServerSocketImpl.Create( Port, 0, UseBufferedSockets);
551 end;
552 ASSERT( servertrans <> nil);
553
554 if UseFramed then begin
555 Console.WriteLine('- framed transport');
556 TransportFactory := TFramedTransportImpl.TFactory.Create
557 end
558 else begin
559 TransportFactory := TTransportFactoryImpl.Create;
560 end;
561 ASSERT( TransportFactory <> nil);
562
563 testHandler := TTestHandlerImpl.Create;
Jake Farrell27274222011-11-10 20:32:44 +0000564 testProcessor := TThriftTest.TProcessorImpl.Create( testHandler );
Jake Farrell27274222011-11-10 20:32:44 +0000565
566 ServerEngine := TSimpleServer.Create( testProcessor,
Roger Meier3bef8c22012-10-06 06:58:00 +0000567 ServerTrans,
Jake Farrell27274222011-11-10 20:32:44 +0000568 TransportFactory,
569 ProtocolFactory);
570
571 testHandler.SetServer( ServerEngine);
572
Roger Meier3bef8c22012-10-06 06:58:00 +0000573 // start the client now when we have the anon handles, but before the server starts
574 if AnonPipe
575 then LaunchAnonPipeChild( ExtractFilePath(ParamStr(0))+'client.exe', pipeserver);
Jake Farrell27274222011-11-10 20:32:44 +0000576
Roger Meier3bef8c22012-10-06 06:58:00 +0000577
578 Console.WriteLine('');
579 Console.WriteLine('Starting the server ...');
Jake Farrell27274222011-11-10 20:32:44 +0000580 serverEngine.Serve;
581 testHandler.SetServer( nil);
582
583 except
584 on E: Exception do
585 begin
586 Console.Write( E.Message);
587 end;
588 end;
589 Console.WriteLine( 'done.');
590end;
591
592end.