sadie 0.0.52 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +2 -1
- data/README +76 -22
- data/Rakefile +41 -1
- data/TODO +2 -31
- data/bin/sadie +17 -0
- data/bin/sadie_query_server +15 -0
- data/bin/sadie_server +27 -0
- data/bin/sadie_server.rb +23 -0
- data/doc/v2 +161 -0
- data/lib/primer.rb +201 -0
- data/lib/sadie/version.rb +1 -1
- data/lib/sadie_server.rb +59 -0
- data/lib/sadie_session.rb +194 -0
- data/lib/sadie_storage_manager.rb +60 -0
- data/lib/sadie_storage_mechanism.rb +18 -0
- data/lib/storage/memory.rb +24 -0
- data/sadie.gemspec +6 -2
- data/spec/primer.rb +167 -0
- data/spec/sadie_server.rb +39 -0
- data/spec/sadie_server_lib.rb +31 -0
- data/spec/sadie_session.rb +99 -0
- data/spec/storage_manager.rb +58 -0
- data/spec/storage_mechanisms/memory.rb +28 -0
- data/test/v2/test_installation/primers/minimal.rb +5 -0
- data/test/v2/test_installation/primers/onelevel/twolevel/test_subdir.rb +5 -0
- data/test/v2/test_installation/primers/test_after_each.rb +14 -0
- data/test/v2/test_installation/primers/test_after_key.rb +14 -0
- data/test/v2/test_installation/primers/test_before_each.rb +14 -0
- data/test/v2/test_installation/primers/test_before_key.rb +14 -0
- data/test/v2/test_installation/primers/test_expires_after_n_secs.rb +6 -0
- data/test/v2/test_installation/primers/test_expires_on_get.rb +6 -0
- data/test/v2/test_installation/primers/test_refresh.rb +10 -0
- metadata +84 -49
- data/lib/sadie/debug.rb +0 -1
- data/lib/sadie/defaults.rb +0 -14
- data/lib/sadie/primer_plugins/DatabaseConnection.plugin.rb +0 -80
- data/lib/sadie/primer_plugins/IniFile.plugin.rb +0 -23
- data/lib/sadie/primer_plugins/Resource.plugin.rb +0 -7
- data/lib/sadie/primer_plugins/SQLQueryTo2DArray.plugin.rb +0 -39
- data/lib/sadie/primer_plugins/TemplateTextFile.plugin.rb +0 -13
- data/lib/sadie.rb +0 -1315
- data/test/README +0 -9
- data/test/tc_sadie_toplevel.rb +0 -43
- data/test/tc_sadie_twodeep.rb +0 -48
- data/test/test_primers/.gitignore +0 -1
- data/test/test_primers/onedeep/multiresult.res +0 -5
- data/test/test_primers/toplevel.ini +0 -5
- data/test/test_primers/toplevel.somegroup.somekey.each +0 -15
- data/test/test_primers/toplevel_destructonget.res.rb +0 -9
- data/test/test_primers/toplevel_double.oneprime.each +0 -14
- data/test/test_primers/toplevel_double.res.rb +0 -5
- data/test/test_primers/toplevel_single.res.rb +0 -3
- data/test/test_primers/toplevel_testeach.res.rb +0 -4
- data/test/test_primers/two/deep/conf.ini +0 -2
- data/test/test_primers/two/deep/expensive.res +0 -3
- data/test/test_primers/two/deep/test.dbi.conx +0 -4
- data/test/test_primers/two/deep/test_template.txt.tmpl +0 -10
- data/test/test_primers/two/deep/testquery.test.sql2ar +0 -1
- data/test/test_primers/two/deep/testquery.test.sql2ar.each +0 -16
- data/test/test_primers/two/deep/two_results.res +0 -8
data/lib/sadie_server.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'sadie_session'
|
2
|
+
|
3
|
+
class SadieServer
|
4
|
+
|
5
|
+
attr_accessor :framework_dirpath
|
6
|
+
def initialize( params )
|
7
|
+
self.framework_dirpath = "/var/sadie"
|
8
|
+
unless params.nil?
|
9
|
+
if params.is_a? Hash
|
10
|
+
if params.has_key?( :framework_dirpath )
|
11
|
+
self.framework_dirpath = params[:framework_dirpath]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
@sadie_session = SadieSession.new( :primers_dirpath => File.join( self.framework_dirpath, 'primers' ) )
|
16
|
+
end
|
17
|
+
|
18
|
+
def get( key )
|
19
|
+
@sadie_session.get( key )
|
20
|
+
end
|
21
|
+
|
22
|
+
def set( key, value )
|
23
|
+
@sadie_session.set( key, value )
|
24
|
+
end
|
25
|
+
#
|
26
|
+
# def query
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# def set_multiple
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def get_multiple
|
33
|
+
# end
|
34
|
+
|
35
|
+
def self.proc_args( argv_param )
|
36
|
+
argv = argv_param.dup
|
37
|
+
ARGV.clear
|
38
|
+
ret = nil
|
39
|
+
|
40
|
+
unless argv.nil?
|
41
|
+
if argv.is_a? Array
|
42
|
+
unless argv.empty?
|
43
|
+
argv.each do |argstr|
|
44
|
+
puts "argstr: #{argstr}"
|
45
|
+
if argstr =~ /^\-\-([^\=]+)\=(.*)$/
|
46
|
+
ret = {} if ret.nil?
|
47
|
+
k,v = $1,$2
|
48
|
+
ret[k.gsub(/\-/,"_").to_sym] = v
|
49
|
+
else
|
50
|
+
ARGV.push argstr
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ret
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require 'sadie_storage_manager'
|
2
|
+
require 'storage/memory'
|
3
|
+
require 'primer'
|
4
|
+
require 'thread'
|
5
|
+
require 'rbtree'
|
6
|
+
|
7
|
+
class SadieSession
|
8
|
+
attr_accessor :primers_dirpath
|
9
|
+
|
10
|
+
def initialize( params )
|
11
|
+
|
12
|
+
@expiry_mutex = Mutex.new
|
13
|
+
@expire_schedule = MultiRBTree.new
|
14
|
+
@expiry_thread = Thread.new do
|
15
|
+
_expiry_loop
|
16
|
+
end
|
17
|
+
|
18
|
+
@refresh_mutex = Mutex.new
|
19
|
+
@refresh_schedule = MultiRBTree.new
|
20
|
+
@refresh_thread = Thread.new do
|
21
|
+
_refresh_loop
|
22
|
+
end
|
23
|
+
|
24
|
+
@registered_key = {}
|
25
|
+
|
26
|
+
unless params.nil?
|
27
|
+
if params.is_a? Hash
|
28
|
+
if params.has_key?( :primers_dirpath )
|
29
|
+
self.primers_dirpath = params[:primers_dirpath]
|
30
|
+
puts "initializing session with primer dirpath: #{self.primers_dirpath}"
|
31
|
+
_register_primers
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@storage_manager_thread_mutex = Mutex.new
|
37
|
+
@storage_manager = SadieStorageManager.new
|
38
|
+
@storage_manager_thread_mutex.synchronize do
|
39
|
+
@storage_manager.register_storage_mechanism :memory, SadieStorageMechanismMemory.new
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def has_key?( key )
|
44
|
+
@storage_manager_thread_mutex.synchronize do
|
45
|
+
@storage_manager.has_key?( key )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def primer_registered?( key )
|
50
|
+
@registered_key.has_key? key
|
51
|
+
end
|
52
|
+
|
53
|
+
def unset( key )
|
54
|
+
@storage_manager_thread_mutex.synchronize do
|
55
|
+
@storage_manager.unset( key )
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def set( keys, value, params=nil )
|
60
|
+
expires, mechanism = :never, :memory
|
61
|
+
unless params.nil?
|
62
|
+
if params.is_a? Hash
|
63
|
+
expires = params[:expire] if params.has_key?( :expire )
|
64
|
+
mechanism = params[:mechanism] if params.has_key?( :mechanism )
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@storage_manager_thread_mutex.synchronize do
|
68
|
+
@storage_manager.set( :keys => Array( keys ),
|
69
|
+
:value => value,
|
70
|
+
:mechanism => mechanism )
|
71
|
+
end
|
72
|
+
_manage_expiry( keys, expires ) unless expires == :never || expires == :on_get
|
73
|
+
end
|
74
|
+
|
75
|
+
def get( key )
|
76
|
+
if @storage_manager.has_key?( key )
|
77
|
+
@storage_manager.get( key )
|
78
|
+
elsif primer_registered?( key )
|
79
|
+
p = Primer.new( :session => self )
|
80
|
+
p.decorate( @registered_key[ key ] )
|
81
|
+
if p.expire == :on_get
|
82
|
+
ret = @storage_manager.get( key )
|
83
|
+
@storage_manager.unset( key )
|
84
|
+
ret
|
85
|
+
elsif ( p.refreshes? )
|
86
|
+
_manage_refresh( key, p.refresh_rate )
|
87
|
+
@storage_manager.get( key )
|
88
|
+
else
|
89
|
+
@storage_manager.get( key )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def _manage_expiry( keys, expires_seconds )
|
97
|
+
if ! expires_seconds.is_a?( Symbol ) && expires_seconds.to_i > 0
|
98
|
+
expires = expires_seconds.to_i + _current_time
|
99
|
+
unless Array(keys).empty?
|
100
|
+
Array(keys).each do |key|
|
101
|
+
@expiry_mutex.synchronize do
|
102
|
+
@expire_schedule[expires] = key
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def _manage_refresh( keys, refresh_seconds )
|
110
|
+
if ! refresh_seconds.is_a?( Symbol ) && refresh_seconds.to_i > 0
|
111
|
+
refreshes = refresh_seconds.to_i + _current_time
|
112
|
+
unless Array(keys).empty?
|
113
|
+
Array(keys).each do |key|
|
114
|
+
@refresh_mutex.synchronize do
|
115
|
+
@refresh_schedule[refreshes] = key
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def _register_primers
|
123
|
+
Dir.glob( File.join( self.primers_dirpath, "**", "*.rb" ) ).each do |primer_filepath|
|
124
|
+
p = Primer.new( :session => self )
|
125
|
+
p.mode = :registration
|
126
|
+
p.decorate( primer_filepath )
|
127
|
+
_register_keys p.keys, primer_filepath
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def _register_keys( keys=nil, filepath )
|
132
|
+
if ( ! keys.nil? ) && ( ! Array( keys ).empty? )
|
133
|
+
Array( keys ).each do |key|
|
134
|
+
@registered_key[key] = filepath
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def _expiry_loop
|
140
|
+
loop do
|
141
|
+
_expiry_pass
|
142
|
+
sleep 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def _expiry_pass
|
147
|
+
time_now_in_seconds = _current_time
|
148
|
+
@expiry_mutex.synchronize do
|
149
|
+
loop do
|
150
|
+
break if @expire_schedule.empty?
|
151
|
+
ts,key = @expire_schedule.shift
|
152
|
+
if ts < time_now_in_seconds
|
153
|
+
unset key
|
154
|
+
else
|
155
|
+
@expire_schedule[ts] = key
|
156
|
+
break
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def _refresh_loop
|
163
|
+
loop do
|
164
|
+
_refresh_pass
|
165
|
+
sleep 1
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def _refresh_pass
|
170
|
+
time_now_in_seconds = _current_time
|
171
|
+
loop do
|
172
|
+
break if @refresh_schedule.empty?
|
173
|
+
ts,key = @refresh_schedule.shift
|
174
|
+
if ts < time_now_in_seconds
|
175
|
+
_refresh key
|
176
|
+
else
|
177
|
+
@refresh_mutex.synchronize do
|
178
|
+
@refresh_schedule[ts] = key
|
179
|
+
end
|
180
|
+
break
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def _refresh( key )
|
186
|
+
p = Primer.new( :session => self )
|
187
|
+
p.decorate( @registered_key[ key ] )
|
188
|
+
_manage_refresh( key, p.refresh_rate )
|
189
|
+
end
|
190
|
+
|
191
|
+
def _current_time
|
192
|
+
Time.now.to_i
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class SadieStorageManager
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@mechanisms = {}
|
5
|
+
@known_keys = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def register_storage_mechanism( handle, mechanism )
|
9
|
+
@mechanisms[handle] = mechanism
|
10
|
+
end
|
11
|
+
|
12
|
+
def mechanism_is_registered?( mechanism_handle )
|
13
|
+
|
14
|
+
@mechanisms.has_key?( mechanism_handle )
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def has_key?( key )
|
19
|
+
@known_keys.has_key?( key )
|
20
|
+
end
|
21
|
+
|
22
|
+
def get( key )
|
23
|
+
@mechanisms[@known_keys[key]].get( key ) if has_key?( key )
|
24
|
+
end
|
25
|
+
|
26
|
+
def unset( key )
|
27
|
+
if has_key?( key )
|
28
|
+
@mechanisms[@known_keys[key]].unset( key )
|
29
|
+
@known_keys.delete key
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def set( params )
|
34
|
+
unless params.nil?
|
35
|
+
|
36
|
+
if params.is_a? Hash
|
37
|
+
|
38
|
+
if params.has_key?( :mechanism )
|
39
|
+
|
40
|
+
if mechanism_is_registered? params[:mechanism]
|
41
|
+
|
42
|
+
if params.has_key?( :keys ) && params[:keys].is_a?( Array ) &&
|
43
|
+
params.has_key?( :value )
|
44
|
+
|
45
|
+
params[:keys].each do |key|
|
46
|
+
@mechanisms[params[:mechanism]].set( key, params[:value] )
|
47
|
+
@known_keys[key] = params[:mechanism]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'sadie_storage_mechanism'
|
2
|
+
class SadieStorageMechanismMemory < SadieStorageMechanism
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@storage_hash = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def set( key, value )
|
9
|
+
@storage_hash[key] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def get( key )
|
13
|
+
@storage_hash[key] if @storage_hash.has_key?( key )
|
14
|
+
end
|
15
|
+
|
16
|
+
def unset( key )
|
17
|
+
@storage_hash.delete key
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_key?( key )
|
21
|
+
@storage_hash.has_key?( key )
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/sadie.gemspec
CHANGED
@@ -23,8 +23,12 @@ Gem::Specification.new do |s|
|
|
23
23
|
# s.add_runtime_dependency "rest-client"
|
24
24
|
|
25
25
|
#s.add_runtime_dependency "ini"
|
26
|
-
s.add_runtime_dependency "dbi"
|
26
|
+
#s.add_runtime_dependency "dbi"
|
27
27
|
#s.add_runtime_dependency "mysql2"
|
28
|
-
s.add_runtime_dependency "dbd-mysql"
|
28
|
+
#s.add_runtime_dependency "dbd-mysql"
|
29
|
+
s.add_runtime_dependency "sinatra", "~> 1.4.4"
|
30
|
+
s.add_runtime_dependency "rbtree", "~> 0.4.2"
|
31
|
+
s.add_development_dependency "rspec"
|
32
|
+
s.add_development_dependency "rack-test"
|
29
33
|
s.extra_rdoc_files = ['README', 'CHANGELOG', 'TODO']
|
30
34
|
end
|
data/spec/primer.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
|
3
|
+
require 'primer'
|
4
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
+
# require 'sadie_storage_manager'
|
6
|
+
# require 'storage_mechanisms/memory'
|
7
|
+
require 'sadie_session'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
describe Primer do
|
11
|
+
|
12
|
+
it "should default to the memory storage mechanism" do
|
13
|
+
p = Primer.new
|
14
|
+
p.storage_mechanism.should == :memory
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to successfully set using a storage manager" do
|
18
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
19
|
+
p = Primer.new( :session => session )
|
20
|
+
p.prime [ "simple.test"] do
|
21
|
+
p.assign [ "simple.test" ] do
|
22
|
+
p.set( "simple.value" )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
session.get( "simple.test" ).should == "simple.value"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not allow assignment for keys not mentioned in the prime directive" do
|
29
|
+
expect {
|
30
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
31
|
+
# storage = SadieStorageManager.new
|
32
|
+
# mech = SadieStorageMechanismMemory.new
|
33
|
+
# storage.register_storage_mechanism :memory, mech
|
34
|
+
p = Primer.new( :session => session )
|
35
|
+
p.prime [ "simple.test"] do
|
36
|
+
p.assign [ "simple.other" ]
|
37
|
+
end
|
38
|
+
}.to raise_error
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not allow set for keys not mentioned in the assign directive" do
|
43
|
+
expect {
|
44
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
45
|
+
p = Primer.new( :session => session )
|
46
|
+
p.prime [ "simple.test"] do
|
47
|
+
p.assign [ "simple.test" ] do
|
48
|
+
p.set ["simple.other"], "someval"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
}.to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be ok to use strings instead of arrays for prime" do
|
55
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
56
|
+
p = Primer.new( :session => session )
|
57
|
+
p.prime "simple.test" do
|
58
|
+
p.assign [ "simple.test" ] do
|
59
|
+
p.set "someval"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
session.get("simple.test").should == "someval"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be ok to use strings instead of arrays for assign" do
|
66
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
67
|
+
p = Primer.new( :session => session )
|
68
|
+
p.prime ["simple.test"] do
|
69
|
+
p.assign "simple.test" do
|
70
|
+
p.set "someval"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
session.get("simple.test").should == "someval"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should be ok to use strings instead of arrays for set" do
|
77
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
78
|
+
p = Primer.new( :session => session )
|
79
|
+
p.prime ["simple.test"] do
|
80
|
+
p.assign "simple.test" do
|
81
|
+
p.set "simple.test","someval"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
session.get("simple.test").should == "someval"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should successfully load a primer file using decorate method" do
|
88
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
89
|
+
p = Primer.new( :session => session )
|
90
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'minimal.rb') )
|
91
|
+
session.get( "minimal.primer" ).should == "testval"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should successfully execute before each clauses" do
|
95
|
+
|
96
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
97
|
+
p = Primer.new( :session => session )
|
98
|
+
def p.get_r
|
99
|
+
@r
|
100
|
+
end
|
101
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_before_each.rb') )
|
102
|
+
session.get( "test.var1" ).should == "val1"
|
103
|
+
session.get( "test.var2" ).should == "val2"
|
104
|
+
r= p.get_r
|
105
|
+
r.has_key?("test.var1").should be_true
|
106
|
+
r.has_key?("test.var2").should be_true
|
107
|
+
r["test.var1"].should == 1
|
108
|
+
r["test.var2"].should == 1
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should successfully execute before key clauses" do
|
112
|
+
|
113
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
114
|
+
p = Primer.new( :session => session )
|
115
|
+
def p.get_r
|
116
|
+
@r
|
117
|
+
end
|
118
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_before_key.rb') )
|
119
|
+
session.get( "test.var1" ).should == "val1"
|
120
|
+
session.get( "test.var2" ).should == "val2"
|
121
|
+
r= p.get_r
|
122
|
+
r.has_key?("test.var1").should be_true
|
123
|
+
r.has_key?("test.var2").should be_false
|
124
|
+
r["test.var1"].should == 1
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should successfully execute after each clauses" do
|
128
|
+
|
129
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
130
|
+
p = Primer.new( :session => session )
|
131
|
+
def p.get_r
|
132
|
+
@r
|
133
|
+
end
|
134
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_after_each.rb') )
|
135
|
+
session.get( "test.var1" ).should == "val1"
|
136
|
+
session.get( "test.var2" ).should == "val2"
|
137
|
+
r= p.get_r
|
138
|
+
r.has_key?("test.var1").should be_true
|
139
|
+
r.has_key?("test.var2").should be_true
|
140
|
+
r["test.var1"].should == "val1"
|
141
|
+
r["test.var2"].should == "val2"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should successfully execute after key clauses" do
|
145
|
+
|
146
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
147
|
+
p = Primer.new( :session => session )
|
148
|
+
def p.get_r
|
149
|
+
@r
|
150
|
+
end
|
151
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_after_key.rb') )
|
152
|
+
session.get( "test.var1" ).should == "val1"
|
153
|
+
session.get( "test.var2" ).should == "val2"
|
154
|
+
r= p.get_r
|
155
|
+
r.has_key?("test.var1").should be_true
|
156
|
+
r.has_key?("test.var2").should be_false
|
157
|
+
r["test.var1"].should == "val1"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should set the refresh rate" do
|
161
|
+
session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
|
162
|
+
p = Primer.new( :session => session )
|
163
|
+
p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_refresh.rb') )
|
164
|
+
p.refresh_rate.should == 2
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..')
|
3
|
+
|
4
|
+
require 'sadie_server'
|
5
|
+
|
6
|
+
class SadieServer
|
7
|
+
def self.proc_args( argv )
|
8
|
+
{ :framework_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation' ) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'bin/sadie_server'
|
13
|
+
require 'rack/test'
|
14
|
+
|
15
|
+
describe 'the sadie server app' do
|
16
|
+
|
17
|
+
include Rack::Test::Methods
|
18
|
+
|
19
|
+
def app
|
20
|
+
Sinatra::Application
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the correct value" do
|
24
|
+
get '/minimal.primer'
|
25
|
+
expect(last_response).to be_ok
|
26
|
+
expect(last_response.body).to eq('testval')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "updates via post" do
|
30
|
+
fields = {
|
31
|
+
:value => 'testval99'
|
32
|
+
}
|
33
|
+
post '/set.via.post', fields
|
34
|
+
expect(last_response).to be_ok
|
35
|
+
get '/set.via.post'
|
36
|
+
expect(last_response).to be_ok
|
37
|
+
expect(last_response.body).to eq('testval99')
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
+
require 'sadie_server'
|
3
|
+
require 'pp'
|
4
|
+
describe SadieServer do
|
5
|
+
|
6
|
+
describe '#proc_args' do
|
7
|
+
|
8
|
+
it "should accept a framework-dirpath arg" do
|
9
|
+
|
10
|
+
result = SadieServer::proc_args ["--framework-dirpath=/tmp/sadietest"]
|
11
|
+
result.should_not be_nil
|
12
|
+
result.is_a?( Hash ).should be_true
|
13
|
+
result.has_key?( :framework_dirpath ).should be_true
|
14
|
+
result[:framework_dirpath].should == '/tmp/sadietest'
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#initialize" do
|
21
|
+
|
22
|
+
it "should store the framework dirpath" do
|
23
|
+
|
24
|
+
serv = SadieServer.new( SadieServer::proc_args( ["--framework-dirpath=/tmp/sadietest"] ) )
|
25
|
+
serv.framework_dirpath.should == '/tmp/sadietest'
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|