sadie 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 059a448fff43ba5db055b31d3d3250c8f419c46e
4
- data.tar.gz: 30b749609ac0075fe987fa0224c55110d1db2b61
3
+ metadata.gz: 3d35237ce7365435d796e102a1e8d8e2455d9363
4
+ data.tar.gz: 03e110b3da7e3ab6d6ad0445e3a7c6ce357fdb55
5
5
  SHA512:
6
- metadata.gz: 946d2e414ea05b04e889f773d7e26b7cae6bce643fc2c54ebf190a613e5cdb886a0856f7a3d4fe249bb3a834f39d64cf716d8246c869ebfb4b19da171a5525eb
7
- data.tar.gz: 9cfb3f414cfd401f199d704e0127de3d830b6152c0909c2f5da803bdc9a6fd2c030201f5be71b67baf12c6f91344814ee8dbe4b2d93618ac1d711056468d70a4
6
+ metadata.gz: 6f148d1da7eb8101b19d167ffb72fa7b1b0918093254fe62eaea3c915322b8658646150bbd89239a6ad31e29d73569977dbd9a4d5a05716f4eb2b351a343e6a6
7
+ data.tar.gz: 8e849601b5ea45613827de33250b67f31cc980aed5d306f6b051bc9438416b9f5a48f0f8f57d6795c53a48f7e11604308a8ddcbc55b8dd39fd2e0d0fc6d69b02
data/CHANGELOG CHANGED
@@ -25,4 +25,5 @@
25
25
  [0.0.50] fixed isset? bug (was only working for non-expensive keys)
26
26
  [0.0.51] eacher bugfix. now correctly handles specific keys.
27
27
  [0.0.52] code cleanup
28
- [0.1.01] ** ground-up rewrite, ignore everything before this line if you're not a historian **
28
+ [0.1.01] ** ground-up rewrite, ignore everything before this line if you're not a historian **
29
+ [0.1.8] new version now at capability pairing with old version.
data/Rakefile CHANGED
@@ -13,16 +13,27 @@ end
13
13
 
14
14
  namespace :spec do
15
15
 
16
+ desc "run all spec tests"
17
+ task :all => [ 'spec:sadie_server_lib', 'spec:storage_mechanism:memory',
18
+ 'spec:storage_mechanism:memory', 'spec:primer', 'spec:storage_manager',
19
+ 'spec:session', 'spec:server' ]do
20
+ a = 1 # a do nothing statement
21
+ end
22
+
16
23
  desc "test sadie server library"
17
24
  task :sadie_server_lib do
18
25
  system "rspec spec/sadie_server_lib.rb"
19
26
  end
20
27
 
21
28
  namespace :storage_mechanism do
22
- desc "test the memory based storage mechanism"
29
+ desc "test the memory-based storage mechanism"
23
30
  task :memory do
24
31
  system "rspec spec/storage_mechanisms/memory.rb"
25
32
  end
33
+ desc "test the file-based storage mechanism"
34
+ task :file do
35
+ system "rspec spec/storage_mechanisms/file.rb"
36
+ end
26
37
  end
27
38
 
28
39
  desc "test primer"
@@ -158,4 +158,16 @@ It should be possible to choose the method of storage for an item
158
158
  end
159
159
  end
160
160
 
161
-
161
+ It should also be possible to set the default method of storage
162
+
163
+ expire and refresh should accept the same triggers, which should be pluggable and should include, by default,
164
+
165
+ * file changes
166
+ * database table changes
167
+ * git repository updates
168
+
169
+ it should be possible to incorporate tests into the framework
170
+
171
+ it should be possible to regularly run tests and make the output available as sadie data
172
+
173
+ Right now, there's a refresh thread, an expiry thread, and the main thread, which essentially serves the get and set methods. The set and unset methods are protected by the @storage_manager_thread_mutex such that the set and unset can never run at the same time and, similarly, only a single set or unset can be in operation at the same time. And this is good. But the next iteration will target a distributed deployment of cooperating sadie instances which share a redis server (or cluster) and a filesystem (possibly distributed via nfs or something similar) or an s3 bucket. So, at this point, a simple mutex isn't really going to cut it. I've found a redis-mutex gem that will be of some assistance. But really what's needed is an abstraction on the locking mechanism...ideally even configurable to the point where I can sub in another in an initializer file...one that makes sense locally and in a distributed context.
@@ -0,0 +1,7 @@
1
+ ===ActiveRecord/ActiveModel
2
+
3
+ =Updating internal models based on git repo
4
+ A great example would be to update activerecord and/or activemodel data representations based on changes in a git repo. This could, in turn, fire off a series of tests that could 1) accept the changes and notify or 2) reject the changes, revert to earlier version and notify
5
+
6
+ =Updating ActiveRecord database using internal models
7
+ It would be handy to show how Sadie could augment a Rails site by using ActiveRecord models to update the database on which the Rails site depends. Data mining would be an appropriate task to illustrate.
data/lib/primer.rb CHANGED
@@ -13,6 +13,9 @@ class Primer
13
13
  if params.has_key?( :session )
