blob: fc0dcf86700df52acda150985e36b1c962fe00c7 [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 Reiss6d477592008-06-11 01:12:09 +000020-module(test_disklog).
21
22-compile(export_all).
23
24t() ->
25 {ok, TransportFactory} =
26 thrift_disk_log_transport:new_transport_factory(
27 test_disklog,
28 [{file, "/tmp/test_log"},
29 {size, {1024*1024, 10}}]),
30 {ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
31 TransportFactory, []),
David Reiss01c6d612010-08-30 22:05:49 +000032 {ok, Proto} = ProtocolFactory(),
33 {ok, Client0} = thrift_client:new(Proto, thriftTest_thrift),
David Reiss6d477592008-06-11 01:12:09 +000034
35 io:format("Client started~n"),
David Reiss65cf7202008-06-11 01:12:20 +000036
David Reissc51986f2009-03-24 20:01:25 +000037 % We have to make oneway calls into this client only since otherwise it will try
David Reiss6d477592008-06-11 01:12:09 +000038 % to read from the disklog and go boom.
David Reiss01c6d612010-08-30 22:05:49 +000039 {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]),
David Reiss6d477592008-06-11 01:12:09 +000040 io:format("Call written~n"),
41
David Reissc51986f2009-03-24 20:01:25 +000042 % Use the send_call method to write a non-oneway call into the log
David Reiss01c6d612010-08-30 22:05:49 +000043 {Client2, ok} = thrift_client:send_call(Client1, testString, [<<"hello world">>]),
David Reiss6ce401d2009-03-24 20:01:58 +000044 io:format("Non-oneway call sent~n"),
David Reiss65cf7202008-06-11 01:12:20 +000045
David Reiss01c6d612010-08-30 22:05:49 +000046 {_Client3, ok} = thrift_client:close(Client2),
David Reiss6d477592008-06-11 01:12:09 +000047 io:format("Client closed~n"),
48
49 ok.
50
David Reiss84454062008-06-11 01:12:31 +000051
52
53t_base64() ->
54 {ok, TransportFactory} =
55 thrift_disk_log_transport:new_transport_factory(
56 test_disklog,
57 [{file, "/tmp/test_b64_log"},
58 {size, {1024*1024, 10}}]),
59 {ok, B64Factory} =
60 thrift_base64_transport:new_transport_factory(TransportFactory),
61 {ok, BufFactory} =
62 thrift_buffered_transport:new_transport_factory(B64Factory),
63 {ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
64 BufFactory, []),
David Reiss01c6d612010-08-30 22:05:49 +000065 {ok, Proto} = ProtocolFactory(),
66 {ok, Client0} = thrift_client:new(Proto, thriftTest_thrift),
David Reiss84454062008-06-11 01:12:31 +000067
68 io:format("Client started~n"),
69
David Reissc51986f2009-03-24 20:01:25 +000070 % We have to make oneway calls into this client only since otherwise it will try
David Reiss84454062008-06-11 01:12:31 +000071 % to read from the disklog and go boom.
David Reiss01c6d612010-08-30 22:05:49 +000072 {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]),
David Reiss84454062008-06-11 01:12:31 +000073 io:format("Call written~n"),
74
David Reissc51986f2009-03-24 20:01:25 +000075 % Use the send_call method to write a non-oneway call into the log
David Reiss01c6d612010-08-30 22:05:49 +000076 {Client2, ok} = thrift_client:send_call(Client1, testString, [<<"hello world">>]),
David Reiss6ce401d2009-03-24 20:01:58 +000077 io:format("Non-oneway call sent~n"),
David Reiss84454062008-06-11 01:12:31 +000078
David Reiss01c6d612010-08-30 22:05:49 +000079 {_Client3, ok} = thrift_client:close(Client2),
David Reiss84454062008-06-11 01:12:31 +000080 io:format("Client closed~n"),
81
82 ok.
David Reiss01c6d612010-08-30 22:05:49 +000083