Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [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 Multiplex.Client.Main; |
| 21 | |
| 22 | {.$DEFINE StressTest} // activate to stress-test the server with frequent connects/disconnects |
| 23 | {.$DEFINE PerfTest} // activate to activate the performance test |
| 24 | |
| 25 | interface |
| 26 | |
| 27 | uses |
| 28 | Windows, SysUtils, Classes, |
| 29 | DateUtils, |
| 30 | Generics.Collections, |
| 31 | Thrift, |
| 32 | Thrift.Protocol, |
| 33 | Thrift.Protocol.Multiplex, |
| 34 | Thrift.Transport.Pipes, |
| 35 | Thrift.Transport, |
| 36 | Thrift.Stream, |
| 37 | Thrift.Collections, |
| 38 | Benchmark, // in gen-delphi folder |
| 39 | Aggr, // in gen-delphi folder |
| 40 | Multiplex.Test.Common; |
| 41 | |
| 42 | type |
| 43 | TTestClient = class |
| 44 | protected |
| 45 | FProtocol : IProtocol; |
| 46 | |
| 47 | procedure ParseArgs( const args: array of string); |
| 48 | procedure Setup; |
| 49 | procedure Run; |
| 50 | public |
| 51 | constructor Create( const args: array of string); |
| 52 | class procedure Execute( const args: array of string); |
| 53 | end; |
| 54 | |
| 55 | implementation |
| 56 | |
| 57 | |
| 58 | type |
| 59 | IServiceClient = interface |
| 60 | ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
|
| 61 | procedure Test;
|
| 62 | end; |
| 63 | |
| 64 | //--- TTestClient ------------------------------------- |
| 65 | |
| 66 | |
| 67 | class procedure TTestClient.Execute( const args: array of string); |
| 68 | var client : TTestClient; |
| 69 | begin |
| 70 | client := TTestClient.Create(args); |
| 71 | try |
| 72 | client.Run; |
| 73 | finally
|
| 74 | client.Free;
|
| 75 | end; |
| 76 | end; |
| 77 | |
| 78 | |
| 79 | constructor TTestClient.Create( const args: array of string); |
| 80 | begin |
| 81 | ParseArgs(args); |
| 82 | Setup; |
| 83 | end; |
| 84 | |
| 85 | |
| 86 | procedure TTestClient.ParseArgs( const args: array of string); |
| 87 | begin |
| 88 | if Length(args) <> 0 |
| 89 | then raise Exception.Create('No args accepted so far'); |
| 90 | end; |
| 91 | |
| 92 | |
| 93 | procedure TTestClient.Setup; |
| 94 | var trans : ITransport; |
| 95 | begin |
| 96 | trans := TSocketImpl.Create( 'localhost', 9090); |
| 97 | trans := TFramedTransportImpl.Create( trans); |
| 98 | trans.Open; |
| 99 | FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE); |
| 100 | end; |
| 101 | |
| 102 | |
| 103 | procedure TTestClient.Run; |
| 104 | var bench : TBenchmarkService.Iface; |
| 105 | aggr : TAggr.Iface; |
| 106 | multiplex : IProtocol; |
| 107 | i : Integer; |
| 108 | begin |
| 109 | try |
| 110 | multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_BENCHMARKSERVICE); |
| 111 | bench := TBenchmarkService.TClient.Create( multiplex); |
| 112 | |
| 113 | multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_AGGR); |
| 114 | aggr := TAggr.TClient.Create( multiplex); |
| 115 | |
| 116 | for i := 1 to 10 |
| 117 | do aggr.addValue( bench.fibonacci(i)); |
| 118 | |
| 119 | for i in aggr.getValues |
| 120 | do Write(IntToStr(i)+' '); |
| 121 | WriteLn; |
| 122 | except |
| 123 | on e:Exception do Writeln(#10+e.Message);
|
| 124 | end;
|
| 125 | end; |
| 126 | |
| 127 | |
| 128 | end. |
| 129 | |
| 130 | |