-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathlashup_kv_SUITE.erl
109 lines (98 loc) · 3.2 KB
/
lashup_kv_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
-module(lashup_kv_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
-export([
all/0,
init_per_suite/1, end_per_suite/1,
init_per_testcase/2, end_per_testcase/2
]).
-export([
fetch_keys/1,
kv_subscribe/1,
remove_forgiving/1
]).
all() -> [
fetch_keys,
kv_subscribe,
remove_forgiving
].
init_per_suite(Config) ->
os:cmd(os:find_executable("epmd") ++ " -daemon"),
{ok, Hostname} = inet:gethostname(),
case net_kernel:start([list_to_atom("runner@" ++ Hostname), shortnames]) of
{ok, _} -> ok;
{error, {already_started, _}} -> ok
end,
Config.
end_per_suite(Config) ->
net_kernel:stop(),
Config.
init_per_testcase(_, Config) ->
application:ensure_all_started(lashup),
Config.
end_per_testcase(_, Config) ->
application:stop(lashup),
application:stop(prometheus),
Config.
fetch_keys(_Config) ->
Key1 = [a,b,c],
{ok, _} = lashup_kv:request_op(Key1, {update,
[{update,
{flag, riak_dt_lwwreg},
{assign, true, erlang:system_time(nano_seconds)}
}]
}),
Key2 = [a,b,d],
{ok, _} = lashup_kv:request_op(Key2, {update,
[{update,
{flag, riak_dt_lwwreg},
{assign, true, erlang:system_time(nano_seconds)}
}]
}),
Key3 = [x,y,z],
{ok, _} = lashup_kv:request_op(Key3, {update,
[{update,
{flag, riak_dt_lwwreg},
{assign, true, erlang:system_time(nano_seconds)}
}]
}),
Keys = lashup_kv:keys(ets:fun2ms(fun({[a, b, '_']}) -> true end)),
true = lists:member(Key1, Keys) and
lists:member(Key2, Keys) and
not lists:member(Key3, Keys),
ok.
kv_subscribe(_Config) ->
{ok, _} = lashup_kv:request_op(flag, {update,
[{update,
{color, riak_dt_lwwreg},
{assign, red, erlang:system_time(nano_seconds)}
}]
}),
{ok, Ref} = lashup_kv:subscribe(ets:fun2ms(fun({flag}) -> true end)),
receive
{lashup_kv_event, Ref, flag} ->
ok
after 5000 ->
ct:fail("Nothing received")
end,
{ok, _} = lashup_kv:request_op(flag, {update,
[{update,
{color, riak_dt_lwwreg},
{assign, blue, erlang:system_time(nano_seconds)}
}]
}),
receive
{lashup_kv_event, Ref, Key} ->
[{{color, riak_dt_lwwreg}, blue}] = lashup_kv:value(Key)
after 5000 ->
ct:fail("Nothing received")
end,
lashup_kv:unsubscribe(Ref).
remove_forgiving(_Config) ->
Key = [x, y, z],
Field = {tratataField, riak_dt_lwwreg},
{ok, _} = lashup_kv:request_op(Key,
{update, [{update, Field, {assign, true, erlang:system_time(nano_seconds)}}]}),
{ok, Map} = lashup_kv:request_op(Key, {update, [{remove, Field}]}),
{ok, Map} = lashup_kv:request_op(Key, {update, [{remove, Field}]}),
{ok, Map} = lashup_kv:request_op(Key, {update, [{remove, Field}]}).