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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
25 import org.apache.thrift.*;
26 import org.apache.thrift.protocol.*;
27 import org.apache.thrift.transport.*;
28 import org.apache.thrift.server.*;
29 import org.apache.thrift.meta_data.*;
32 import org.apache.thrift.protocol.TProtocolDecorator;
33 import org.apache.thrift.protocol.TMultiplexedProtocol;
34 import org.apache.thrift.protocol.TMultiplexedProcessor;
36 // generated code imports
40 import BenchmarkService;
41 import BenchmarkServiceImpl;
42 import BenchmarkServiceProcessor;
46 class BenchmarkServiceHandler implements BenchmarkService
48 public function new() {
51 public function fibonacci(n : haxe.Int32) : haxe.Int32 {
52 trace('Benchmark.fibonacci($n)');
68 class AggrServiceHandler implements Aggr
70 private var values : List<haxe.Int32> = new List<haxe.Int32>();
72 public function new() {
75 public function addValue(value : haxe.Int32) : Void {
76 trace('Aggr.addValue($value)');
80 public function getValues() : List< haxe.Int32> {
81 trace('Aggr.getValues()');
88 class MultiplexTest extends TestBase {
90 private inline static var NAME_BENCHMARKSERVICE : String = "BenchmarkService";
91 private inline static var NAME_AGGR : String = "Aggr";
94 public static override function Run(server : Bool) : Void {
104 // run the multiplex server
105 public static override function RunMultiplexServer() : Void {
108 var benchHandler : BenchmarkService = new BenchmarkServiceHandler();
109 var benchProcessor : TProcessor = new BenchmarkServiceProcessor( benchHandler);
111 var aggrHandler : Aggr = new AggrServiceHandler();
112 var aggrProcessor : TProcessor = new AggrProcessor( aggrHandler);
114 var multiplex : TMultiplexedProcessor = new TMultiplexedProcessor();
115 multiplex.RegisterProcessor( NAME_BENCHMARKSERVICE, benchProcessor, true); // default
116 multiplex.RegisterProcessor( NAME_AGGR, aggrProcessor);
118 // protocol+transport stack
119 var protfact : TProtocolFactory = new TBinaryProtocolFactory(true,true);
120 var servertrans : TServerTransport = new TServerSocket( 9090, 5, false);
121 var transfact : TTransportFactory = new TFramedTransportFactory();
123 var server : TServer = new TSimpleServer( multiplex, servertrans, transfact, protfact);
125 trace("Starting the server ...");
128 catch( e : TApplicationException)
130 TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
132 catch( e : TException)
134 TestBase.Expect(false,'$e');
139 // run multiplex client against multiplex server
140 public static override function RunMultiplexClient() : Void {
143 var trans : TTransport;
144 trans = new TSocket("localhost", 9090);
145 trans = new TFramedTransport(trans);
148 var protocol : TProtocol = new TBinaryProtocol(trans,true,true);
149 var multiplex : TMultiplexedProtocol;
151 multiplex = new TMultiplexedProtocol( protocol, NAME_BENCHMARKSERVICE);
152 var bench = new BenchmarkServiceImpl( multiplex);
154 multiplex = new TMultiplexedProtocol( protocol, NAME_AGGR);
155 var aggr = new AggrImpl( multiplex);
157 trace('calling aggr.add( bench.fibo())...');
161 aggr.addValue( bench.fibonacci(i));
164 trace('calling aggr ...');
166 var values = aggr.getValues();
167 TestBase.Expect(values != null,'aggr.getValues() == null');
170 trace('fib($i) = $k');
178 catch( e : TApplicationException)
180 TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
182 catch( e : TException)
184 TestBase.Expect(false,'$e');
189 // run non-multiplex client against multiplex server to test default fallback
190 public static override function RunDefaultClient() : Void {
193 var trans : TTransport;
194 trans = new TSocket("localhost", 9090);
195 trans = new TFramedTransport(trans);
198 var protocol : TProtocol = new TBinaryProtocol(trans,true,true);
200 var bench = new BenchmarkServiceImpl( protocol);
202 trace('calling bench (via default) ...');
205 var k = bench.fibonacci(i);
206 trace('fib($i) = $k');
212 catch( e : TApplicationException)
214 TestBase.Expect(false,'${e.errorID} ${e.errorMsg}');
216 catch( e : TException)
218 TestBase.Expect(false,'$e');