From f973473d47ea3dfd67563e00b6149d5b104fed1d Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Tue, 3 Mar 2015 16:30:29 +0900 Subject: [PATCH] Remove test/pulse_util dir --- .../tango/test/pulse_util/event_logger.erl | 133 --------------- .../tango/test/pulse_util/handle_errors.erl | 153 ------------------ .../tango/test/pulse_util/lamport_clock.erl | 48 ------ 3 files changed, 334 deletions(-) delete mode 100644 prototype/tango/test/pulse_util/event_logger.erl delete mode 100644 prototype/tango/test/pulse_util/handle_errors.erl delete mode 100644 prototype/tango/test/pulse_util/lamport_clock.erl diff --git a/prototype/tango/test/pulse_util/event_logger.erl b/prototype/tango/test/pulse_util/event_logger.erl deleted file mode 100644 index 8633b99..0000000 --- a/prototype/tango/test/pulse_util/event_logger.erl +++ /dev/null @@ -1,133 +0,0 @@ -%%% File : handle_errors.erl -%%% Author : Ulf Norell -%%% Description : -%%% Created : 26 Mar 2012 by Ulf Norell --module(event_logger). - --compile(export_all). - --behaviour(gen_server). - -%% API --export([start_link/0, event/1, event/2, get_events/0, start_logging/0]). --export([timestamp/0]). - -%% gen_server callbacks --export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). - --define(SERVER, ?MODULE). - --record(state, { start_time, events = [] }). - --record(event, { timestamp, data }). - - -%%==================================================================== -%% API -%%==================================================================== -%%-------------------------------------------------------------------- -%% Function: start_link() -> {ok,Pid} | ignore | {error,Error} -%% Description: Starts the server -%%-------------------------------------------------------------------- -start_link() -> - gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). - -start_logging() -> - gen_server:call(?MODULE, {start, timestamp()}). - -event(EventData) -> - event(EventData, timestamp()). - -event(EventData, Timestamp) -> - gen_server:call(?MODULE, - #event{ timestamp = Timestamp, data = EventData }). - -async_event(EventData) -> - gen_server:cast(?MODULE, - #event{ timestamp = timestamp(), data = EventData }). - -get_events() -> - gen_server:call(?MODULE, get_events). - -%%==================================================================== -%% gen_server callbacks -%%==================================================================== - -%%-------------------------------------------------------------------- -%% Function: init(Args) -> {ok, State} | -%% {ok, State, Timeout} | -%% ignore | -%% {stop, Reason} -%% Description: Initiates the server -%%-------------------------------------------------------------------- -init([]) -> - {ok, #state{}}. - -%%-------------------------------------------------------------------- -%% Function: %% handle_call(Request, From, State) -> -%% {reply, Reply, State} | -%% {reply, Reply, State, Timeout} | -%% {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, Reply, State} | -%% {stop, Reason, State} -%% Description: Handling call messages -%%-------------------------------------------------------------------- -handle_call(Event = #event{}, _From, State) -> - {reply, ok, add_event(Event, State)}; -handle_call({start, Now}, _From, S) -> - {reply, ok, S#state{ events = [], start_time = Now }}; -handle_call(get_events, _From, S) -> - {reply, lists:reverse([ {E#event.timestamp, E#event.data} || E <- S#state.events]), - S#state{ events = [] }}; -handle_call(Request, _From, State) -> - {reply, {error, {bad_call, Request}}, State}. - -%%-------------------------------------------------------------------- -%% Function: handle_cast(Msg, State) -> {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} -%% Description: Handling cast messages -%%-------------------------------------------------------------------- -handle_cast(Event = #event{}, State) -> - {noreply, add_event(Event, State)}; -handle_cast(_Msg, State) -> - {noreply, State}. - -%%-------------------------------------------------------------------- -%% Function: handle_info(Info, State) -> {noreply, State} | -%% {noreply, State, Timeout} | -%% {stop, Reason, State} -%% Description: Handling all non call/cast messages -%%-------------------------------------------------------------------- -handle_info(_Info, State) -> - {noreply, State}. - -%%-------------------------------------------------------------------- -%% Function: terminate(Reason, State) -> void() -%% Description: This function is called by a gen_server when it is about to -%% terminate. It should be the opposite of Module:init/1 and do any necessary -%% cleaning up. When it returns, the gen_server terminates with Reason. -%% The return value is ignored. -%%-------------------------------------------------------------------- -terminate(_Reason, _State) -> - ok. - -%%-------------------------------------------------------------------- -%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState} -%% Description: Convert process state when code is changed -%%-------------------------------------------------------------------- -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - -%%-------------------------------------------------------------------- -%%% Internal functions -%%-------------------------------------------------------------------- - -add_event(#event{timestamp = Now, data = Data}, State) -> - Event = #event{ timestamp = Now, data = Data }, - State#state{ events = [Event|State#state.events] }. - -timestamp() -> - lamport_clock:get(). diff --git a/prototype/tango/test/pulse_util/handle_errors.erl b/prototype/tango/test/pulse_util/handle_errors.erl deleted file mode 100644 index 798f379..0000000 --- a/prototype/tango/test/pulse_util/handle_errors.erl +++ /dev/null @@ -1,153 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @author Hans Svensson <> -%%% @copyright (C) 2012, Hans Svensson -%%% @doc -%%% -%%% @end -%%% Created : 19 Mar 2012 by Hans Svensson <> -%%%------------------------------------------------------------------- --module(handle_errors). - --behaviour(gen_event). - -%% API --export([start_link/0, add_handler/0]). - -%% gen_event callbacks --export([init/1, handle_event/2, handle_call/2, - handle_info/2, terminate/2, code_change/3]). - --define(SERVER, ?MODULE). - --record(state, { errors = [] }). - -%%%=================================================================== -%%% gen_event callbacks -%%%=================================================================== - -%%-------------------------------------------------------------------- -%% @doc -%% Creates an event manager -%% -%% @spec start_link() -> {ok, Pid} | {error, Error} -%% @end -%%-------------------------------------------------------------------- -start_link() -> - gen_event:start_link({local, ?SERVER}). - -%%-------------------------------------------------------------------- -%% @doc -%% Adds an event handler -%% -%% @spec add_handler() -> ok | {'EXIT', Reason} | term() -%% @end -%%-------------------------------------------------------------------- -add_handler() -> - gen_event:add_handler(?SERVER, ?MODULE, []). - -%%%=================================================================== -%%% gen_event callbacks -%%%=================================================================== - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Whenever a new event handler is added to an event manager, -%% this function is called to initialize the event handler. -%% -%% @spec init(Args) -> {ok, State} -%% @end -%%-------------------------------------------------------------------- -init([]) -> - {ok, #state{}}. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Whenever an event manager receives an event sent using -%% gen_event:notify/2 or gen_event:sync_notify/2, this function is -%% called for each installed event handler to handle the event. -%% -%% @spec handle_event(Event, State) -> -%% {ok, State} | -%% {swap_handler, Args1, State1, Mod2, Args2} | -%% remove_handler -%% @end -%%-------------------------------------------------------------------- -handle_event({error, _, {_, "Hintfile '~s' has bad CRC" ++ _, _}}, State) -> - {ok, State}; -handle_event({error, _, {_, "** Generic server" ++ _, _}}, State) -> - {ok, State}; -handle_event({error, _, {_, "Failed to merge ~p: ~p\n", [_, not_ready]}}, State) -> - {ok, State}; -handle_event({error, _, {_, "Failed to merge ~p: ~p\n", [_, {merge_locked, _, _}]}}, State) -> - {ok, State}; -handle_event({error, _, {_, "Failed to read lock data from ~s: ~p\n", [_, {invalid_data, <<>>}]}}, State) -> - {ok, State}; -handle_event({error, _, Event}, State) -> - {ok, State#state{ errors = [Event|State#state.errors] }}; -handle_event(_Event, State) -> - {ok, State}. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Whenever an event manager receives a request sent using -%% gen_event:call/3,4, this function is called for the specified -%% event handler to handle the request. -%% -%% @spec handle_call(Request, State) -> -%% {ok, Reply, State} | -%% {swap_handler, Reply, Args1, State1, Mod2, Args2} | -%% {remove_handler, Reply} -%% @end -%%-------------------------------------------------------------------- -handle_call(get_errors, S) -> - {ok, S#state.errors, S#state{ errors = [] }}; -handle_call(_Request, State) -> - Reply = ok, - {ok, Reply, State}. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% This function is called for each installed event handler when -%% an event manager receives any other message than an event or a -%% synchronous request (or a system message). -%% -%% @spec handle_info(Info, State) -> -%% {ok, State} | -%% {swap_handler, Args1, State1, Mod2, Args2} | -%% remove_handler -%% @end -%%-------------------------------------------------------------------- -handle_info(_Info, State) -> - {ok, State}. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Whenever an event handler is deleted from an event manager, this -%% function is called. It should be the opposite of Module:init/1 and -%% do any necessary cleaning up. -%% -%% @spec terminate(Reason, State) -> void() -%% @end -%%-------------------------------------------------------------------- -terminate(_Reason, _State) -> - ok. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% Convert process state when code is changed -%% -%% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} -%% @end -%%-------------------------------------------------------------------- -code_change(_OldVsn, State, _Extra) -> - {ok, State}. - -%%%=================================================================== -%%% Internal functions -%%%=================================================================== diff --git a/prototype/tango/test/pulse_util/lamport_clock.erl b/prototype/tango/test/pulse_util/lamport_clock.erl deleted file mode 100644 index fab7244..0000000 --- a/prototype/tango/test/pulse_util/lamport_clock.erl +++ /dev/null @@ -1,48 +0,0 @@ - --module(lamport_clock). - --export([init/0, get/0, update/1, incr/0]). - --define(KEY, ?MODULE). - --ifdef(TEST). - -init() -> - case get(?KEY) of - undefined -> - %% {Ca, Cb, _} = now(), - %% FakeTOD = ((Ca * 1000000) + Cb) * 1000000, - FakeTOD = 0, - put(?KEY, FakeTOD + 1); - N when is_integer(N) -> - ok - end. - -get() -> - get(?KEY). - -update(Remote) -> - New = erlang:max(get(?KEY), Remote) + 1, - put(?KEY, New), - New. - -incr() -> - New = get(?KEY) + 1, - put(?KEY, New), - New. - --else. % TEST - -init() -> - ok. - -get() -> - ok. - -update(_) -> - ok. - -incr() -> - ok. - --endif. % TEST