Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 4 files changed
  • 0 comments
  • 1 contributor
11  apps/dummy_app/ebin/dummy_app.appup
... ...
@@ -1,3 +1,14 @@
  1
+{"3", 
  2
+    %% Upgrade instructions
  3
+    [{"2", [
  4
+        {update,dummy_app_server,{advanced,[from2to3]}}
  5
+    ]}], 
  6
+    %% Downgrade instructions
  7
+    [{"2",[
  8
+        {update,dummy_app_server,{advanced,[from3to2]}}
  9
+    ]}]
  10
+}.
  11
+
1 12
 {"2",
2 13
     %% Upgrade instructions from 1 to 2
3 14
     [{"1", [
2  apps/dummy_app/src/dummy_app.app.src
... ...
@@ -1,7 +1,7 @@
1 1
 {application, dummy_app,
2 2
  [
3 3
   {description, "Dummy project to test release process"},
4  
-  {vsn, "2"},
  4
+  {vsn, "3"},
5 5
   {registered, []},
6 6
   {applications, [
7 7
                   kernel,
60  apps/dummy_app/src/dummy_app_server.erl
@@ -3,26 +3,35 @@
3 3
 -behaviour(gen_server).
4 4
 
5 5
 %% API
6  
--export([start_link/0, poke/0, num_pokes/0, poke_twice/0]).
  6
+%% API
  7
+-export([ start_link/0
  8
+        , poke/0
  9
+        , poke/1
  10
+        , poke_twice/0
  11
+        , num_pokes/0
  12
+        , prod/0
  13
+        , prod/1
  14
+        , num_prods/0
  15
+        ]).
7 16
 
8 17
 %% gen_server callbacks
9 18
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
10 19
      terminate/2, code_change/3]).
11 20
 
12  
--record(state, {num_pokes = 0}).
  21
+-record(state, {num_pokes = 0, num_prods = 0}).
13 22
 
14 23
 %% API
15  
-start_link() ->
16  
-    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
  24
+start_link()    -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
17 25
 
18  
-poke() ->
19  
-    gen_server:call(?MODULE, poke).
  26
+poke()          -> poke(1).
  27
+poke_twice()    -> poke(2).
  28
+poke(N)         -> gen_server:call(?MODULE, {poke, N}).
20 29
 
21  
-poke_twice() ->
22  
-    gen_server:call(?MODULE, poke_twice).
  30
+prod()          -> prod(1).
  31
+prod(N)         -> gen_server:call(?MODULE, {prod, N}).
23 32
 
24  
-num_pokes() ->
25  
-    gen_server:call(?MODULE, num_pokes).
  33
+num_pokes()     -> gen_server:call(?MODULE, num_pokes).
  34
+num_prods()     -> gen_server:call(?MODULE, num_prods).
26 35
 
27 36
 
28 37
 %% gen_server callbacks
@@ -32,14 +41,17 @@ init([]) ->
32 41
 handle_call(num_pokes, _From, State = #state{ num_pokes = PokeCount }) ->
33 42
     {reply, PokeCount, State};
34 43
 
35  
-handle_call(poke_twice, _From, State) ->
36  
-    NewPokeCount = State#state.num_pokes + 2,
37  
-    NewState     = State#state{num_pokes = NewPokeCount},
38  
-    Reply        = {ok, NewPokeCount},
  44
+handle_call(num_prods, _From, State = #state{ num_prods = ProdCount }) ->
  45
+    {reply, ProdCount, State};
  46
+
  47
+handle_call({prod, N}, _From, State) ->
  48
+    NewProdCount = State#state.num_prods + N,
  49
+    NewState     = State#state{num_prods = NewProdCount},
  50
+    Reply        = {ok, NewProdCount},
39 51
     {reply, Reply, NewState};
40 52
 
41  
-handle_call(poke, _From, State) ->
42  
-    NewPokeCount = State#state.num_pokes + 1,
  53
+handle_call({poke, N}, _From, State) ->
  54
+    NewPokeCount = State#state.num_pokes + N,
43 55
     NewState     = State#state{num_pokes = NewPokeCount},
44 56
     Reply        = {ok, NewPokeCount},
45 57
     {reply, Reply, NewState}.
@@ -53,9 +65,15 @@ handle_info(_Info, State) ->
53 65
 terminate(_Reason, _State) ->
54 66
     ok.
55 67
 
56  
-code_change(OldVsn, State, Extra) ->
57  
-    error_logger:info_msg("code_change, oldvsn:~p state:~p extra:~p~n",
58  
-                          [OldVsn, State, Extra]),
59  
-    {ok, State}.
  68
+%% Upgrade from 2
  69
+code_change(_OldVsn, State, [from2to3]) ->
  70
+    error_logger:info_msg("CODE_CHANGE from 2~n"),
  71
+    {state, NumPokes} = State, %% State here is the 'old' format, with 1 field
  72
+    NewState = #state{num_pokes=NumPokes}, %% will assume default for num_prods
  73
+    {ok, NewState}.
  74
+
  75
+%% Note downgrade code_change not implemented
  76
+    
  77
+    
60 78
 
61  
-%%% Internal functions
  79
+%%% Internal functions
2  rel/reltool.config
... ...
@@ -1,6 +1,6 @@
1 1
 {sys, [
2 2
        {lib_dirs, ["../apps"]},
3  
-       {rel, "dummy", "2",
  3
+       {rel, "dummy", "3",
4 4
         [
5 5
          kernel,
6 6
          stdlib,

No commit comments for this range

Something went wrong with that request. Please try again.