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, |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 38 | Thrift.Configuration, |
Jens Geyer | 66f9536 | 2021-03-29 20:35:41 +0200 | [diff] [blame] | 39 | Benchmark, |
| 40 | Aggr, |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 41 | Multiplex.Test.Common; |
| 42 | |
| 43 | type |
| 44 | TTestClient = class |
| 45 | protected |
| 46 | FProtocol : IProtocol; |
| 47 | |
| 48 | procedure ParseArgs( const args: array of string); |
| 49 | procedure Setup; |
| 50 | procedure Run; |
| 51 | public |
| 52 | constructor Create( const args: array of string); |
| 53 | class procedure Execute( const args: array of string); |
| 54 | end; |
| 55 | |
| 56 | implementation |
| 57 | |
| 58 | |
| 59 | type |
| 60 | IServiceClient = interface |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 61 | ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}'] |
| 62 | procedure Test; |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 63 | end; |
| 64 | |
| 65 | //--- TTestClient ------------------------------------- |
| 66 | |
| 67 | |
| 68 | class procedure TTestClient.Execute( const args: array of string); |
| 69 | var client : TTestClient; |
| 70 | begin |
| 71 | client := TTestClient.Create(args); |
| 72 | try |
| 73 | client.Run; |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 74 | finally |
| 75 | client.Free; |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 76 | end; |
| 77 | end; |
| 78 | |
| 79 | |
| 80 | constructor TTestClient.Create( const args: array of string); |
| 81 | begin |
Jens Geyer | eab29a0 | 2014-11-09 23:32:50 +0100 | [diff] [blame] | 82 | inherited Create; |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 83 | ParseArgs(args); |
| 84 | Setup; |
| 85 | end; |
| 86 | |
| 87 | |
| 88 | procedure TTestClient.ParseArgs( const args: array of string); |
| 89 | begin |
| 90 | if Length(args) <> 0 |
| 91 | then raise Exception.Create('No args accepted so far'); |
| 92 | end; |
| 93 | |
| 94 | |
| 95 | procedure TTestClient.Setup; |
| 96 | var trans : ITransport; |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 97 | config : IThriftConfiguration; |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 98 | begin |
Jens Geyer | a019cda | 2019-11-09 23:24:52 +0100 | [diff] [blame] | 99 | config := TThriftConfigurationImpl.Create; |
| 100 | trans := TSocketImpl.Create( 'localhost', 9090, DEFAULT_THRIFT_TIMEOUT, config); |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 101 | trans := TFramedTransportImpl.Create( trans); |
| 102 | trans.Open; |
| 103 | FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE); |
| 104 | end; |
| 105 | |
| 106 | |
| 107 | procedure TTestClient.Run; |
| 108 | var bench : TBenchmarkService.Iface; |
| 109 | aggr : TAggr.Iface; |
| 110 | multiplex : IProtocol; |
| 111 | i : Integer; |
| 112 | begin |
| 113 | try |
| 114 | multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_BENCHMARKSERVICE); |
| 115 | bench := TBenchmarkService.TClient.Create( multiplex); |
| 116 | |
| 117 | multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_AGGR); |
| 118 | aggr := TAggr.TClient.Create( multiplex); |
| 119 | |
| 120 | for i := 1 to 10 |
| 121 | do aggr.addValue( bench.fibonacci(i)); |
| 122 | |
| 123 | for i in aggr.getValues |
| 124 | do Write(IntToStr(i)+' '); |
| 125 | WriteLn; |
| 126 | except |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 127 | on e:Exception do Writeln(#10+e.Message); |
| 128 | end; |
Jens Geyer | 8a70196 | 2013-03-25 01:28:12 +0200 | [diff] [blame] | 129 | end; |
| 130 | |
| 131 | |
| 132 | end. |
| 133 | |
| 134 | |