deja-vu 0.4 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Change.log CHANGED
@@ -1,4 +1,8 @@
1
- -- Dec. 7th
1
+ -- Dec. 8th, 2009
2
+ - modified the storage model
3
+ - fixed xampl transaction
4
+
5
+ -- Dec. 7th, 2009
2
6
  - added analysis class to do basic stats on recordings
3
7
  - refactored the player to be better
4
8
  - fixed a bug in the recorder
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ begin
9
9
  s.homepage = "http://github.com/kuccello/deja-vu"
10
10
  s.authors = ['Kristan "Krispy" Uccello']
11
11
  s.files = FileList["[A-Z]*", "{lib,test,example,example-playback}/**/*"]
12
- s.version = "0.4"
12
+ s.version = "0.5"
13
13
  end
14
14
  Jeweler::GemcutterTasks.new
15
15
  rescue LoadError
@@ -1,3 +1,4 @@
1
+ require 'dirge'
1
2
  require ~'deja-vu/init'
2
3
  #require ~'rack-session-listener'
3
4
  require 'digest/sha1'
@@ -25,30 +26,30 @@ module SoldierOfCode
25
26
  end
26
27
 
27
28
  def call(env)
28
-
29
29
  if @opt[:enable_record] then
30
30
  user_identifier_before = get_user_identifier(env)
31
31
  env_before = env
32
32
  t_start = Time.new
33
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} HERE BEFORE APP CALL"
33
34
  resp = @app.call(env) # would be nice to capture all log output from the downstream as well.... TODO add log object as logger
35
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} HERE AFTER APP CALL"
34
36
  t_stop = Time.new
35
37
  user_identifier_after = get_user_identifier(env)
36
38
 
37
39
  current_request = Rack::Request.new(env)
38
40
 
39
- dejavu_recorder = nil
41
+ dejavu_recorder = Recorder.new(@opt)
40
42
  if user_identifier_before != user_identifier_after then
41
- # something changed the identifier
42
- dejavu_recorder = Recorder.new(@opt)
43
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} HERE SOMETHING CHANGED"
43
44
  dejavu_recorder.identifier_change(user_identifier_after)
44
45
  end
45
46
 
46
- dejavu_recorder = Recorder.new(@opt) unless dejavu_recorder
47
-
47
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} ABOUT TO DO THE RECORD"
48
48
  dejavu_recorder.record(env, resp, current_request, t_start, t_stop, user_identifier_after)
49
-
49
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} FINISHED THE RECORD OPERATION"
50
50
  resp
51
51
  else
52
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} HERE SKIPPED COMPLETLEY"
52
53
  @app.call(env)
53
54
  end
54
55
  end
@@ -59,7 +60,7 @@ module SoldierOfCode
59
60
  # otherwise will create a hash based on the env data available
60
61
  #
61
62
  def get_user_identifier(env) # => a string representing a specific browser client user
62
-
63
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} HERE DOING IDENTIFIER WORK"
63
64
  http_accept = env['HTTP_ACCEPT']
64
65
  http_agent = env['HTTP_USER_AGENT']
65
66
  user_ip = env['REMOTE_ADDR']
@@ -184,7 +184,7 @@ module DejaVuNS
184
184
  accessed
185
185
  index = record.get_the_index
186
186
  if(nil == index) then
187
- raise Xampl::XamplException.new("no value for the index 'id' of record defined in : " << record.pp_xml)
187
+ raise Xampl::XamplException.new("no value for the index 'pid' of record defined in : " << record.pp_xml)
188
188
  end
189
189
 
190
190
  existing = @record_child[index]
@@ -206,6 +206,7 @@ module DejaVuNS
206
206
  accessed
207
207
 
208
208
  record = nil
209
+ record = Record.lookup(index) if Xampl.persister and Xampl.persister.automatic
209
210
  record = Record.new(index) unless record
210
211
 
211
212
  yield(record) if block_given?
@@ -218,6 +219,7 @@ module DejaVuNS
218
219
  record = @record_child[index]
219
220
  return record if record
220
221
 
222
+ record = Record.lookup(index) if Xampl.persister and Xampl.persister.automatic
221
223
  record = Record.new(index) unless record
222
224
 
223
225
  yield(record) if block_given?
@@ -834,7 +836,28 @@ module DejaVuNS
834
836
  end
835
837
 
836
838
  class Record
