odba 1.1.9 → 1.2.1

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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/devenv.yml +34 -0
  3. data/.github/workflows/ruby.yml +8 -8
  4. data/.gitignore +15 -0
  5. data/History.md +131 -0
  6. data/README.md +77 -1
  7. data/Rakefile +3 -15
  8. data/devenv.lock +171 -0
  9. data/devenv.nix +66 -0
  10. data/devenv.yaml +16 -0
  11. data/lib/odba/cache.rb +395 -344
  12. data/lib/odba/cache_entry.rb +42 -31
  13. data/lib/odba/connection_pool.rb +99 -72
  14. data/lib/odba/drbwrapper.rb +26 -18
  15. data/lib/odba/id_server.rb +20 -20
  16. data/lib/odba/index.rb +249 -215
  17. data/lib/odba/index_definition.rb +17 -17
  18. data/lib/odba/marshal.rb +15 -14
  19. data/lib/odba/odba.rb +40 -32
  20. data/lib/odba/odba_error.rb +4 -2
  21. data/lib/odba/persistable.rb +460 -414
  22. data/lib/odba/storage.rb +328 -277
  23. data/lib/odba/stub.rb +166 -153
  24. data/lib/odba/version.rb +1 -1
  25. data/lib/odba.rb +9 -9
  26. data/odba.gemspec +8 -3
  27. data/test/example.rb +47 -0
  28. data/test/helper.rb +6 -0
  29. data/test/suite.rb +7 -0
  30. data/test/test_array.rb +38 -33
  31. data/test/test_cache.rb +666 -622
  32. data/test/test_cache_entry.rb +51 -71
  33. data/test/test_connection_pool.rb +70 -25
  34. data/test/test_drbwrapper.rb +31 -20
  35. data/test/test_hash.rb +98 -89
  36. data/test/test_id_server.rb +30 -32
  37. data/test/test_index.rb +191 -158
  38. data/test/test_marshal.rb +15 -25
  39. data/test/test_persistable.rb +378 -369
  40. data/test/test_storage.rb +510 -471
  41. data/test/test_stub.rb +147 -135
  42. metadata +63 -20
  43. data/Guide.txt +0 -36
  44. data/History.txt +0 -91
  45. data/Manifest.txt +0 -38
  46. data/install.rb +0 -1098
  47. data/lib/odba/18_19_loading_compatibility.rb +0 -77
data/test/test_hash.rb CHANGED
@@ -1,112 +1,119 @@
1
1
  #!/usr/bin/env ruby
2
2
  # TestHash -- odba -- ??.??.???? -- hwyss@ywesee.com
3
-
4
- $: << File.dirname(__FILE__)
5
- $: << File.expand_path('../lib/', File.dirname(__FILE__))
6
-
7
- require 'minitest/autorun'
8
- require 'flexmock/test_unit'
9
- require 'flexmock'
10
- require 'odba/persistable'
11
- require 'odba/stub'
12
- require 'odba/odba'
3
+ require_relative "helper"
4
+ require "odba/persistable"
5
+ require "odba/stub"
6
+ require "odba/odba"
13
7
 
14
8
  module ODBA
15
- class TestHash < Minitest::Test
9
+ class TestHash < Test::Unit::TestCase
16
10
  include FlexMock::TestCase
17
- class ODBAContainerInHash
18
- include Persistable
19
- attr_accessor :non_replaceable, :replaceable, :odba_id
20
- end
11
+ class ODBAContainerInHash
12
+ include Persistable
13
+ attr_accessor :non_replaceable, :replaceable, :odba_id
14
+ end
15
+
21
16
  class Container
22
17
  attr_accessor :content
23
18
  end
