Skip to content

Commit

Permalink
Update Repo files (#31)
Browse files Browse the repository at this point in the history
* Working tests with OTP 25

* Remove riak core mention, update makefile example

* Remove lager config

* Remove lager, fix riak_core commit

* Update rebar3 executable

* Set up rebar3 formatting

* Fix wrong path

* Fix wrong path

* Add missing command

* Add OTP to Job

* Apply formatting

* Remove rebar.lock

* Change rebar.config

* Pin rebar3_format

* Update rebar3 format

* Roll-back rebar3 format

* Add test-otp-version job

* Fix minor error

* Add older OTP versions

* Use supplied rebar3 instead of local rebar3

* Remove OTP 22 and below

* Add tests for old OTP versions

* Put versions into quotes

* Fix versions

* Remove version 19

* Only test OTP 22 with old versions

* Add OTP 21 to tests

* Add older rebar

* Remove old otp versions

* Remove travis CI

* Return to make test

* Break formatter check step

* Fix formatting

* Group OTP 25 specific code in tests

* Format test file

Co-authored-by: Federico Carrone <[email protected]>
  • Loading branch information
fkrause98 and unbalancedparentheses authored Jun 14, 2022
1 parent 4b77c66 commit 45245d9
Show file tree
Hide file tree
Showing 15 changed files with 388 additions and 387 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: tutorial-tests
on: [push]
jobs:
check-formatting:
runs-on: ubuntu-latest
name: Rebar3 formatting check
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: '25'
- run: ./rebar3 compile
- run: ./rebar3 format --verify
test-otp-versions:
runs-on: ubuntu-latest
name: OTP Versions Testing
strategy:
matrix:
version: ['23', '24', '25']
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.version}}
- run: make test
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Riak Core Tutorial [![Build Status](https://travis-ci.org/lambdaclass/riak_core_tutorial.svg?branch=master)](https://travis-ci.org/lambdaclass/riak_core_tutorial)

This repository contains an example riak_core application using the most
recent version of the [riak_core_ng fork](https://hex.pm/packages/riak_core_ng)
and running on Erlang/OTP 21 with rebar3.
recent version of [riak_core](https://hex.pm/packages/riak_core)
and running on Erlang/OTP 25 with rebar3.

Below is a detailed [tutorial](/#riak-core-tutorial) that explains the step-by-step process to
produce the same code base from scratch.
Expand Down Expand Up @@ -634,18 +634,19 @@ Let's add a Makefile to easily run any of the nodes:
.PHONY: dev1 dev2 dev3 clean_data
dev1:
rebar3 as dev1 release && _build/dev1/rel/rc_example/bin/rc_example
./rebar3 as dev1 release && _build/dev1/rel/rc_example/bin/rc_example
dev2:
rebar3 as dev2 release && _build/dev2/rel/rc_example/bin/rc_example
./rebar3 as dev2 release && _build/dev2/rel/rc_example/bin/rc_example
dev3:
rebar3 as dev3 release && _build/dev3/rel/rc_example/bin/rc_example
./rebar3 as dev3 release && _build/dev3/rel/rc_example/bin/rc_example
clean_data:
rm -rf _build/dev1/rel/rc_example/data* ; rm -rf _build/dev2/rel/rc_example/data* ; rm -rf _build/dev3/rel/rc_example/data*
```
Currently, the latest rebar3 release is not built with
We also include a `clean_data` target, for the cases when we want to start
with a fresh cluster (riak_core persists cluster
information between runs, so you may need to remove it when you make
Expand Down
15 changes: 3 additions & 12 deletions conf/sys.config
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
[
{riak_core,
[
{ring_state_dir, "./data/ring"},
[{riak_core,
[{ring_state_dir, "./data/ring"},
{web_port, {{web_port}}},
{handoff_port, {{handoff_port}}},
{schema_dirs, ["lib/rc_example-0.1.0/priv"]}
]},
{sasl, [{errlog_type, error}]},
{lager, [
{handlers, [
{lager_console_backend, [{level, info}]},
{lager_file_backend, [{file, "log/error.log"}, {level, error}]},
{lager_file_backend, [{file, "log/console.log"}, {level, info}]}]}
]}].
]}].
42 changes: 26 additions & 16 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{erl_opts, [debug_info]}.
{deps, [{riak_core, "3.1.0", {pkg, riak_core_ng}},
{lager, "3.5.1"}]}.

{relx, [{release, {rc_example, "0.1.0"},
[rc_example]},
{dev_mode, true},
{include_erts, false},
{extended_start_script, false},
{sys_config, "conf/sys.config"},
{vm_args, "conf/vm.args"},
{overlay, [{template, "conf/sys.config", "releases/{{default_release_version}}/sys.config"},
{template, "conf/vm.args", "releases/{{default_release_version}}/vm.args"}]}
]}.
{deps,
[{riak_core,
{git,
"https://github.com/basho/riak_core",
{ref, "f15acd3a87150431277eb754792ec24a0dc81d75"}}}]}.

{profiles, [{dev1, [{relx, [{overlay_vars, "conf/vars_dev1.config"}]}]},
{dev2, [{relx, [{overlay_vars, "conf/vars_dev2.config"}]}]},
{dev3, [{relx, [{overlay_vars, "conf/vars_dev3.config"}]}]},
{dev4, [{relx, [{overlay_vars, "conf/vars_dev4.config"}]}]}]}.
{project_plugins, [{rebar3_format, "~> 1.1.0"}]}.

{shell,
% {config, "config/sys.config"},
[{apps, [rc_example]}]}.

{relx,
[{release, {rc_example, "0.1.0"}, [rc_example]},
{dev_mode, true},
{include_erts, false},
{sys_config, "conf/sys.config"},
{vm_args, "conf/vm.args"},
{extended_start_script, false},
{overlay,
[{template, "conf/sys.config", "releases/{{release_version}}/sys.config"},
{template, "conf/vm.args", "releases/{{release_version}}/vm.args"}]}]}.

{profiles,
[{dev1, [{relx, [{overlay_vars, "conf/vars_dev1.config"}]}]},
{dev2, [{relx, [{overlay_vars, "conf/vars_dev2.config"}]}]},
{dev3, [{relx, [{overlay_vars, "conf/vars_dev3.config"}]}]}]}.
46 changes: 0 additions & 46 deletions rebar.lock

This file was deleted.

Binary file modified rebar3
Binary file not shown.
20 changes: 6 additions & 14 deletions src/rc_example.app.src
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
{application, rc_example,
{application,
rc_example,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, { rc_example_app, []}},
{applications,
[kernel,
stdlib,
lager,
cuttlefish,
riak_core
]},
{env,[]},
{mod, {rc_example_app, []}},
{applications, [kernel, stdlib, compiler, cuttlefish, riak_core]},
{env, []},
{modules, []},

{maintainers, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.
{links, []}]}.
63 changes: 29 additions & 34 deletions src/rc_example.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,57 @@

-include_lib("riak_core/include/riak_core_vnode.hrl").

-export([ping/0,
ping/1,
ring_status/0,
put/2,
get/1,
delete/1,
keys/0,
values/0,
clear/0
]).
-export([ping/0, ping/1, ring_status/0, put/2, get/1, delete/1, keys/0, values/0,
clear/0]).

%% @doc Pings a random vnode to make sure communication is functional
ping()->
ping(os:timestamp()).
ping() ->
ping(os:timestamp()).

ping(Key) ->
sync_command(Key, ping).
sync_command(Key, ping).

ring_status() ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
riak_core_ring:pretty_print(Ring, [legend]).
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
riak_core_ring:pretty_print(Ring, [legend]).

put(Key, Value) ->
sync_command(Key, {put, Key, Value}).
sync_command(Key, {put, Key, Value}).

get(Key) ->
sync_command(Key, {get, Key}).
sync_command(Key, {get, Key}).

delete(Key) ->
sync_command(Key, {delete, Key}).
sync_command(Key, {delete, Key}).

keys() ->
coverage_command(keys).
coverage_command(keys).

values() ->
coverage_command(values).
coverage_command(values).

clear() ->
{ok, []} = coverage_command(clear),
ok.
{ok, []} = coverage_command(clear),
ok.

%% internal
hash_key(Key) ->
riak_core_util:chash_key({<<"rc_example">>, term_to_binary(Key)}).
riak_core_util:chash_key({<<"rc_example">>, term_to_binary(Key)}).

sync_command(Key, Command) ->
DocIdx = hash_key(Key),
PrefList = riak_core_apl:get_apl(DocIdx, 1, rc_example),
[IndexNode] = PrefList,
riak_core_vnode_master:sync_spawn_command(IndexNode, Command, rc_example_vnode_master).
DocIdx = hash_key(Key),
PrefList = riak_core_apl:get_apl(DocIdx, 1, rc_example),
[IndexNode] = PrefList,
riak_core_vnode_master:sync_spawn_command(IndexNode, Command, rc_example_vnode_master).

coverage_command(Command) ->
Timeout = 5000,
ReqId = erlang:phash2(erlang:monotonic_time()),
{ok, _} = rc_example_coverage_fsm_sup:start_fsm([ReqId, self(), Command, Timeout]),

receive
{ReqId, Val} -> Val
end.
Timeout = 5000,
ReqId =
erlang:phash2(
erlang:monotonic_time()),
{ok, _} = rc_example_coverage_fsm_sup:start_fsm([ReqId, self(), Command, Timeout]),

receive
{ReqId, Val} ->
Val
end.
7 changes: 3 additions & 4 deletions src/rc_example_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
%% Application callbacks
-export([start/2, stop/1]).


start(_StartType, _StartArgs) ->
ok = riak_core:register([{vnode_module, rc_example_vnode}]),
ok = riak_core_node_watcher:service_up(rc_example, self()),
rc_example_sup:start_link().
ok = riak_core:register([{vnode_module, rc_example_vnode}]),
ok = riak_core_node_watcher:service_up(rc_example, self()),
rc_example_sup:start_link().

stop(_State) ->
ok.
Loading

0 comments on commit 45245d9

Please sign in to comment.