14
14
  self.session = params[:session]
15
15
  end
16
+ if params.has_key?( :default_storage_mechanism )
17
+ self.storage_mechanism = params[:default_storage_mechanism]
18
+ end
16
19
  end
17
20
  end
18
21
  end
data/lib/sadie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Sadie
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/sadie_server.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'sadie_session'
2
+ require 'yaml'
3
+ require 'pp'
2
4
 
3
5
  class SadieServer
4
6
 
5
- attr_accessor :framework_dirpath
6
- def initialize( params )
7
+ attr_accessor :framework_dirpath, :default_storage_mechanism
8
+ def initialize( params=nil )
7
9
  self.framework_dirpath = "/var/sadie"
10
+ self.default_storage_mechanism = :memory
8
11
  unless params.nil?
9
12
  if params.is_a? Hash
10
13
  if params.has_key?( :framework_dirpath )
@@ -12,7 +15,25 @@ class SadieServer
12
15
  end
13
16
  end
14
17
  end
15
- @sadie_session = SadieSession.new( :primers_dirpath => File.join( self.framework_dirpath, 'primers' ) )
18
+
19
+ sess_params = {
20
+ :primers_dirpath => File.join( self.framework_dirpath, 'primers' )
21
+ }
22
+ if _config_hash.is_a?( Hash ) &&
23
+ _config_hash.has_key?( 'storage' ) &&
24
+ _config_hash['storage'].is_a?( Hash )
25
+ if _config_hash['storage'].has_key?( 'default_storage_mechanism' )
26
+ sess_params[:default_storage_mechanism] = _config_hash['storage']['default_storage_mechanism']
27
+ end
28
+ if _config_hash['storage'].has_key?( 'file' ) &&
29
+ _config_hash['storage']['file'].is_a?( Hash ) &&
30
+ _config_hash['storage']['file'].has_key?( 'key_storage_dirpath' )
31
+ sess_params[:file_storage_mechanism_dirpath] = _config_hash['storage']['file']['key_storage_dirpath']
32
+ end
33
+
34
+ end
35
+ puts "sess_params: #{sess_params.pretty_inspect}"
36
+ @sadie_session = SadieSession.new( sess_params )
16
37
  end
17
38
 
18
39
  def get( key )
@@ -32,7 +53,25 @@ class SadieServer
32
53
  # def get_multiple
33
54
  # end
34
55
 
35
- def self.proc_args( argv_param )
56
+ def _config_hash
57
+
58
+ if @config_hash.nil?
59
+ @config_hash = YAML.load_file(File.join(self.framework_dirpath,'config','sadie.yml'))
60
+
61
+ if @config_hash.is_a?( Hash )
62
+ if ( @config_hash.has_key?( 'storage' ) ) &&
63
+ ( @config_hash['storage'].is_a?( Hash ) ) &&
64
+ ( @config_hash['storage'].has_key?( 'default_storage_mechanism' ) )
65
+ @config_hash['storage']['default_storage_mechanism'] = @config_hash['storage']['default_storage_mechanism'].to_sym
66
+ end
67
+ end
68
+
69
+ end
70
+ @config_hash
71
+
72
+ end
73
+
74
+ def self.proc_args( argv_param=nil )
36
75
  argv = argv_param.dup
37
76
  ARGV.clear
38
77
  ret = nil
data/lib/sadie_session.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'sadie_storage_manager'
2
2
  require 'storage/memory'
3
+ require 'storage/file'
3
4
  require 'primer'
4
5
  require 'thread'
5
6
  require 'rbtree'
@@ -22,14 +23,25 @@ class SadieSession
22
23
  end
23
24
 
24
25
  @registered_key = {}
25
-
26
+ @default_storage_mechanism = :memory
27
+ @file_storage_mechanism_dirpath = nil
26
28
  unless params.nil?
27
29
  if params.is_a? Hash
30
+
28
31
  if params.has_key?( :primers_dirpath )