24
- class TestStub
25
- attr_accessor :receiver, :odba_replace
26
- def is_a?(arg)
27
- true
28
- end
29
- end
30
- def setup
31
- @hash = Hash.new
32
- ODBA.cache = flexmock("cache")
33
- ODBA.storage = flexmock("storage")
34
- @hash.clear
35
- end
19
+
20
+ class TestStub
21
+ attr_accessor :receiver, :odba_replace
22
+ def is_a?(arg)
23
+ true
24
+ end
25
+ end
26
+
27
+ def setup
28
+ @hash = {}
29
+ ODBA.cache = flexmock("cache")
30
+ ODBA.storage = flexmock("storage")
31
+ @hash.clear
32
+ end
33
+
36
34
  def teardown
37
35
  super
38
36
  end
39
- def test_odba_unsaved_neighbors_hash
40
- repkey1 = ODBAContainerInHash.new
41
- repkey2 = ODBAContainerInHash.new
42
- repvalue1 = ODBAContainerInHash.new
43
- repvalue2 = ODBAContainerInHash.new
44
- @hash.store(repkey1, repvalue1)
45
- @hash.store(repkey2, repvalue2)
46
- result = @hash.odba_unsaved_neighbors(1)
47
- assert_equal(true, result.include?(repkey1))
48
- assert_equal(true, result.include?(repkey2))
49
- assert_equal(true, result.include?(repvalue1))
50
- assert_equal(true, result.include?(repvalue2))
51
- end
52
- def test_odba_replace_persistables_hash
53
- key1 = flexmock("key")
54
- value1 = flexmock("value")
55
- @hash.store(key1, value1)
56
- @hash.odba_replace_persistables
57
- assert_equal(@hash, {})
58
- end
59
- def test_odba_prefetch
60
- key1 = flexmock("key")
61
- val1 = flexmock("val1")
62
- @hash.store(key1, val1)
63
- assert_equal(false, @hash.odba_prefetch?)
64
- end
65
- def test_odba_unsaved_true
66
- key = flexmock("key")
67
- val = flexmock("val")
68
- @hash.instance_variable_set("@odba_persistent", true)
69
- @hash.store(key, val)
70
- val.should_receive(:is_a?).and_return { |klass| true }
71
- val.should_receive(:odba_unsaved?).and_return { true }
72
-
73
- assert_equal(true, @hash.odba_unsaved?)
74
- end
37
+
38
+ def test_odba_unsaved_neighbors_hash
39
+ repkey1 = ODBAContainerInHash.new
40
+ repkey2 = ODBAContainerInHash.new
41
+ repvalue1 = ODBAContainerInHash.new
42
+ repvalue2 = ODBAContainerInHash.new
43
+ @hash.store(repkey1, repvalue1)
44
+ @hash.store(repkey2, repvalue2)
45
+ result = @hash.odba_unsaved_neighbors(1)
46
+ assert_equal(true, result.include?(repkey1))
47
+ assert_equal(true, result.include?(repkey2))
48
+ assert_equal(true, result.include?(repvalue1))
49
+ assert_equal(true, result.include?(repvalue2))
50
+ end
51
+
52
+ def test_odba_replace_persistables_hash
53
+ key1 = flexmock("key")
54
+ value1 = flexmock("value")
55
+ @hash.store(key1, value1)
56
+ @hash.odba_replace_persistables
57
+ assert_equal(@hash, {})
58
+ end
59
+
60
+ def test_odba_prefetch
61
+ key1 = flexmock("key")
62
+ val1 = flexmock("val1")
63
+ @hash.store(key1, val1)
64
+ assert_equal(false, @hash.odba_prefetch?)
65
+ end
66
+
67
+ def test_odba_unsaved_true
68
+ key = flexmock("key")
69
+ val = flexmock("val")
70
+ @hash.instance_variable_set(:@odba_persistent, true)
71
+ @hash.store(key, val)
72
+ val.should_receive(:is_a?).and_return { |klass| true }
73
+ val.should_receive(:odba_unsaved?).and_return { true }
74
+
75
+ assert_equal(true, @hash.odba_unsaved?)
76
+ end
77
+
75
78
  def test_odba_cut_connection
76
79
  remove_obj = Object.new
77
80
  remove_obj.extend(ODBA::Persistable)
