2012-10-10 22:14:06 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2012 Basho Technologies, Inc.
|
|
|
|
%%
|
|
|
|
%% This file is provided to you under the Apache License,
|
|
|
|
%% Version 2.0 (the "License"); you may not use this file
|
|
|
|
%% except in compliance with the License. You may obtain
|
|
|
|
%% a copy of the License at
|
|
|
|
%%
|
|
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
%%
|
|
|
|
%% Unless required by applicable law or agreed to in writing,
|
|
|
|
%% software distributed under the License is distributed on an
|
|
|
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
%% KIND, either express or implied. See the License for the
|
|
|
|
%% specific language governing permissions and limitations
|
|
|
|
%% under the License.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
2012-09-07 15:06:40 +00:00
|
|
|
-module(rpc_output).
|
|
|
|
|
2012-12-14 15:50:49 +00:00
|
|
|
-behavior(riak_test).
|
2012-09-07 15:06:40 +00:00
|
|
|
-export([confirm/0]).
|
2012-12-14 15:50:49 +00:00
|
|
|
|
2012-09-12 16:44:48 +00:00
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
-compile([{parse_transform, lager_transform}]).
|
2012-09-07 15:06:40 +00:00
|
|
|
|
2012-09-12 16:44:48 +00:00
|
|
|
-behavior(gen_event).
|
|
|
|
|
|
|
|
%% gen_event callbacks
|
|
|
|
-export([init/1,
|
|
|
|
handle_call/2,
|
|
|
|
handle_event/2,
|
|
|
|
handle_info/2,
|
|
|
|
terminate/2,
|
|
|
|
code_change/3]).
|
2014-05-22 21:54:23 +00:00
|
|
|
|
2012-09-07 15:06:40 +00:00
|
|
|
confirm() ->
|
2012-09-12 16:44:48 +00:00
|
|
|
gen_event:add_handler(lager_event, ?MODULE, []),
|
2012-09-07 15:43:56 +00:00
|
|
|
io:put_chars("This is an io:put_chars/1 call"),
|
|
|
|
io:format("This is an io:format/1 call"),
|
|
|
|
io:format("This is an io:format/~w call", [2]),
|
2012-09-12 16:44:48 +00:00
|
|
|
lager:info("This is a lager message"),
|
|
|
|
{ok, {LogId, Failures}} = gen_event:delete_handler(lager_event, ?MODULE, []),
|
|
|
|
?assertEqual(5, LogId),
|
2014-05-22 21:54:23 +00:00
|
|
|
?assertEqual([], Failures),
|
|
|
|
pass.
|
2012-09-12 16:44:48 +00:00
|
|
|
|
|
|
|
-record(state, {level = debug, verbose = true, log_id = 1, failures = []}).
|
|
|
|
|
|
|
|
init(_) -> {ok, #state{}}.
|
|
|
|
handle_event({log, _Dest, _Level, {_Date, _Time}, [_LevelStr, _Location, Message]},
|
|
|
|
State) ->
|
|
|
|
check_log_message(lists:flatten(Message), State);
|
|
|
|
handle_event({log, _Level, {_Date, _Time}, [_LevelStr, _Location, Message]}, State) ->
|
|
|
|
check_log_message(lists:flatten(Message), State);
|
|
|
|
handle_event(_, State) ->
|
|
|
|
{ok, State}.
|
2014-05-22 21:54:23 +00:00
|
|
|
|
2012-09-12 16:44:48 +00:00
|
|
|
handle_call(_, State) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
handle_info(_, State) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
terminate(_Reason, #state{log_id = LogId, failures = Failures}) ->
|
|
|
|
{ok, {LogId, Failures}}.
|
2014-05-22 21:54:23 +00:00
|
|
|
|
2012-09-12 16:44:48 +00:00
|
|
|
check_log_message(Message, #state{log_id = LogId, failures = Failures} = State) ->
|
|
|
|
try
|
|
|
|
case LogId of
|
|
|
|
1 -> ?assertEqual(Message, "This is an io:put_chars/1 call");
|
|
|
|
2 -> ?assertEqual(Message, "This is an io:format/1 call");
|
|
|
|
3 -> ?assertEqual(Message, "This is an io:format/2 call");
|
|
|
|
4 -> ?assertEqual(Message, "This is a lager message");
|
|
|
|
_ -> ?assert(false)
|
|
|
|
end,
|
|
|
|
{ok, State#state{log_id = LogId + 1}}
|
|
|
|
catch
|
|
|
|
_:Reason -> {ok, State#state{log_id = LogId + 1, failures = [Reason|Failures]}}
|
2014-05-22 21:54:23 +00:00
|
|
|
end.
|