29
32
  self.primers_dirpath = params[:primers_dirpath]
30
33
  puts "initializing session with primer dirpath: #{self.primers_dirpath}"
31
34
  _register_primers
32
35
  end
36
+
37
+ if params.has_key?( :default_storage_mechanism )
38
+ @default_storage_mechanism = params[:default_storage_mechanism]
39
+ end
40
+
41
+ if params.has_key?( :file_storage_mechanism_dirpath )
42
+ @file_storage_mechanism_dirpath = params[:file_storage_mechanism_dirpath]
43
+ end
44
+
33
45
  end
34
46
  end
35
47
 
@@ -37,6 +49,7 @@ class SadieSession
37
49
  @storage_manager = SadieStorageManager.new
38
50
  @storage_manager_thread_mutex.synchronize do
39
51
  @storage_manager.register_storage_mechanism :memory, SadieStorageMechanismMemory.new
52
+ @storage_manager.register_storage_mechanism :file, SadieStorageMechanismFile.new(:key_storage_dirpath => @file_storage_mechanism_dirpath)
40
53
  end
41
54
  end
42
55
 
@@ -57,7 +70,7 @@ class SadieSession
57
70
  end
58
71
 
59
72
  def set( keys, value, params=nil )
60
- expires, mechanism = :never, :memory
73
+ expires, mechanism = :never, @default_storage_mechanism
61
74
  unless params.nil?
62
75
  if params.is_a? Hash
63
76
  expires = params[:expire] if params.has_key?( :expire )
@@ -121,7 +134,8 @@ class SadieSession
121
134
 
122
135
  def _register_primers
123
136
  Dir.glob( File.join( self.primers_dirpath, "**", "*.rb" ) ).each do |primer_filepath|
124
- p = Primer.new( :session => self )
137
+ p = Primer.new( :session => self,
138
+ :default_storage_mechanism => @default_storage_mechanism )
125
139
  p.mode = :registration
126
140
  p.decorate( primer_filepath )
127
141
  _register_keys p.keys, primer_filepath
@@ -2,7 +2,6 @@ class SadieStorageManager
2
2
 
3
3
  def initialize
4
4
  @mechanisms = {}
5
- @known_keys = {}
6
5
  end
7
6
 
8
7
  def register_storage_mechanism( handle, mechanism )
@@ -10,23 +9,35 @@ class SadieStorageManager
10
9
  end
11
10
 
12
11
  def mechanism_is_registered?( mechanism_handle )
13
-
14
12
  @mechanisms.has_key?( mechanism_handle )
15
-
13
+ end
14
+
15
+ def registered_mechanisms
16
+ @mechanisms.keys
17
+ end
18
+
19
+ def where_key?( key )
20
+ ret = nil
21
+ registered_mechanisms.each do |mech|
22
+ if @mechanisms[mech].has_key?( key )
23
+ ret = mech
24
+ break
25
+ end
26
+ end
27
+ ret
16
28
  end
17
29
 
18
30
  def has_key?( key )
19
- @known_keys.has_key?( key )
31
+ ( ! where_key?( key ).nil? )
20
32
  end
21
33
 
22
34
  def get( key )
23
- @mechanisms[@known_keys[key]].get( key ) if has_key?( key )
35
+ @mechanisms[where_key?( key )].get( key ) if has_key?( key )
24
36
  end
25
37
 
26
38
  def unset( key )
27
39
  if has_key?( key )
28
- @mechanisms[@known_keys[key]].unset( key )
29
- @known_keys.delete key
40
+ @mechanisms[where_key?( key )].unset( key )
30
41
  end
31
42
  end
32
43
 
@@ -44,16 +55,11 @@ class SadieStorageManager
44
55
 
45
56
  params[:keys].each do |key|
46
57
  @mechanisms[params[:mechanism]].set( key, params[:value] )
47
- @known_keys[key] = params[:mechanism]
48
58
  end
49
59
  end
50
-
51
60
  end
52
-
53
61
  end
54
-
55
62
  end
56
-
57
63
  end
58
64
  end
59
65
 
