Permalink
Browse files

More changes to new interface format

  • Loading branch information...
1 parent 1931517 commit dc45fff2e99bd0d7c49c191fcc59529211c02350 Gianfranco committed Jul 2, 2011
Showing with 69 additions and 47 deletions.
  1. +43 −39 src/frame_axiom.erl
  2. +26 −8 test/frame_axiom_tests.erl
View
@@ -28,9 +28,6 @@
-export([diff/2,
diff/3]).
-snapshot(SnapShot) when SnapShot == node;
- SnapShot == named_process ->
- snapshot(ets:new(snapshot,[private]),SnapShot);
snapshot(SnapShots) when is_list(SnapShots) ->
lists:foldl(fun(SnapShot,Ets) -> snapshot(Ets,SnapShot)
end,ets:new(snapshot,[private]),SnapShots).
@@ -58,22 +55,17 @@ snapshot(Ets,{port,all}) ->
snapshot(Ets,{port,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,port,Option)
end,Ets,Options);
+snapshot(Ets,{dir,{all,Path}}) ->
+ snapshot(Ets,{dir,[{X,Path}||X<-all(dir)]});
snapshot(Ets,{dir,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,dir,Option)
end,Ets,Options);
-
-snapshot(Ets,ets) ->
- Existing = ets:all(),
- ets:insert(Ets,{ets,Existing}),
- Ets;
-snapshot(Ets,{dir,Path}) ->
- Structure = collect(false,Path),
- ets:insert(Ets,{{dir,Path},Structure}),
- Ets;
-snapshot(Ets,node) ->
- Current = nodes(),
- ets:insert(Ets,{node,Current}),
- Ets.
+snapshot(Ets,{node,all}) ->
+ snapshot(Ets,{node,all(node)});
+snapshot(Ets,{node,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,node,Option)
+ end,Ets,Options).
+
snapshot(Ets,process,creation) ->
Pids = erlang:processes(),
@@ -146,7 +138,16 @@ snapshot(Ets,dir,{deletion,Path}) ->
snapshot(Ets,dir,{content_changes,Path}) ->
Current = collect(true,Path),
ets:insert(Ets,{{content_changes,Path},Current}),
+ Ets;
+snapshot(Ets,node,connection) ->
+ Current = nodes(),
+ ets:insert(Ets,{{node,connection},Current}),
+ Ets;
+snapshot(Ets,node,disconnection) ->
+ Current = nodes(),
+ ets:insert(Ets,{{node,disconnection},Current}),
Ets.
+
diff(Ets,[X]) ->
diff(Ets,X);
@@ -174,25 +175,16 @@ diff(Ets,{port,all}) ->
diff(Ets,{port,Options}) when is_list(Options) ->
lists:foldl(fun(Option,Res) -> Res++diff(Ets,port,Option)
end,[],Options);
+diff(Ets,{dir,{all,Path}}) ->
+ diff(Ets,{dir,[{X,Path}||X<-all(dir)]});
diff(Ets,{dir,Options}) when is_list(Options) ->
lists:foldl(fun(Option,Res) -> Res++diff(Ets,dir,Option)
end,[],Options);
-
-diff(Ets,ets) ->
- Current = ets:all(),
- [{ets,Recorded}] = ets:lookup(Ets,ets),
- {Created,Deleted} = split(created,deleted,Current,Recorded),
- Created++Deleted;
-diff(Ets,{dir,Path}) ->
- Current = collect(false,Path),
- [{{dir,Path},Recorded}] = ets:lookup(Ets,{dir,Path}),
- {Created,Deleted} = split(created,deleted,Current,Recorded),
- Created++Deleted;
-diff(Ets,node) ->
- Current = nodes(),
- [{node,Recorded}] = ets:lookup(Ets,node),
- {Connected,Disconnected} = split(connected,disconnected,Current,Recorded),
- Connected++Disconnected.
+diff(Ets,{node,all}) ->
+ diff(Ets,{node,all(node)});
+diff(Ets,{node,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,Res) -> Res++diff(Ets,node,Option)
+ end,[],Options).
diff(Ets,process,creation) ->
CurrentPids = erlang:processes(),
@@ -303,7 +295,18 @@ diff(Ets,dir,{content_changes,Path}) ->
Current = collect(true,Path),
Key = {content_changes,Path},
[{Key,Recorded}] = ets:lookup(Ets,Key),
- contents_changed(Recorded,Current).
+ contents_changed(Recorded,Current);
+diff(Ets,node,connection) ->
+ Current = nodes(),
+ Key = {node,connection},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{connected,N}||N<-Current,not lists:member(N,Recorded)];
+diff(Ets,node,disconnection) ->
+ Current = nodes(),
+ Key = {node,disconnection},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{disconnected,N}||N<-Recorded,not lists:member(N,Current)].
+
%% Helpers section
@@ -316,7 +319,13 @@ all(application) ->
all(ets) ->
[creation,deletion];
all(port) ->
- [opened,closed].
+ [opened,closed];
+all(node) ->
+ [connection,disconnection];
+all(dir) ->
+ [creation,deletion,content_changes].
+
+
@@ -341,11 +350,6 @@ collect(ExactP,Path) ->
end
end.
-
-split(KeyA,KeyB,As,Bs) ->
- {[{KeyA,A}||A<-As,not lists:member(A,Bs)],
- [{KeyB,B}||B<-Bs,not lists:member(B,As)]}.
-
named_processes() ->
Procs = [{P,erlang:process_info(P,registered_name)}||P<-erlang:processes()],
lists:foldl(fun({_,{registered_name,N}},Acc) -> Acc++[N];
View
@@ -89,6 +89,7 @@ named_process_replaced_diff_test() ->
synchronoulsy_kill_process(Pid2).
all_no_change_diff_test() ->
+ timer:sleep(300), %% Let the Eunit processes settle in peace
Options = all,
Ref = frame_axiom:snapshot([{process,Options}]),
?assertEqual([],frame_axiom:diff(Ref,[{process,Options}])).
@@ -302,22 +303,41 @@ file_no_change_all_diff_test() ->
node_connected_diff_test() ->
ensure_empd(),
net_kernel:start([box_box,shortnames]),
- Ref = frame_axiom:snapshot(node),
+ Options = [connection],
+ Ref = frame_axiom:snapshot([{node,Options}]),
{ok,Node} = slave:start(list_to_atom(inet_db:gethostname()),'slave'),
- ?assertEqual([{connected,Node}],frame_axiom:diff(Ref,node)),
+ ?assertEqual([{connected,Node}],frame_axiom:diff(Ref,[{node,Options}])),
slave:stop(Node),
net_kernel:stop().
node_disconnected_diff_test() ->
ensure_empd(),
net_kernel:start([box_box,shortnames]),
+ Options = [disconnection],
{ok,Node} = slave:start(list_to_atom(inet_db:gethostname()),'slave'),
- Ref = frame_axiom:snapshot(node),
+ Ref = frame_axiom:snapshot([{node,Options}]),
slave:stop(Node),
- ?assertEqual([{disconnected,Node}],frame_axiom:diff(Ref,node)),
+ ?assertEqual([{disconnected,Node}],frame_axiom:diff(Ref,[{node,Options}])),
net_kernel:stop().
+node_no_diff_all_test() ->
+ Options = all,
+ Ref = frame_axiom:snapshot([{node,Options}]),
+ ?assertEqual([],frame_axiom:diff(Ref,[{node,Options}])).
+node_all_diff_test() ->
+ ensure_empd(),
+ net_kernel:start([box_box,shortnames]),
+ Options = all,
+ {ok,Node1} = slave:start(list_to_atom(inet_db:gethostname()),'slave_one'),
+ Ref = frame_axiom:snapshot([{node,Options}]),
+ slave:stop(Node1),
+ {ok,Node2} = slave:start(list_to_atom(inet_db:gethostname()),'slave_two'),
+ ?assertEqual([{connected,Node2},
+ {disconnected,Node1}],frame_axiom:diff(Ref,[{node,Options}])),
+ slave:stop(Node2),
+ net_kernel:stop().
+
%% multiple type snapshot
%% ---------------------------------------------------------
multiple_type_creation_test() ->
@@ -404,16 +424,14 @@ second_snapshot_call_test() ->
{application,A_Options}])),
application:stop(snmp).
-
successive_snapshots_of_same_resets_test() ->
E_Options = all,
Ref = frame_axiom:snapshot([{ets,E_Options}]),
Ets = ets:new(a,[]),
- frame_axiom:snapshot(Ref,ets),
- ?assertEqual([],frame_axiom:diff(Ref,ets)),
+ frame_axiom:snapshot(Ref,[{ets,E_Options}]),
+ ?assertEqual([],frame_axiom:diff(Ref,[{ets,E_Options}])),
ets:delete(Ets).
-
%% helpers
%% -----------------------------------------------------------------------------
synchronoulsy_start_named(Name) ->

0 comments on commit dc45fff

Please sign in to comment.