Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
  • 4 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -1,3 +1,2 @@
-ebin
*.beam
*~
View
21 apps/dummy_app/ebin/dummy_app.appup
@@ -0,0 +1,21 @@
+{"3",
+ %% Upgrade instructions
+ [{"2", [
+ {update,dummy_app_server,{advanced,[from2to3]}}
+ ]}],
+ %% Downgrade instructions
+ [{"2",[
+ {update,dummy_app_server,{advanced,[from3to2]}}
+ ]}]
+}.
+
+{"2",
+ %% Upgrade instructions from 1 to 2
+ [{"1", [
+ {load_module, dummy_app_server}
+ ]}],
+ %% Downgrade instructions from 2 to 1
+ [{"1",[
+ {load_module, dummy_app_server}
+ ]}]
+}.
View
2  apps/dummy_app/src/dummy_app.app.src
@@ -1,7 +1,7 @@
{application, dummy_app,
[
{description, "Dummy project to test release process"},
- {vsn, "1"},
+ {vsn, "3"},
{registered, []},
{applications, [
kernel,
View
55 apps/dummy_app/src/dummy_app_server.erl
@@ -3,23 +3,35 @@
-behaviour(gen_server).
%% API
--export([start_link/0, poke/0, num_pokes/0]).
+%% API
+-export([ start_link/0
+ , poke/0
+ , poke/1
+ , poke_twice/0
+ , num_pokes/0
+ , prod/0
+ , prod/1
+ , num_prods/0
+ ]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--record(state, {num_pokes = 0}).
+-record(state, {num_pokes = 0, num_prods = 0}).
%% API
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+poke() -> poke(1).
+poke_twice() -> poke(2).
+poke(N) -> gen_server:call(?MODULE, {poke, N}).
-poke() ->
- gen_server:call(?MODULE, poke).
+prod() -> prod(1).
+prod(N) -> gen_server:call(?MODULE, {prod, N}).
-num_pokes() ->
- gen_server:call(?MODULE, num_pokes).
+num_pokes() -> gen_server:call(?MODULE, num_pokes).
+num_prods() -> gen_server:call(?MODULE, num_prods).
%% gen_server callbacks
@@ -29,8 +41,17 @@ init([]) ->
handle_call(num_pokes, _From, State = #state{ num_pokes = PokeCount }) ->
{reply, PokeCount, State};
-handle_call(poke, _From, State) ->
- NewPokeCount = State#state.num_pokes + 1,
+handle_call(num_prods, _From, State = #state{ num_prods = ProdCount }) ->
+ {reply, ProdCount, State};
+
+handle_call({prod, N}, _From, State) ->
+ NewProdCount = State#state.num_prods + N,
+ NewState = State#state{num_prods = NewProdCount},
+ Reply = {ok, NewProdCount},
+ {reply, Reply, NewState};
+
+handle_call({poke, N}, _From, State) ->
+ NewPokeCount = State#state.num_pokes + N,
NewState = State#state{num_pokes = NewPokeCount},
Reply = {ok, NewPokeCount},
{reply, Reply, NewState}.
@@ -44,7 +65,15 @@ handle_info(_Info, State) ->
terminate(_Reason, _State) ->
ok.
-code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
+%% Upgrade from 2
+code_change(_OldVsn, State, [from2to3]) ->
+ error_logger:info_msg("CODE_CHANGE from 2~n"),
+ {state, NumPokes} = State, %% State here is the 'old' format, with 1 field
+ NewState = #state{num_pokes=NumPokes}, %% will assume default for num_prods
+ {ok, NewState}.
+
+%% Note downgrade code_change not implemented
+
+
-%%% Internal functions
+%%% Internal functions
View
8 apps/helper_app/ebin/helper_app.app
@@ -0,0 +1,8 @@
+{application,helper_app,
+ [{description,"Helper app for dummy project"},
+ {vsn,"1"},
+ {registered,[]},
+ {applications,[kernel,stdlib]},
+ {mod,{helper_app,[]}},
+ {env,[]},
+ {modules,[helper_app,helper_app_server,helper_app_sup]}]}.
View
12 apps/helper_app/src/helper_app.app.src
@@ -0,0 +1,12 @@
+{application, helper_app,
+ [
+ {description, "Helper app for dummy project"},
+ {vsn, "1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, { helper_app, []}},
+ {env, []}
+ ]}.
View
19 apps/helper_app/src/helper_app.erl
@@ -0,0 +1,19 @@
+-module(helper_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/0, start/2, stop/1]).
+
+start() -> application:start(helper_app).
+
+%% ===================================================================
+%% Application callbacks
+%% ===================================================================
+
+start(_StartType, _StartArgs) ->
+ error_logger:info_msg("Starting helper_app application...~n"),
+ helper_app_sup:start_link().
+
+stop(_State) ->
+ ok.
View
50 apps/helper_app/src/helper_app_server.erl
@@ -0,0 +1,50 @@
+-module(helper_app_server).
+
+-behaviour(gen_server).
+
+%% API
+%% API
+-export([ start_link/0
+ , num_to_comment/1
+ ]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+ terminate/2, code_change/3]).
+
+-record(state, {num_pokes = 0, num_prods = 0}).
+
+%% API
+start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+num_to_comment(N) -> gen_server:call(?MODULE, {num_to_comment, N}).
+
+%% gen_server callbacks
+init([]) ->
+ {ok, #state{}}.
+
+handle_call({num_to_comment, N}, _From, State) ->
+ Reply = comment(N),
+ {reply, Reply, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+%% Upgrade from 2
+code_change(_OldVsn, State, _Extra) ->
+ error_logger:info_msg("code_change in helper app server~n"),
+ {ok, State}.
+
+%% Note downgrade code_change not implemented
+
+
+%%% Internal functions
+
+comment(N) when is_integer(N), N rem 2 =:= 0 -> "An even number!";
+comment(_) -> "An odd number!".
View
30 apps/helper_app/src/helper_app_sup.erl
@@ -0,0 +1,30 @@
+-module(helper_app_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ===================================================================
+%% API functions
+%% ===================================================================
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ===================================================================
+%% Supervisor callbacks
+%% ===================================================================
+
+init([]) ->
+ Children = [
+ ?CHILD(helper_app_server, worker)
+ ],
+ {ok, { {one_for_one, 5, 10}, Children} }.
+
View
1  rebar.config
@@ -1,5 +1,6 @@
{sub_dirs, [
"apps/dummy_app",
+ "apps/helper_app",
"rel"
]}.
View
4 rel/reltool.config
@@ -1,10 +1,11 @@
{sys, [
{lib_dirs, ["../apps"]},
- {rel, "dummy", "1",
+ {rel, "dummy", "4",
[
kernel,
stdlib,
sasl,
+ helper_app,
dummy_app
]},
{rel, "start_clean", "",
@@ -31,3 +32,4 @@
{copy, "files/app.config", "etc/app.config"},
{copy, "files/vm.args", "etc/vm.args"}
]}.
+

No commit comments for this range

Something went wrong with that request. Please try again.