78
- remove_obj.instance_variable_set('@odba_id', 2)
81
+ remove_obj.instance_variable_set(:@odba_id, 2)
79
82
  other = Object.new
80
83
  other.extend(ODBA::Persistable)
81
- other.instance_variable_set('@odba_id', 3)
84
+ other.instance_variable_set(:@odba_id, 3)
82
85
  receiver = ODBA::Stub.new(2, nil, remove_obj)
83
- ODBA.cache.should_receive(:fetch).with(2,nil).and_return(remove_obj)
84
- @hash.store('foo', receiver)
85
- @hash.store(receiver, 'bar')
86
- @hash.store('bar', other)
87
- @hash.store(other, 'baz')
86
+ ODBA.cache.should_receive(:fetch).with(2, nil).and_return(remove_obj)
87
+ @hash.store("foo", receiver)
88
+ @hash.store(receiver, "bar")
89
+ @hash.store("bar", other)
90
+ @hash.store(other, "baz")
88
91
  @hash.odba_cut_connection(remove_obj)
89
- assert_equal({'bar' => other, other => 'baz'}, @hash)
92
+ assert_equal({"bar" => other, other => "baz"}, @hash)
90
93
  end
94
+
91
95
  def test_odba_collection
92
- @hash.update('foo' => 'bar', 'trouble' => 'not')
93
- assert_equal([['foo', 'bar'],['trouble', 'not']],
94
- @hash.odba_collection.sort)
96
+ @hash.update("foo" => "bar", "trouble" => "not")
97
+ assert_equal([["foo", "bar"], ["trouble", "not"]],
98
+ @hash.odba_collection.sort)
95
99
  end
100
+
96
101
  def test_odba_replace
97
- modified = { 'foo' => 'bar' }
102
+ modified = {"foo" => "bar"}
98
103
  reloaded = modified.dup
99
- modified.update('foo' => 'baz', 'han' => 'solo')
104
+ modified.update("foo" => "baz", "han" => "solo")
100
105
 
101
106
  modified.odba_replace!(reloaded)
102
107
 
103
108
  assert_equal(reloaded, modified)
104
109
  end
110
+
105
111
  def test_odba_restore
106
- collection = [[:foo, 'bar'],[:trouble, 'not']]
112
+ collection = [[:foo, "bar"], [:trouble, "not"]]
107
113
  @hash.odba_restore(collection)
108
- assert_equal({:foo => 'bar', :trouble => 'not'}, @hash)
114
+ assert_equal({foo: "bar", trouble: "not"}, @hash)
109
115
  end
116
+
110
117
  def test_odba_target_ids
111
118
  o = ODBAContainerInHash.new
112
119
  o.odba_id = 1
@@ -114,13 +121,14 @@ module ODBA
114
121
  p.odba_id = 2
115
122
  q = ODBAContainerInHash.new
116
123
  q.odba_id = 3
117
- @hash.store('foo', p)
118
- @hash.store(p, 'bar')
119
- @hash.store('bar', q)
120
- @hash.store(q, 'baz')
121
- @hash.instance_variable_set('@var', o)
122
- assert_equal([1,2,3], @hash.odba_target_ids.sort)
124
+ @hash.store("foo", p)
125
+ @hash.store(p, "bar")
126
+ @hash.store("bar", q)
127
+ @hash.store(q, "baz")
128
+ @hash.instance_variable_set(:@var, o)
129
+ assert_equal([1, 2, 3], @hash.odba_target_ids.sort)
123
130
  end
131
+
124
132
  def test_odba_stubize
125
133
  obj = Object.new
126
134
  obj.extend(ODBA::Persistable)
@@ -129,20 +137,21 @@ module ODBA
129
137
  assert_equal(11, obj.odba_id)
130
138
  hash = {1 => obj}
131
139
  assert_equal(12, hash.odba_id)
132
- assert_equal(true, hash.odba_stubize(obj, :force => true))
140
+ assert_equal(true, hash.odba_stubize(obj, force: true))
133
141
  assert_equal([1], hash.keys)
