blob: 35fdf6f5b73b9947b55ca42e8f4e06685450d598 [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,
38 Benchmark, // in gen-delphi folder
39 Aggr, // in gen-delphi folder
40 Multiplex.Test.Common;
41
42type
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
55implementation
56
57
58type
59 IServiceClient = interface
Jens Geyerd5436f52014-10-03 19:50:38 +020060 ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
61 procedure Test;
Jens Geyer8a701962013-03-25 01:28:12 +020062 end;
63
64//--- TTestClient -------------------------------------
65
66
67class procedure TTestClient.Execute( const args: array of string);
68var client : TTestClient;
69begin
70 client := TTestClient.Create(args);
71 try
72 client.Run;
Jens Geyerd5436f52014-10-03 19:50:38 +020073 finally
74 client.Free;
Jens Geyer8a701962013-03-25 01:28:12 +020075 end;
76end;
77
78
79constructor TTestClient.Create( const args: array of string);
80begin
Jens Geyereab29a02014-11-09 23:32:50 +010081 inherited Create;
Jens Geyer8a701962013-03-25 01:28:12 +020082 ParseArgs(args);
83 Setup;
84end;
85
86
87procedure TTestClient.ParseArgs( const args: array of string);
88begin
89 if Length(args) <> 0
90 then raise Exception.Create('No args accepted so far');
91end;
92
93
94procedure TTestClient.Setup;
95var trans : ITransport;
96begin
97 trans := TSocketImpl.Create( 'localhost', 9090);
98 trans := TFramedTransportImpl.Create( trans);
99 trans.Open;
100 FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE);
101end;
102
103
104procedure TTestClient.Run;
105var bench : TBenchmarkService.Iface;
106 aggr : TAggr.Iface;
107 multiplex : IProtocol;
108 i : Integer;
109begin
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
Jens Geyerd5436f52014-10-03 19:50:38 +0200124 on e:Exception do Writeln(#10+e.Message);
125 end;
Jens Geyer8a701962013-03-25 01:28:12 +0200126end;
127
128
129end.
130
131