blob: 03742208589a974cfe48818f7e2a7600cab6729a [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001%%
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
David Reiss8a162a52008-06-11 01:03:16 +000020-module(client).
21
22-include("calculator_thrift.hrl").
23
24-export([t/0]).
25
26p(X) ->
27 io:format("~p~n", [X]),
28 ok.
29
30t() ->
walter-weinmann53106162017-09-18 20:18:50 +020031 Port = 9090,
David Reiss8a162a52008-06-11 01:03:16 +000032
David Reiss3f660a42010-08-30 22:05:29 +000033 {ok, Client0} = thrift_client_util:new("127.0.0.1",
34 Port,
35 calculator_thrift,
36 []),
37
38 {Client1, {ok, ok}} = thrift_client:call(Client0, ping, []),
David Reiss8a162a52008-06-11 01:03:16 +000039 io:format("ping~n", []),
40
David Reiss3f660a42010-08-30 22:05:29 +000041 {Client2, {ok, Sum}} = thrift_client:call(Client1, add, [1, 1]),
David Reiss8a162a52008-06-11 01:03:16 +000042 io:format("1+1=~p~n", [Sum]),
43
David Reiss3f660a42010-08-30 22:05:29 +000044 {Client3, {ok, Sum1}} = thrift_client:call(Client2, add, [1, 4]),
David Reiss8a162a52008-06-11 01:03:16 +000045 io:format("1+4=~p~n", [Sum1]),
46
walter-weinmannfcb2f5a2017-09-05 15:20:37 +020047 Work = #'Work'{op=?TUTORIAL_OPERATION_SUBTRACT,
David Reiss8a162a52008-06-11 01:03:16 +000048 num1=15,
49 num2=10},
David Reiss3f660a42010-08-30 22:05:29 +000050 {Client4, {ok, Diff}} = thrift_client:call(Client3, calculate, [1, Work]),
David Reiss8a162a52008-06-11 01:03:16 +000051 io:format("15-10=~p~n", [Diff]),
52
David Reiss3f660a42010-08-30 22:05:29 +000053 {Client5, {ok, Log}} = thrift_client:call(Client4, getStruct, [1]),
David Reiss8a162a52008-06-11 01:03:16 +000054 io:format("Log: ~p~n", [Log]),
55
David Reiss3f660a42010-08-30 22:05:29 +000056 Client6 =
57 try
walter-weinmannfcb2f5a2017-09-05 15:20:37 +020058 Work1 = #'Work'{op=?TUTORIAL_OPERATION_DIVIDE,
David Reiss3f660a42010-08-30 22:05:29 +000059 num1=1,
60 num2=0},
61 {ClientS1, {ok, _Quot}} = thrift_client:call(Client5, calculate, [2, Work1]),
David Reiss8a162a52008-06-11 01:03:16 +000062
David Reiss3f660a42010-08-30 22:05:29 +000063 io:format("LAME: exception handling is broken~n", []),
64 ClientS1
65 catch
66 throw:{ClientS2, Z} ->
67 io:format("Got exception where expecting - the " ++
68 "following is NOT a problem!!!~n"),
69 p(Z),
70 ClientS2
71 end,
David Reiss8a162a52008-06-11 01:03:16 +000072
73
David Reiss3f660a42010-08-30 22:05:29 +000074 {Client7, {ok, ok}} = thrift_client:call(Client6, zip, []),
David Reiss8a162a52008-06-11 01:03:16 +000075 io:format("zip~n", []),
76
David Reiss3f660a42010-08-30 22:05:29 +000077 {_Client8, ok} = thrift_client:close(Client7),
David Reiss8a162a52008-06-11 01:03:16 +000078 ok.