Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 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 | using System; |
| 21 | using System.Collections.Generic; |
| 22 | using Thrift.Collections; |
| 23 | using Thrift.Transport; |
| 24 | using Thrift.Protocol; |
| 25 | using Thrift.Server; |
| 26 | using Thrift; |
| 27 | using Test.Multiplex; |
| 28 | |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 29 | namespace Test.Multiplex.Client |
| 30 | { |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 31 | public class TestClient |
| 32 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 33 | static void Execute(int port) |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 34 | { |
| 35 | try |
| 36 | { |
| 37 | TTransport trans; |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 38 | trans = new TSocket("localhost", port); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 39 | trans = new TFramedTransport(trans); |
| 40 | trans.Open(); |
| 41 | |
| 42 | TProtocol Protocol = new TBinaryProtocol(trans, true, true); |
| 43 | |
| 44 | TMultiplexedProtocol multiplex; |
| 45 | |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 46 | multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_BENCHMARKSERVICE); |
| 47 | BenchmarkService.Iface bench = new BenchmarkService.Client(multiplex); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 48 | |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 49 | multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_AGGR); |
| 50 | Aggr.Iface aggr = new Aggr.Client(multiplex); |
Jens Geyer | d5436f5 | 2014-10-03 19:50:38 +0200 | [diff] [blame] | 51 | |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 52 | for (sbyte i = 1; 10 >= i; ++i) |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 53 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 54 | aggr.addValue(bench.fibonacci(i)); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 57 | foreach (int k in aggr.getValues()) |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 58 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 59 | Console.Write(k.ToString() + " "); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 60 | Console.WriteLine(""); |
| 61 | } |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 62 | trans.Close(); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 63 | } |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 64 | catch (Exception e) |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 65 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 66 | Console.WriteLine(e.Message); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 70 | static void Main(string[] args) |
| 71 | { |
Nobuaki Sukegawa | 88c5ee7 | 2016-09-04 18:49:18 +0900 | [diff] [blame] | 72 | int port = 9090; |
| 73 | if (args.Length > 0) |
| 74 | { |
| 75 | port = ushort.Parse(args[0]); |
| 76 | } |
| 77 | Execute(port); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 78 | Console.WriteLine("done."); |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 79 | } |
Jens Geyer | 7203424 | 2013-05-08 18:46:57 +0200 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |