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 inherited Create; 82 ParseArgs(args); 83 Setup; 84 end; 85 86 87 procedure TTestClient.ParseArgs( const args: array of string); 88 begin 89 if Length(args) <> 0 90 then raise Exception.Create('No args accepted so far'); 91 end; 92 93 94 procedure TTestClient.Setup; 95 var trans : ITransport; 96 begin 97 trans := TSocketImpl.Create( 'localhost', 9090); 98 trans := TFramedTransportImpl.Create( trans); 99 trans.Open; 100 FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE); 101 end; 102 103 104 procedure TTestClient.Run; 105 var bench : TBenchmarkService.Iface; 106 aggr : TAggr.Iface; 107 multiplex : IProtocol; 108 i : Integer; 109 begin 110 try 111 multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_BENCHMARKSERVICE); 112 bench := TBenchmarkService.TClient.Create( multiplex); 113 114 multiplex := TMultiplexedProtocol.Create( FProtocol, NAME_AGGR); 115 aggr := TAggr.TClient.Create( multiplex); 116 117 for i := 1 to 10 118 do aggr.addValue( bench.fibonacci(i)); 119 120 for i in aggr.getValues 121 do Write(IntToStr(i)+' '); 122 WriteLn; 123 except 124 on e:Exception do Writeln(#10+e.Message); 125 end; 126 end; 127 128 129 end. 130 131 132