Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +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 | |
| 20 | -module(test_disklog). |
| 21 | |
| 22 | -ifdef(TEST). |
| 23 | -include_lib("eunit/include/eunit.hrl"). |
| 24 | |
| 25 | disklog_test() -> |
| 26 | {ok, TransportFactory} = |
| 27 | thrift_disk_log_transport:new_transport_factory( |
| 28 | test_disklog, |
alisdair sullivan | ec71f2e | 2014-10-08 18:26:11 -0700 | [diff] [blame] | 29 | [{file, "./test_log"}, |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 30 | {size, {1024*1024, 10}}]), |
| 31 | {ok, ProtocolFactory} = |
| 32 | thrift_binary_protocol:new_protocol_factory( TransportFactory, []), |
| 33 | {ok, Proto} = ProtocolFactory(), |
Jens Geyer | 6d15c30 | 2014-10-02 10:03:09 +0200 | [diff] [blame] | 34 | {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift), |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 35 | |
| 36 | io:format("Client started~n"), |
| 37 | |
| 38 | % We have to make oneway calls into this client only since otherwise it |
| 39 | % will try to read from the disklog and go boom. |
| 40 | {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]), |
| 41 | io:format("Call written~n"), |
| 42 | |
| 43 | % Use the send_call method to write a non-oneway call into the log |
| 44 | {Client2, ok} = |
| 45 | thrift_client:send_call(Client1, testString, [<<"hello world">>]), |
| 46 | io:format("Non-oneway call sent~n"), |
| 47 | |
| 48 | {_Client3, ok} = thrift_client:close(Client2), |
| 49 | io:format("Client closed~n"), |
Jens Geyer | 5aff35f | 2014-10-01 21:06:52 +0200 | [diff] [blame] | 50 | |
| 51 | lists:foreach(fun(File) -> file:delete(File) end, [ |
alisdair sullivan | ec71f2e | 2014-10-08 18:26:11 -0700 | [diff] [blame] | 52 | "./test_log.1", |
| 53 | "./test_log.idx", |
| 54 | "./test_log.siz" |
Jens Geyer | 5aff35f | 2014-10-01 21:06:52 +0200 | [diff] [blame] | 55 | ]), |
| 56 | io:format("Cleaning up test files~n"), |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 57 | |
| 58 | ok. |
| 59 | |
| 60 | disklog_base64_test() -> |
| 61 | {ok, TransportFactory} = |
| 62 | thrift_disk_log_transport:new_transport_factory( |
| 63 | test_disklog, |
alisdair sullivan | ec71f2e | 2014-10-08 18:26:11 -0700 | [diff] [blame] | 64 | [{file, "./test_b64_log"}, |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 65 | {size, {1024*1024, 10}}]), |
| 66 | {ok, B64Factory} = |
| 67 | thrift_base64_transport:new_transport_factory(TransportFactory), |
| 68 | {ok, BufFactory} = |
| 69 | thrift_buffered_transport:new_transport_factory(B64Factory), |
| 70 | {ok, ProtocolFactory} = |
| 71 | thrift_binary_protocol:new_protocol_factory(BufFactory, []), |
| 72 | {ok, Proto} = ProtocolFactory(), |
Jens Geyer | 6d15c30 | 2014-10-02 10:03:09 +0200 | [diff] [blame] | 73 | {ok, Client0} = thrift_client:new(Proto, thrift_test_thrift), |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 74 | |
| 75 | io:format("Client started~n"), |
| 76 | |
| 77 | % We have to make oneway calls into this client only since otherwise |
| 78 | % it will try to read from the disklog and go boom. |
| 79 | {Client1, {ok, ok}} = thrift_client:call(Client0, testOneway, [16#deadbeef]), |
| 80 | io:format("Call written~n"), |
| 81 | |
| 82 | % Use the send_call method to write a non-oneway call into the log |
| 83 | {Client2, ok} = |
| 84 | thrift_client:send_call(Client1, testString, [<<"hello world">>]), |
| 85 | io:format("Non-oneway call sent~n"), |
| 86 | |
| 87 | {_Client3, ok} = thrift_client:close(Client2), |
| 88 | io:format("Client closed~n"), |
| 89 | |
Jens Geyer | 5aff35f | 2014-10-01 21:06:52 +0200 | [diff] [blame] | 90 | lists:foreach(fun(File) -> file:delete(File) end, [ |
alisdair sullivan | ec71f2e | 2014-10-08 18:26:11 -0700 | [diff] [blame] | 91 | "./test_b64_log.1", |
| 92 | "./test_b64_log.idx", |
| 93 | "./test_b64_log.siz" |
Jens Geyer | 5aff35f | 2014-10-01 21:06:52 +0200 | [diff] [blame] | 94 | ]), |
| 95 | io:format("Cleaning up test files~n"), |
| 96 | |
Anthony F. Molinaro | 917d898 | 2011-06-21 06:20:18 +0000 | [diff] [blame] | 97 | ok. |
| 98 | |
| 99 | -endif. |