David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [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 | |
David Reiss | 6d47759 | 2008-06-11 01:12:09 +0000 | [diff] [blame] | 20 | -module(test_disklog). |
| 21 | |
| 22 | -compile(export_all). |
| 23 | |
| 24 | t() -> |
| 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, []), |
| 32 | {ok, Client} = thrift_client:start_link(ProtocolFactory, thriftTest_thrift), |
| 33 | |
| 34 | io:format("Client started~n"), |
David Reiss | 65cf720 | 2008-06-11 01:12:20 +0000 | [diff] [blame] | 35 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 36 | % We have to make oneway calls into this client only since otherwise it will try |
David Reiss | 6d47759 | 2008-06-11 01:12:09 +0000 | [diff] [blame] | 37 | % to read from the disklog and go boom. |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 38 | {ok, ok} = thrift_client:call(Client, testOneway, [16#deadbeef]), |
David Reiss | 6d47759 | 2008-06-11 01:12:09 +0000 | [diff] [blame] | 39 | io:format("Call written~n"), |
| 40 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 41 | % Use the send_call method to write a non-oneway call into the log |
David Reiss | 65cf720 | 2008-06-11 01:12:20 +0000 | [diff] [blame] | 42 | ok = thrift_client:send_call(Client, testString, [<<"hello world">>]), |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 43 | io:format("Non-oneway call sent~n"), |
David Reiss | 65cf720 | 2008-06-11 01:12:20 +0000 | [diff] [blame] | 44 | |
David Reiss | 6d47759 | 2008-06-11 01:12:09 +0000 | [diff] [blame] | 45 | ok = thrift_client:close(Client), |
| 46 | io:format("Client closed~n"), |
| 47 | |
| 48 | ok. |
| 49 | |
David Reiss | 8445406 | 2008-06-11 01:12:31 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | t_base64() -> |
| 53 | {ok, TransportFactory} = |
| 54 | thrift_disk_log_transport:new_transport_factory( |
| 55 | test_disklog, |
| 56 | [{file, "/tmp/test_b64_log"}, |
| 57 | {size, {1024*1024, 10}}]), |
| 58 | {ok, B64Factory} = |
| 59 | thrift_base64_transport:new_transport_factory(TransportFactory), |
| 60 | {ok, BufFactory} = |
| 61 | thrift_buffered_transport:new_transport_factory(B64Factory), |
| 62 | {ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory( |
| 63 | BufFactory, []), |
| 64 | {ok, Client} = thrift_client:start_link(ProtocolFactory, thriftTest_thrift), |
| 65 | |
| 66 | io:format("Client started~n"), |
| 67 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 68 | % We have to make oneway calls into this client only since otherwise it will try |
David Reiss | 8445406 | 2008-06-11 01:12:31 +0000 | [diff] [blame] | 69 | % to read from the disklog and go boom. |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 70 | {ok, ok} = thrift_client:call(Client, testOneway, [16#deadbeef]), |
David Reiss | 8445406 | 2008-06-11 01:12:31 +0000 | [diff] [blame] | 71 | io:format("Call written~n"), |
| 72 | |
David Reiss | c51986f | 2009-03-24 20:01:25 +0000 | [diff] [blame] | 73 | % Use the send_call method to write a non-oneway call into the log |
David Reiss | 8445406 | 2008-06-11 01:12:31 +0000 | [diff] [blame] | 74 | ok = thrift_client:send_call(Client, testString, [<<"hello world">>]), |
David Reiss | 6ce401d | 2009-03-24 20:01:58 +0000 | [diff] [blame] | 75 | io:format("Non-oneway call sent~n"), |
David Reiss | 8445406 | 2008-06-11 01:12:31 +0000 | [diff] [blame] | 76 | |
| 77 | ok = thrift_client:close(Client), |
| 78 | io:format("Client closed~n"), |
| 79 | |
| 80 | ok. |
| 81 | |