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