837
- include Xampl::XamplObject
839
+ include Xampl::XamplPersistedObject
840
+
841
+ @@default_persister_format = nil
842
+
843
+ def default_persister_format
844
+ @@default_persister_format
845
+ end
846
+ def Record.default_persister_format
847
+ @@default_persister_format
848
+ end
849
+ def Record.set_default_persister_format(format)
850
+ @@default_persister_format = format
851
+ end
852
+
853
+ def Record.find_by_query
854
+ things = Xampl.find_xampl do | q |
855
+ q.add_condition('class', :equals, self.name)
856
+ yield(q)
857
+ end
858
+ end
859
+
860
+
838
861
  include Xampl::XamplWithDataContent
839
862
 
840
863
  @@tag = "record"
@@ -843,12 +866,13 @@ module DejaVuNS
843
866
  @@module_name = "DejaVuNS"
844
867
  @@safe_name = "DejaVuNS_record"
845
868
  @@attributes = [
846
- [ :@id, "id" ],
869
+ [ :@pid, "pid" ],
847
870
  [ :@stamp, "stamp" ],
848
871
  [ :@status, "status" ],
849
872
  [ :@httpmethod, "httpmethod" ],
850
873
  [ :@url, "url" ],
851
874
  [ :@request_time, "request-time" ],
875
+ [ :@scheduled_for_deletion_at, "scheduled-for-deletion-at" ],
852
876
  ]
853
877
  include DejaVuNS::HeaderAsChild
854
878
  include DejaVuNS::BodyAsChild
@@ -856,15 +880,25 @@ module DejaVuNS
856
880
  include DejaVuNS::MultipartReferenceAsChild
857
881
 
858
882
 
859
- def id
860
- accessed
861
- @id
883
+ def Record.lookup(pid)
884
+ Xampl.lookup(Record, pid)
862
885
  end
863
886
 
864
- def id=(v)
865
- accessed
866
- changed
867
- @id = v
887
+ def Record.[](pid)
888
+ Xampl.lookup(Record, pid)
889
+ end
890
+
891
+ def pid
892
+ @pid
893
+ end
894
+
895
+ def pid=(v)
896
+ accessed
897
+ # This is kind of optimistic, I think you are in trouble if you do this
898
+ Xampl.auto_uncache(self) if @pid
899
+ @pid = v
900
+ changed
901
+ Xampl.auto_cache(self) if v
868
902
  end
869
903
 
870
904
  def stamp
@@ -922,16 +956,28 @@ module DejaVuNS
922
956
  @request_time = v
923
957
  end
924
958
 
959
+ def scheduled_for_deletion_at
960
+ accessed
961
+ @scheduled_for_deletion_at
962
+ end
963
+
964
+ def scheduled_for_deletion_at=(v)
965
+ accessed
966
+ changed
967
+ @scheduled_for_deletion_at = v
968
+ end
969
+
925
970
  def initialize(index=nil)
926
- @id = index if index
971
+ @pid = index if index
927
972
  super()
928
973
 
929
- @id = nil if not defined? @id
974
+ @pid = nil if not defined? @pid
930
975
  @stamp = nil if not defined? @stamp
931
976
  @status = nil if not defined? @status
932
977
  @httpmethod = nil if not defined? @httpmethod
933
978
  @url = nil if not defined? @url
934
979
  @request_time = nil if not defined? @request_time
980
+ @scheduled_for_deletion_at = nil if not defined? @scheduled_for_deletion_at
935
981
 
936
982
  init_xampl_object
937
983
  init_data_content
@@ -947,12 +993,12 @@ module DejaVuNS
947
993
  end
948
994
 
949
995
  def clear_non_persistent_index_attributes
950
- @id = nil
951
996
  @stamp = nil
952
997
  @status = nil
953
998
  @httpmethod = nil
954
999
  @url = nil
955
1000
  @request_time = nil
1001
+ @scheduled_for_deletion_at = nil
956
1002
  end
957
1003
 
958
1004
  def append_to(other)
@@ -960,11 +1006,11 @@ module DejaVuNS
960
1006
  end
961
1007
 
962
1008
  def Record.persisted?
963
- return nil
1009
+ return :pid
964
1010
  end
965
1011
 
966
1012
  def persisted?
967
- return nil
1013
+ return :pid
968
1014
  end
969
1015
 
970
1016
  def Record.tag
@@ -1012,15 +1058,15 @@ module DejaVuNS
1012
1058
  end
1013
1059
 
1014
1060
  def indexed_by
1015
- :id
1061
+ :pid
1016
1062
  end
1017
1063
 
1018
1064
  def get_the_index
1019
- @id
1065
+ @pid
1020
1066
  end
1021
1067
 
1022
1068
  def set_the_index(index)
1023
- @id = index
1069
+ @pid = index
1024
1070
  end
