blob: 2cc7ab03f569a002f6b7010629159e60f67213a4 [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
60 ['{7745C1C2-AB20-43BA-B6F0-08BF92DE0BAC}']
61 procedure Test;
62 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;
73 finally
74 client.Free;
75 end;
76end;
77
78
79constructor TTestClient.Create( const args: array of string);
80begin
81 ParseArgs(args);
82 Setup;
83end;
84
85
86procedure TTestClient.ParseArgs( const args: array of string);
87begin
88 if Length(args) <> 0
89 then raise Exception.Create('No args accepted so far');
90end;
91
92
93procedure TTestClient.Setup;
94var trans : ITransport;
95begin
96 trans := TSocketImpl.Create( 'localhost', 9090);
97 trans := TFramedTransportImpl.Create( trans);
98 trans.Open;
99 FProtocol := TBinaryProtocolImpl.Create( trans, TRUE, TRUE);
100end;
101
102
103procedure TTestClient.Run;
104var bench : TBenchmarkService.Iface;
105 aggr : TAggr.Iface;
106 multiplex : IProtocol;
107 i : Integer;
108begin
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;
125end;
126
127
128end.
129
130