@@ -0,0 +1,50 @@
1
+ require 'sadie_storage_mechanism'
2
+ class SadieStorageMechanismFile < SadieStorageMechanism
3
+ attr_accessor :key_storage_dirpath
4
+
5
+ def initialize( params=nil )
6
+ self.key_storage_dirpath = "/tmp/sadie-key-storage"
7
+ unless params.nil?
8
+ if params.is_a?( Hash )
9
+ if params.has_key?( :key_storage_dirpath ) && ! params[:key_storage_dirpath].nil?
10
+ self.key_storage_dirpath = params[:key_storage_dirpath]
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def set( key, value )
17
+ _validate_keystorage_directory
18
+ File.open(_keyvalue_filepath(key), 'wb') { |file| file.write(value) }
19
+ end
20
+
21
+ def get( key )
22
+ _validate_keystorage_directory
23
+ value = File.open(_keyvalue_filepath(key), 'rb') { |f| f.read }
24
+ value
25
+ end
26
+
27
+ def unset( key )
28
+ _validate_keystorage_directory
29
+ File.delete(_keyvalue_filepath(key))
30
+ end
31
+
32
+ def has_key?( key )
33
+ _validate_keystorage_directory
34
+ File.exists?(_keyvalue_filepath(key))
35
+ end
36
+
37
+ private
38
+
39
+ def _validate_keystorage_directory
40
+ raise "Key storage directory (#{self.key_storage_dirpath}) does not exist" unless _keystorage_directory_exists?
41
+ end
42
+
43
+ def _keyvalue_filepath(key)
44
+ File.join(self.key_storage_dirpath,key)
45
+ end
46
+
47
+ def _keystorage_directory_exists?
48
+ Dir.exists?( self.key_storage_dirpath )
49
+ end
50
+ end
data/spec/primer.rb CHANGED
@@ -9,29 +9,40 @@ require 'pp'
9
9
 
10
10
  describe Primer do
11
11
 
12
+ before :each do
13
+ system 'install -d /tmp/sadie-test-keystor'
14
+ @session = SadieSession.new(
15
+ :primers_dirpath =>
16
+ File.join(
17
+ File.dirname( __FILE__ ), '..','test','v2',
18
+ 'test_installation','primers'
19
+ ),
20
+ :file_storage_mechanism_dirpath => '/tmp/sadie-test-keystor'
21
+ )
22
+ end
23
+
24
+ after :each do
25
+ system 'rm -rf /tmp/sadie-test-keystor'
26
+ end
27
+
12
28
  it "should default to the memory storage mechanism" do
13
29
  p = Primer.new
14
30
  p.storage_mechanism.should == :memory
15
31
  end
16
32
 
17
33
  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 )
34
+ p = Primer.new( :session => @session )
20
35
  p.prime [ "simple.test"] do
21
36
  p.assign [ "simple.test" ] do
22
37
  p.set( "simple.value" )
23
38
  end
24
39
  end
25
- session.get( "simple.test" ).should == "simple.value"
40
+ @session.get( "simple.test" ).should == "simple.value"
26
41
  end
27
42
 
28
43
  it "should not allow assignment for keys not mentioned in the prime directive" do
29
44
  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 )
45
+ p = Primer.new( :session => @session )
35
46
  p.prime [ "simple.test"] do
36
47
  p.assign [ "simple.other" ]
37
48
  end
@@ -41,8 +52,7 @@ describe Primer do
41
52
 
42
53
  it "should not allow set for keys not mentioned in the assign directive" do
43
54
  expect {
44
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
45
- p = Primer.new( :session => session )
55
+ p = Primer.new( :session => @session )
46
56
  p.prime [ "simple.test"] do
47
57
  p.assign [ "simple.test" ] do
48
58
  p.set ["simple.other"], "someval"
@@ -52,55 +62,50 @@ describe Primer do
52
62
  end
53
63
 
54
64
  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 )
65
+ p = Primer.new( :session => @session )
57
66
  p.prime "simple.test" do
58
67
  p.assign [ "simple.test" ] do
59
68
  p.set "someval"
60
69
  end
61
70
  end
62
- session.get("simple.test").should == "someval"
71
+ @session.get("simple.test").should == "someval"
63
72
  end
64
73
 
65
74
  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 )
75
+ p = Primer.new( :session => @session )
68
76
  p.prime ["simple.test"] do
69
77
  p.assign "simple.test" do
70
78
  p.set "someval"
71
79
  end
72
80
  end
73
- session.get("simple.test").should == "someval"
81
+ @session.get("simple.test").should == "someval"
74
82
  end
75
83
 
76
84
  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 )
85
+ p = Primer.new( :session => @session )
79
86
  p.prime ["simple.test"] do
80
87
  p.assign "simple.test" do
81
88
  p.set "simple.test","someval"
82
89
  end
83
90
  end
84
- session.get("simple.test").should == "someval"
91
+ @session.get("simple.test").should == "someval"
85
92
  end