1025
1071
 
1026
1072
  def substitute_in_visit(visitor)
@@ -6,7 +6,7 @@
6
6
  agent=""
7
7
  ip="">
8
8
 
9
- <record id=""
9
+ <record pid=""
10
10
  stamp=""
11
11
  status=""
12
12
  httpmethod=""
@@ -14,6 +14,8 @@ module SoldierOfCode
14
14
  def initialize(opt)
15
15
  @identifier = opt['cookie_name']
16
16
  @opt = opt
17
+
18
+ @foo = Time.new.to_i
17
19
  end
18
20
 
19
21
  def export(to_file_named)
@@ -30,27 +32,43 @@ module SoldierOfCode
30
32
 
31
33
  # 1. try to locate the recording
32
34
  recording = nil
35
+
36
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
37
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} INSIDE RECORD - STARTING TXN"
38
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
39
+
33
40
  DejaVuNS.transaction do
41
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} JUST INSIDE"
34
42
  recording = DejaVuNS::Recording.find_by_identifier(@identifier)
35
-
36
- # puts "#{__FILE__}:#{__LINE__} #{__method__} #{recording.class.name}"
43
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} RECORDING FOUND: #{recording.pid}"
44
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.class.name}"
37
45
  # 1.b if not found then create a new one
38
46
  unless recording
47
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
39
48
  recording = DejaVuNS.root.new_recording(DejaVuNS.pid_from_string(@identifier||identifier))
40
49
  recording.cookie = req.cookies[@identifier||identifier]
41
50
  recording.stamp = Time.new.to_i
42
51
  recording.agent = env['HTTP_USER_AGENT']
43
52
  recording.ip = env['REMOTE_ADDR']
53
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
44
54
  end
45
55
 
46
56
  # 2. create a new record
47
- # puts "#{__FILE__}:#{__LINE__} #{__method__} #{recording.class.name}"
57
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.class.name}"
58
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
48
59
  record = recording.new_record("#{Time.new.to_i}")
60
+ #puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
49
61
  record.stamp = "#{Time.new.to_i}"
62
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
63
+
50
64
  record.status = "#{resp[0]}"
65
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
51
66
  record.httpmethod = env['REQUEST_METHOD']
67
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
52
68
  record.url = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}"
69
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
53
70
  record.request_time = ("#{end_time.to_i}.#{end_time.usec}".to_f - "#{start_time.to_i}.#{start_time.usec}".to_f).to_s
71
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
54
72
 
55
73
  # 3. add the body etc elements
56
74
  resp[1].each do |k, v|
@@ -58,33 +76,56 @@ module SoldierOfCode
58
76
  h.name = k
59
77
  h.value = v
60
78
  end
79
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
61
80
 
62
81
  record.new_body().content = "<![CDATA[#{resp[2]}]]>"
82
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
63
83
 
64
84
  if req.post? && env['CONTENT_TYPE'] =~ %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n
65
85
  # its multipart
66
86
  # <multipart-reference name="" file-path=""/>
67
87
  # can I grab it off the env object?
68
- puts "#{__FILE__}:#{__LINE__} #{__method__} NOT IMPLEMENTED - MULTIPART"
88
+ puts "#{__FILE__}:#{__LINE__} #{Thread.current} NOT IMPLEMENTED - MULTIPART"
69
89
  else
90
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
70
91
  # safe param recording
71
92
  req.params.each do |k,v|
72
93
  p = record.new_param()
73
94
  p.name = k
74
95
  p.value = v
75
96
  end
97
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} "
76
98
 
77
99
  end
100
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} ABOUT TO PRINT XML"
101
+ STDOUT.flush
102
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.pp_xml}"
78
103
  end
79
104
 
105
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
106
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
107
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
108
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
109
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
110
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} DONE TXN"
111
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
112
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
113
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
114
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
115
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
116
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
117
+
80
118
  end
81
119
 
82
120
  def identifier_change(new_identifier)
83
121
  DejaVuNS.transaction do
122
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} IDENTIFIER CHANGE"
84
123
  recording = DejaVuNS::Recording.find_by_identifier(@identifier)
85
124
  if recording
125
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.current} IDENTIFIER CHANGE HERE"
86
126
  @identifier = new_identifier
87
127
  recording.cookie = new_identifier
128
+ # puts "#{__FILE__}:#{__LINE__} #{Thread.currentta} IDENTIFIER CHANGE HERE #{recording.cookie}"
88
129
  end
89
130
  end
90
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deja-vu
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.4"
4
+ version: "0.5"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kristan "Krispy" Uccello