blob: b6d5fb62b0acd206ed5872c5565c74e60bd49084 [file] [log] [blame]
Jens Geyer8a701962013-03-25 01:28:12 +02001(*
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 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
25interface
26
27uses
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 Geyera019cda2019-11-09 23:24:52 +010038 Thrift.Configuration,
Jens Geyer66f95362021-03-29 20:35:41 +020039 Benchmark,
40 Aggr,
Jens Geyer8a701962013-03-25 01:28:12 +020041 Multiplex.Test.Common;
42
43type
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
56implementation
57
58
59type
60 IServiceClient = interface
Jens Geyerd5436f52014-10-03 19:50:38 +020061 ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
62 procedure Test;
Jens Geyer8a701962013-03-25 01:28:12 +020063 end;
64
65//--- TTestClient -------------------------------------
66
67
68class procedure TTestClient.Execute( const args: array of string);
69var client : TTestClient;
70begin
71 client := TTestClient.Create(args);
72 try
73 client.Run;
Jens Geyerd5436f52014-10-03 19:50:38 +020074 finally
75 client.Free;
Jens Geyer8a701962013-03-25 01:28:12 +020076 end;
77end;
78
79
80constructor TTestClient.Create( const args: array of string);
81begin
Jens Geyereab29a02014-11-09 23:32:50 +010082 inherited Create;
Jens Geyer8a701962013-03-25 01:28:12 +020083 ParseArgs(args);
84 Setup;
85end;
86
87
88procedure TTestClient.ParseArgs( const args: array of string);
89begin
90 if Length(args) <> 0
91 then raise Exception.Create('No args accepted so far');
92end;
93
94
95procedure TTestClient.Setup;
96var trans : ITransport;
Jens Geyera019cda2019-11-09 23:24:52 +010097 config : IThriftConfiguration;
Jens Geyer8a701962013-03-25 01:28:12 +020098begin
Jens Geyera019cda2019-11-09 23:24:52 +010099 config := TThriftConfigurationImpl.Create;
100 trans := TSocketImpl.Create( 'localhost', 9090, DEFAULT_THRIFT_TIMEOUT, config);
Jens Geyer8a701962013-03-25 01:28:12 +0200101 trans := TFramedTransportImpl.Create( trans);
102 trans.Open;
103 FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE);
104end;
105
106
107procedure TTestClient.Run;
108var bench : TBenchmarkService.Iface;
109 aggr : TAggr.Iface;
110 multiplex : IProtocol;
111 i : Integer;
112begin
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 Geyerd5436f52014-10-03 19:50:38 +0200127 on e:Exception do Writeln(#10+e.Message);
128 end;
Jens Geyer8a701962013-03-25 01:28:12 +0200129end;
130
131
132end.
133
134