86
93
 
87
94
  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 )
95
+ p = Primer.new( :session => @session )
90
96
  p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'minimal.rb') )
91
- session.get( "minimal.primer" ).should == "testval"
97
+ @session.get( "minimal.primer" ).should == "testval"
92
98
  end
93
99
 
94
100
  it "should successfully execute before each clauses" do
95
101
 
96
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
97
- p = Primer.new( :session => session )
102
+ p = Primer.new( :session => @session )
98
103
  def p.get_r
99
104
  @r
100
105
  end
101
106
  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"
107
+ @session.get( "test.var1" ).should == "val1"
108
+ @session.get( "test.var2" ).should == "val2"
104
109
  r= p.get_r
105
110
  r.has_key?("test.var1").should be_true
106
111
  r.has_key?("test.var2").should be_true
@@ -110,14 +115,13 @@ describe Primer do
110
115
 
111
116
  it "should successfully execute before key clauses" do
112
117
 
113
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
114
- p = Primer.new( :session => session )
118
+ p = Primer.new( :session => @session )
115
119
  def p.get_r
116
120
  @r
117
121
  end
118
122
  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"
123
+ @session.get( "test.var1" ).should == "val1"
124
+ @session.get( "test.var2" ).should == "val2"
121
125
  r= p.get_r
122
126
  r.has_key?("test.var1").should be_true
123
127
  r.has_key?("test.var2").should be_false
@@ -126,14 +130,13 @@ describe Primer do
126
130
 
127
131
  it "should successfully execute after each clauses" do
128
132
 
129
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
130
- p = Primer.new( :session => session )
133
+ p = Primer.new( :session => @session )
131
134
  def p.get_r
132
135
  @r
133
136
  end
134
137
  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"
138
+ @session.get( "test.var1" ).should == "val1"
139
+ @session.get( "test.var2" ).should == "val2"
137
140
  r= p.get_r
138
141
  r.has_key?("test.var1").should be_true
139
142
  r.has_key?("test.var2").should be_true
@@ -143,14 +146,13 @@ describe Primer do
143
146
 
144
147
  it "should successfully execute after key clauses" do
145
148
 
146
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
147
- p = Primer.new( :session => session )
149
+ p = Primer.new( :session => @session )
148
150
  def p.get_r
149
151
  @r
150
152
  end
151
153
  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
+ @session.get( "test.var1" ).should == "val1"
155
+ @session.get( "test.var2" ).should == "val2"
154
156
  r= p.get_r
155
157
  r.has_key?("test.var1").should be_true
156
158
  r.has_key?("test.var2").should be_false
@@ -158,10 +160,22 @@ describe Primer do
158
160
  end
159
161
 
160
162
  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 = Primer.new( :session => @session )
