blob: c810a08917fda0d981c01ba8a56e473a386f88ac [file] [log] [blame]
Jens Geyer72034242013-05-08 18:46:57 +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
20using System;
21using System.Collections.Generic;
22using Thrift.Collections;
23using Thrift.Transport;
24using Thrift.Protocol;
25using Thrift.Server;
26using Thrift;
27using Test.Multiplex;
28
Jens Geyer72034242013-05-08 18:46:57 +020029namespace Test.Multiplex.Client
30{
Jens Geyerd5436f52014-10-03 19:50:38 +020031 public class TestClient
32 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090033 static void Execute(int port)
Jens Geyer72034242013-05-08 18:46:57 +020034 {
35 try
36 {
37 TTransport trans;
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090038 trans = new TSocket("localhost", port);
Jens Geyer72034242013-05-08 18:46:57 +020039 trans = new TFramedTransport(trans);
40 trans.Open();
41
42 TProtocol Protocol = new TBinaryProtocol(trans, true, true);
43
44 TMultiplexedProtocol multiplex;
45
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090046 multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_BENCHMARKSERVICE);
47 BenchmarkService.Iface bench = new BenchmarkService.Client(multiplex);
Jens Geyer72034242013-05-08 18:46:57 +020048
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090049 multiplex = new TMultiplexedProtocol(Protocol, Constants.NAME_AGGR);
50 Aggr.Iface aggr = new Aggr.Client(multiplex);
Jens Geyerd5436f52014-10-03 19:50:38 +020051
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090052 for (sbyte i = 1; 10 >= i; ++i)
Jens Geyer72034242013-05-08 18:46:57 +020053 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090054 aggr.addValue(bench.fibonacci(i));
Jens Geyer72034242013-05-08 18:46:57 +020055 }
56
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090057 foreach (int k in aggr.getValues())
Jens Geyer72034242013-05-08 18:46:57 +020058 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090059 Console.Write(k.ToString() + " ");
Jens Geyer72034242013-05-08 18:46:57 +020060 Console.WriteLine("");
61 }
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090062 trans.Close();
Jens Geyer72034242013-05-08 18:46:57 +020063 }
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090064 catch (Exception e)
Jens Geyer72034242013-05-08 18:46:57 +020065 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090066 Console.WriteLine(e.Message);
Jens Geyer72034242013-05-08 18:46:57 +020067 }
68 }
69
Jens Geyer72034242013-05-08 18:46:57 +020070 static void Main(string[] args)
71 {
Nobuaki Sukegawa88c5ee72016-09-04 18:49:18 +090072 int port = 9090;
73 if (args.Length > 0)
74 {
75 port = ushort.Parse(args[0]);
76 }
77 Execute(port);
Jens Geyer72034242013-05-08 18:46:57 +020078 Console.WriteLine("done.");
Jens Geyer72034242013-05-08 18:46:57 +020079 }
Jens Geyer72034242013-05-08 18:46:57 +020080 }
81}
82