134
142
  assert_equal false, hash.values.first.is_a?(ODBA::Stub)
135
143
  end
144
+
136
145
  def test_odba_stubize__key
137
146
  obj = Object.new
138
147
  obj.extend(ODBA::Persistable)
139
148
  id = 10
140
149
  ODBA.cache.should_receive(:next_id).times(2).and_return { id += 1 }
141
150
  assert_equal(11, obj.odba_id)
142
- hash = {obj => 'foo'}
151
+ hash = {obj => "foo"}
143
152
  assert_equal(12, hash.odba_id)
144
- assert_equal(true, hash.odba_stubize(obj, :force => true))
145
- assert_equal({obj => 'foo'}, hash)
153
+ assert_equal(true, hash.odba_stubize(obj, force: true))
154
+ assert_equal({obj => "foo"}, hash)
146
155
  end
147
- end
156
+ end
148
157
  end
@@ -1,45 +1,43 @@
1
1
  #!/usr/bin/env ruby
2
2
  # TestIdServer -- odba -- 10.11.2004 -- hwyss@ywesee.com
3
-
4
- $: << File.dirname(__FILE__)
5
- $: << File.expand_path('../lib', File.dirname(__FILE__))
6
-
7
- require 'minitest/autorun'
8
- require 'flexmock/test_unit'
9
- require 'flexmock'
10
- require 'odba/id_server'
11
- require 'odba/odba'
12
- require 'odba/marshal'
3
+ require_relative "helper"
4
+ require "odba/id_server"
5
+ require "odba/odba"
6
+ require "odba/marshal"
13
7
 
14
8
  module ODBA
15
- class TestIdServer < Minitest::Test
9
+ class TestIdServer < Test::Unit::TestCase
16
10
  include FlexMock::TestCase
17
- def setup
18
- @cache = ODBA.cache = flexmock('cache')
19
- @id_server = IdServer.new
20
- @id_server.instance_variable_set('@odba_id', 1)
21
- end
11
+ def setup
12
+ @cache = ODBA.cache = flexmock("cache")
13
+ @id_server = IdServer.new
14
+ @id_server.instance_variable_set(:@odba_id, 1)
15
+ end
16
+
22
17
  def teardown
23
18
  @id_server = nil
24
19
  super
25
20
  end
26
- def test_first
21
+
22
+ def test_first
27
23
  @cache.should_receive(:store).with(@id_server).times(3)
28
- assert_equal(1, @id_server.next_id(:foo))
29
- assert_equal(1, @id_server.next_id(:bar))
30
- assert_equal(1, @id_server.next_id(:baz))
31
- end
32
- def test_consecutive
24
+ assert_equal(1, @id_server.next_id(:foo))
25
+ assert_equal(1, @id_server.next_id(:bar))
26
+ assert_equal(1, @id_server.next_id(:baz))
27
+ end
28
+
29
+ def test_consecutive
33
30
  @cache.should_receive(:store).with(@id_server).times(3)
34
- assert_equal(1, @id_server.next_id(:foo))
35
- assert_equal(2, @id_server.next_id(:foo))
36
- assert_equal(3, @id_server.next_id(:foo))
37
- end
38
- def test_dumpable
31
+ assert_equal(1, @id_server.next_id(:foo))
32
+ assert_equal(2, @id_server.next_id(:foo))
33
+ assert_equal(3, @id_server.next_id(:foo))
34
+ end
35
+
36
+ def test_dumpable
39
37
  @cache.should_receive(:store).with(@id_server).times(1)
40
- @id_server.next_id(:foo)
41
- dump = @id_server.odba_isolated_dump
42
- assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
43
- end
44
- end
38
+ @id_server.next_id(:foo)
39
+ dump = @id_server.odba_isolated_dump
40
+ assert_instance_of(ODBA::IdServer, ODBA.marshaller.load(dump))
41
+ end
42
+ end
45
43
  end