163
164
  p.decorate( File.join(File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation', 'primers', 'test_refresh.rb') )
164
- p.refresh_rate.should == 2
165
+ p.refresh_rate.should == 1
166
+ end
167
+
168
+ it "should be possible to set the default storage mechanism" do
169
+ p1 = Primer.new( :session => @session )
170
+ p2 = Primer.new( :session => @session, :default_storage_mechanism => :file )
171
+ def p1.get_default_stormech
172
+ self.storage_mechanism
173
+ end
174
+ def p2.get_default_stormech
175
+ self.storage_mechanism
176
+ end
177
+ p1.get_default_stormech.should == :memory
178
+ p2.get_default_stormech.should == :file
165
179
  end
166
180
 
167
181
  end
data/spec/sadie_server.rb CHANGED
@@ -4,8 +4,8 @@ $:.unshift File.join(File.dirname(__FILE__), '..')
4
4
  require 'sadie_server'
5
5
 
6
6
  class SadieServer
7
- def self.proc_args( argv )
8
- { :framework_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation' ) }
7
+ def self.proc_args( argv=nil )
8
+ { :framework_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','another_test_installation' ) }
9
9
  end
10
10
  end
11
11
 
@@ -20,6 +20,14 @@ describe 'the sadie server app' do
20
20
  Sinatra::Application
21
21
  end
22
22
 
23
+ before :each do
24
+ system 'install -d /tmp/sadie-test-keystor'
25
+ end
26
+
27
+ after :each do
28
+ system 'rm -rf /tmp/sadie-test-keystor'
29
+ end
30
+
23
31
  it "returns the correct value" do
24
32
  get '/minimal.primer'
25
33
  expect(last_response).to be_ok
@@ -36,4 +44,28 @@ describe 'the sadie server app' do
36
44
  expect(last_response).to be_ok
37
45
  expect(last_response.body).to eq('testval99')
38
46
  end
47
+
48
+ it "should return the config as a hash" do
49
+ srv = SadieServer.new( SadieServer::proc_args )
50
+ srv._config_hash.is_a?( Hash ).should be_true
51
+ end
52
+
53
+ it "should return the default storage mechanism config val as a symbol" do
54
+ srv = SadieServer.new( SadieServer::proc_args )
55
+ srv._config_hash['storage']['default_storage_mechanism'].is_a?(Symbol).should be_true
56
+ end
57
+
58
+ it "should initialize the session with the default storage mechanism" do
59
+ srv = SadieServer.new( SadieServer::proc_args )
60
+ def srv.get_session
61
+ @sadie_session
62
+ end
63
+ sess = srv.get_session
64
+ puts "sess: #{sess.pretty_inspect}"
65
+ def sess.get_default_storage_mechanism
66
+ @default_storage_mechanism
67
+ end
68
+ sess.get_default_storage_mechanism.should == :file
69
+ end
70
+
39
71
  end
@@ -1,17 +1,20 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
2
  require 'sadie_server'
3
3
  require 'pp'
4
+
5
+ test_framework_dirpath = File.join( File.dirname(__FILE__), '..', 'test', 'v2', 'test_installation')
6
+
4
7
  describe SadieServer do
5
8
 
6
9
  describe '#proc_args' do
7
10
 
8
11
  it "should accept a framework-dirpath arg" do
9
12
 
10
- result = SadieServer::proc_args ["--framework-dirpath=/tmp/sadietest"]
13
+ result = SadieServer::proc_args ["--framework-dirpath=#{test_framework_dirpath}"]
11
14
  result.should_not be_nil
12
15
  result.is_a?( Hash ).should be_true
13
16
  result.has_key?( :framework_dirpath ).should be_true
14
- result[:framework_dirpath].should == '/tmp/sadietest'
17
+ result[:framework_dirpath].should == test_framework_dirpath
15
18
 
16
19
  end
17
20
 
@@ -21,8 +24,8 @@ describe SadieServer do
21
24
 
22
25
  it "should store the framework dirpath" do
23
26
 
24
- serv = SadieServer.new( SadieServer::proc_args( ["--framework-dirpath=/tmp/sadietest"] ) )
25
- serv.framework_dirpath.should == '/tmp/sadietest'
27
+ serv = SadieServer.new( SadieServer::proc_args( ["--framework-dirpath=#{test_framework_dirpath}"] ) )
28
+ serv.framework_dirpath.should == test_framework_dirpath
26
29
 
27
30
  end
28
31
 
@@ -3,74 +3,125 @@ require 'sadie_session'
3
3
  require 'pp'
4
4
  describe SadieSession do
5
5
 
6
+ before :each do
7
+ system 'install -d /tmp/sadie-test-keystor'
8
+ @session = SadieSession.new(
9
+ :primers_dirpath =>
10
+ File.join(
11
+ File.dirname( __FILE__ ), '..','test','v2',
12
+ 'test_installation','primers'
13
+ ),
14
+ :file_storage_mechanism_dirpath => '/tmp/sadie-test-keystor'
15
+ )
16
+ @session_default_file = SadieSession.new(
17
+ :primers_dirpath =>
18
+ File.join(
19
+ File.dirname( __FILE__ ), '..','test','v2',
20
+ 'test_installation','primers'
21
+ ),
22
+ :file_storage_mechanism_dirpath => '/tmp/sadie-test-keystor',
23
+ :default_storage_mechanism => :file
24
+ )
25
+ end
26
+
27
+ after :each do
28
+ system 'rm -rf /tmp/sadie-test-keystor'
29
+ end
30
+
6
31
  it "should be able to get and set" do
7
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
8
- session.set('test.key','test.value')
9
- session.get('test.key').should == 'test.value'
32
+ @session.set('test.key','test.value')
33
+ @session.get('test.key').should == 'test.value'
10
34
  end
11
35
 
12
36
  it "should register primers" do
13
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
14
- session.primer_registered?("minimal.primer").should be_true
37
+ @session.primer_registered?("minimal.primer").should be_true
15
38
  end
16
39
 
17
40
  it "should not execute primer assign directives" do
18
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
19
- session.has_key?("minimal.primer").should be_false
41
+ @session.has_key?("minimal.primer").should be_false
20
42
  end
21
43
 
22
44
  it "should be possible to _get_ registered keys" do
23
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
24
- session.get("minimal.primer").should == "testval"
45
+ @session.get("minimal.primer").should == "testval"
25
46
  end
26
47
 
27
48
  it "should find primers in subdirectories" do
28
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
29
- session.get("subdir.test").should == "testval"
49
+ @session.get("subdir.test").should == "testval"
30
50
  end
31
51
 
32
52
  it "should be possible to expire on get" do
33
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
34
- session.get("test.expires.onget").should == "testval"
35
- session.has_key?("test.expires.onget").should be_false
53
+ @session.get("test.expires.onget").should == "testval"
54
+ @session.has_key?("test.expires.onget").should be_false
36
55
  end
37
56
 
38
57
  it "should put keys in the expire schedule" do
39
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
40
-
41
- def session.in_expire_schedule?( key )
58
+ def @session.in_expire_schedule?( key )
42
59
  ( ! @expire_schedule.values.index(key).nil? )
43
60
  end
44
61
 
45
- session.get("test.expires.nsecs").should == "testval"
46
- session.in_expire_schedule?("test.expires.nsecs").should be true
62
+ @session.get("test.expires.nsecs").should == "testval"
63
+ @session.in_expire_schedule?("test.expires.nsecs").should be true
47
64
  end
48
65
 
49
66
  it "should expire keys using _expire_pass" do
50
67
 
51
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
52
- def session.run_expiry_pass
68
+ def @session.run_expiry_pass
53
69
  _expiry_pass
54
70
  end
55
- session.stub(:_current_time).and_return(2,5,8,11,14)
56
- session.stub(:_expiry_loop).and_return(false)
57
- session.get("test.expires.nsecs").should == "testval"
58
- session.has_key?("test.expires.nsecs").should be_true
59
- session.run_expiry_pass
60
- session.has_key?("test.expires.nsecs").should be_false
71
+ @session.stub(:_current_time).and_return(2,5,8,11,14)
72
+ @session.stub(:_expiry_loop).and_return(false)
73
+ @session.get("test.expires.nsecs").should == "testval"
74
+ @session.has_key?("test.expires.nsecs").should be_true
75
+ @session.run_expiry_pass
76
+ @session.has_key?("test.expires.nsecs").should be_false
61
77
  end
62
78
 
63
79
  it "should refresh keys" do
64
80
 
65
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
66
- def session.run_refresh_pass
81
+ def @session.run_refresh_pass
67
82
  _refresh_pass
68
83
  end
69
- session.stub(:_current_time).and_return(2,5,8,11,14)
70
- session.stub(:_refresh_loop).and_return(false)
71
- session.get("test.refresh").should == "refresh"
72
- session.run_refresh_pass
73
- session.get("test.refresh").should == "rrefresh"
84
+ @session.stub(:_current_time).and_return(2,5,8,11,14)
85
+ @session.stub(:_refresh_loop).and_return(false)
86
+ @session.get("test.refresh").should == "refresh"
87
+ @session.run_refresh_pass
88
+ @session.get("test.refresh").should == "rrefresh"
89
+ end
90
+
91
+ it "should set the default storage mechanism" do
92
+ def @session.get_default_storage_mechanism
93
+ @default_storage_mechanism
94
+ end
95
+ @session.get_default_storage_mechanism.should == :memory
96
+ @session_default_file = SadieSession.new(
97
+ :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ),
98
+ :default_storage_mechanism => :file)
99
+ def @session_default_file.get_default_storage_mechanism
100
+ @default_storage_mechanism
101
+ end
102
+ @session_default_file.get_default_storage_mechanism.should == :file
103
+ end
104
+
105
+ it "should initialize the file storage mechanism with the key storage dirpath set in init params" do
106
+ def @session.storagemgr
107
+ @storage_manager
108
+ end
109
+ mgr = @session.storagemgr
110
+ def mgr.getfilemech
111
+ @mechanisms[:file]
112
+ end
113
+ filemech = mgr.getfilemech
114
+ filemech.key_storage_dirpath.should == '/tmp/sadie-test-keystor'
115
+ end
116
+
117
+ it "should store keys in different storage mechanisms" do
118
+ def @session.detect_storage_mechanism(key)
119
+ @storage_manager.where_key?( key )
120
+ end
121
+ @session.set('key1','val1',:mechanism => :memory)
122
+ @session.set('key2','val2',:mechanism => :file)
123
+ @session.detect_storage_mechanism('key1').should == :memory
124
+ @session.detect_storage_mechanism('key2').should == :file
74
125
  end
75
126
 
76
127
  # --- SLOW!
@@ -78,19 +129,17 @@ describe SadieSession do
78
129
 
79
130
  it "should expire keys after specified time" do
80
131
 
81
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
82
- session.get("test.expires.nsecs").should == "testval"
83
- session.has_key?("test.expires.nsecs").should be_true
132
+ @session.get("test.expires.nsecs").should == "testval"
133
+ @session.has_key?("test.expires.nsecs").should be_true
84
134
  sleep 2
85
- session.has_key?("test.expires.nsecs").should be_false
135
+ @session.has_key?("test.expires.nsecs").should be_false
86
136
  end
87
137
 
88
138
  it "should refresh keys after specified time" do
89
139
 
90
- session = SadieSession.new( :primers_dirpath => File.join( File.dirname( __FILE__ ), '..','test','v2','test_installation','primers' ))
91
- session.get("test.refresh").should == "refresh"
140
+ @session.get("test.refresh").should == "refresh"
92
141
  sleep 2
93
- session.get("test.refresh").should == "rrefresh"
142
+ @session.get("test.refresh").should == "rrefresh"
94
143
  end
95
144
 
96
145
  end
@@ -0,0 +1,31 @@
1
+ require 'storage/file'
2
+ describe SadieStorageMechanismFile do
3
+
4
+ before :each do
5
+ system 'install -d /tmp/stormech-file-test'
6
+ @mech = SadieStorageMechanismFile.new( :key_storage_dirpath => '/tmp/stormech-file-test' )
7
+ end
8
+
9
+ after :each do
10
+ system 'rm -rf /tmp/stormech-file-test'
11
+ end
12
+
13
+ it "should successfully return a set value" do
14
+ @mech.set 'somekey.test','some_value'
15
+ @mech.get( 'somekey.test' ).should == 'some_value'
16
+ end
17
+
18
+ it "should have a functional has_key? method" do
19
+ @mech.has_key?( "somekey.test" ).should be_false
20
+ @mech.set 'somekey.test','some_value'
21
+ @mech.has_key?( "somekey.test" ).should be_true
22
+ end
23
+
24
+ it "should have a functional unset method" do
25
+ @mech.set 'somekey.test','some_value'
26
+ @mech.has_key?( "somekey.test" ).should be_true
27
+ @mech.unset 'somekey.test'
28
+ @mech.has_key?( "somekey.test" ).should be_false
29
+ end
30
+
31
+ end
@@ -0,0 +1,4 @@
1
+ storage:
2
+ default_storage_mechanism: file
3
+ file:
4
+ key_storage_dirpath: /tmp/sadie-test-keystor
@@ -0,0 +1,5 @@
1
+ prime ["minimal.primer"] do
2
+ assign do
3
+ set "testval"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ storage:
2
+ default_storage_mechanism: memory
3
+ file:
4
+ key_storage_dirpath: /tmp/sadie-test-keystor
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sadie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred McDavid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -93,7 +93,8 @@ files:
93
93
  - bin/sadie_query_server
94
94
  - bin/sadie_server
95
95
  - bin/sadie_server.rb
96
- - doc/v2
96
+ - doc/planning/brainstorm.txt
97
+ - doc/planning/todo.examples.txt
97
98
  - lib/.gitignore
98
99
  - lib/primer.rb
99
100
  - lib/sadie/version.rb
@@ -101,6 +102,7 @@ files:
101
102
  - lib/sadie_session.rb
102
103
  - lib/sadie_storage_manager.rb
103
104
  - lib/sadie_storage_mechanism.rb
105
+ - lib/storage/file.rb
104
106
  - lib/storage/memory.rb
105
107
  - rdoc/classes/Sadie.html
106
108
  - rdoc/created.rid
@@ -119,7 +121,11 @@ files:
119
121
  - spec/sadie_server_lib.rb
120
122
  - spec/sadie_session.rb
121
123
  - spec/storage_manager.rb
124
+ - spec/storage_mechanisms/file.rb
122
125
  - spec/storage_mechanisms/memory.rb
126
+ - test/v2/another_test_installation/config/sadie.yml
127
+ - test/v2/another_test_installation/primers/minimal.rb
128
+ - test/v2/test_installation/config/sadie.yml
123
129
  - test/v2/test_installation/primers/minimal.rb
124
130
  - test/v2/test_installation/primers/onelevel/twolevel/test_subdir.rb
125
131
  - test/v2/test_installation/primers/test_after_each.rb