perobs 2.5.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,91 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Copyright (c) 2016 by Chris Schlaeger <chris@taskjuggler.org>
4
- #
5
- # MIT License
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- require 'fileutils'
27
-
28
- require 'spec_helper'
29
- require 'perobs/FixedSizeBlobFile'
30
-
31
- describe PEROBS::FixedSizeBlobFile do
32
-
33
- before(:all) do
34
- @db_dir = generate_db_name('FixedSizeBlobFile')
35
- FileUtils.mkdir_p(@db_dir)
36
- @bf = PEROBS::FixedSizeBlobFile.new(@db_dir, 'FixedSizeBlobFile', 4)
37
- end
38
-
39
- after(:all) do
40
- FileUtils.rm_rf(@db_dir)
41
- end
42
-
43
- it 'should create the file' do
44
- @bf.open
45
- end
46
-
47
- it 'should return free addresses' do
48
- expect(@bf.free_address).to eql(0)
49
- end
50
-
51
- it 'should store and retrieve a blob' do
52
- @bf.store_blob(0,'0000')
53
- expect(@bf.retrieve_blob(0)).to eql('0000')
54
- end
55
-
56
- it 'should store and retrieve multiple blobs' do
57
- @bf.store_blob(0,'XXXX')
58
- @bf.store_blob(1,'1111')
59
- @bf.store_blob(2,'2222')
60
- @bf.store_blob(3,'3333')
61
- expect(@bf.retrieve_blob(0)).to eql('XXXX')
62
- expect(@bf.retrieve_blob(1)).to eql('1111')
63
- expect(@bf.retrieve_blob(2)).to eql('2222')
64
- expect(@bf.retrieve_blob(3)).to eql('3333')
65
- end
66
-
67
- it 'should return nil for a too large address' do
68
- expect(@bf.retrieve_blob(4)).to be_nil
69
- end
70
-
71
- it 'should delete an entry' do
72
- @bf.delete_blob(2)
73
- expect(@bf.retrieve_blob(4)).to be_nil
74
- end
75
-
76
- it 'should return 2 as an empty address now' do
77
- expect(@bf.free_address).to eql(2)
78
- end
79
-
80
- it 'should persist all values over and close/open' do
81
- @bf.close
82
- @bf.open
83
-
84
- expect(@bf.retrieve_blob(0)).to eql('XXXX')
85
- expect(@bf.retrieve_blob(1)).to eql('1111')
86
- expect(@bf.retrieve_blob(2)).to be_nil
87
- expect(@bf.retrieve_blob(3)).to eql('3333')
88
- end
89
-
90
- end
91
-
@@ -1,91 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Copyright (c) 2016 by Chris Schlaeger <chris@taskjuggler.org>
4
- #
5
- # MIT License
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- require 'fileutils'
27
-
28
- require 'spec_helper'
29
- require 'perobs/FreeSpaceManager'
30
-
31
- describe PEROBS::FreeSpaceManager do
32
-
33
- before(:all) do
34
- @db_dir = generate_db_name('FreeSpaceManager')
35
- FileUtils.mkdir_p(@db_dir)
36
- @m = PEROBS::FreeSpaceManager.new(@db_dir)
37
- end
38
-
39
- after(:all) do
40
- FileUtils.rm_rf(@db_dir)
41
- end
42
-
43
- it 'should open the space manager' do
44
- @m.open
45
- expect(@m.inspect).to eql('[]')
46
- end
47
-
48
- it 'should support adding and removing space' do
49
- @m.add_space(1, 7)
50
- expect(@m.has_space?(1, 7)).to be true
51
- expect(@m.inspect).to eql('[nil, nil, [[1, 7]]]')
52
- expect(@m.get_space(4)).to eql([ 1, 7 ])
53
- expect(@m.inspect).to eql('[nil, nil, []]')
54
- end
55
-
56
- it 'should no longer provide that space' do
57
- expect(@m.get_space(4)).to be_nil
58
- end
59
-
60
- it 'should keep values over an close/open' do
61
- @m.add_space(1, 15)
62
- @m.close
63
- @m.open
64
- expect(@m.inspect).to eql('[nil, nil, [], [[1, 15]]]')
65
- expect(@m.get_space(8)).to eql([ 1, 15 ])
66
- end
67
-
68
- it 'should support clearing the data' do
69
- @m.clear
70
- expect(@m.inspect).to eql('[]')
71
- end
72
-
73
- it 'should multiple values to a pool' do
74
- 1.upto(8) { |i| @m.add_space(i, i) }
75
- expect(@m.inspect).to eql('[[[1, 1]], [[2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6], [7, 7]], [[8, 8]]]')
76
- end
77
-
78
- it 'should return the spaces again' do
79
- expect(@m.get_space(1)).to eql([ 1, 1])
80
- expect(@m.inspect).to eql('[[], [[2, 2], [3, 3]], [[4, 4], [5, 5], [6, 6], [7, 7]], [[8, 8]]]')
81
- expect(@m.get_space(2)).to eql([ 3, 3])
82
- expect(@m.inspect).to eql('[[], [[2, 2]], [[4, 4], [5, 5], [6, 6], [7, 7]], [[8, 8]]]')
83
- expect(@m.get_space(2)).to eql([ 2, 2])
84
- expect(@m.inspect).to eql('[[], [], [[4, 4], [5, 5], [6, 6], [7, 7]], [[8, 8]]]')
85
- expect(@m.get_space(4)).to eql([ 7, 7])
86
- expect(@m.inspect).to eql('[[], [], [[4, 4], [5, 5], [6, 6]], [[8, 8]]]')
87
- expect(@m.get_space(8)).to eql([ 8, 8])
88
- expect(@m.inspect).to eql('[[], [], [[4, 4], [5, 5], [6, 6]], []]')
89
- end
90
-
91
- end
@@ -1,118 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Copyright (c) 2016 by Chris Schlaeger <chris@taskjuggler.org>
4
- #
5
- # MIT License
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- require 'fileutils'
27
-
28
- require 'spec_helper'
29
- require 'perobs/IndexTree'
30
-
31
- describe PEROBS::StackFile do
32
-
33
- before(:all) do
34
- @db_dir = generate_db_name('IndexTree')
35
- FileUtils.mkdir_p(@db_dir)
36
- @t = PEROBS::IndexTree.new(@db_dir)
37
- @ref = []
38
- end
39
-
40
- after(:all) do
41
- FileUtils.rm_rf(@db_dir)
42
- end
43
-
44
- it 'should create the file' do
45
- @t.open
46
- end
47
-
48
- it 'should store and retrieve a value' do
49
- @t.put_value(0x8, 8)
50
- expect(@t.inspect).to eql("{\n 8 => 8,\n}\n")
51
- expect(@t.get_value(0x8)).to eql(8)
52
- end
53
-
54
- it 'should store another value in the same node' do
55
- @t.put_value(0x4, 4)
56
- expect(@t.get_value(0x4)).to eql(4)
57
- end
58
-
59
- it 'should store another value in a new sub-node' do
60
- @t.put_value(0x88, 0x88)
61
- expect(@t.inspect).to eql("{\n 4 => 4,\n {\n 8 => 8,\n 136 => 136,\n }\n }\n")
62
- expect(@t.get_value(0x88)).to eql(0x88)
63
- end
64
-
65
- it 'should store one more value in a new sub-node' do
66
- @t.put_value(0x888, 0x888)
67
- expect(@t.inspect).to eql("{\n 4 => 4,\n {\n 8 => 8,\n {\n 136 => 136,\n 2184 => 2184,\n }\n }\n }\n")
68
- expect(@t.get_value(0x888)).to eql(0x888)
69
- end
70
-
71
- it 'should delete the 0x88 entry' do
72
- expect(@t.delete_value(0x88)).to be true
73
- expect(@t.inspect).to eql("{\n 4 => 4,\n {\n 8 => 8,\n {\n 2184 => 2184,\n }\n }\n }\n")
74
- end
75
-
76
- it 'should delete all other entries' do
77
- expect(@t.delete_value(0x8)).to be true
78
- expect(@t.delete_value(0x4)).to be true
79
- expect(@t.delete_value(0x888)).to be true
80
- expect(@t.inspect).to eql("{\n}\n")
81
- end
82
-
83
- it 'should replace an existing value' do
84
- @t.put_value(0x8, 1)
85
- @t.put_value(0x8, 2)
86
- expect(@t.inspect).to eql("{\n 8 => 2,\n}\n")
87
- expect(@t.get_value(0x8)).to eql(2)
88
- end
89
-
90
- it 'should store lots more values' do
91
- @ref = [ 28465, 62258, 59640, 40113, 29237, 22890, 43429, 20374, 37393, 48482, 3243, 5751, 23426, 200, 16835, 38979, 31961, 58810, 40284, 53696, 44741, 53939, 16715, 2775, 16708, 49209, 48767, 6138, 36574, 23063, 13374, 33611, 43477, 63753, 22456, 4461, 52257, 62546, 13629, 52716, 54576, 64695, 7514, 22406, 60298, 43935, 50906, 48965, 56244, 12918, 630, 463, 44735, 49868, 10941, 29121, 26034, 21946, 34071, 55514, 35488, 64583, 59245, 43911, 3035, 2848, 3584, 6813, 61754, 877, 28118, 52626, 4454, 19024, 7467, 59573, 7661, 49226, 33151, 25919, 3596, 36407, 41008, 21611, 52627, 6393, 5551, 34773, 26697, 10510, 50726, 7743, 9843, 62188, 24468, 63553, 3728, 60080, 45667, 6165, 38354 ]
92
- @ref.each { |v| @t.put_value(v, v) }
93
- @ref.each do |v|
94
- expect(@t.get_value(v)).to eql(v)
95
- end
96
- end
97
-
98
- it 'should still have the values after a close/open' do
99
- @t.close
100
- @t.open
101
- @ref.each do |v|
102
- expect(@t.get_value(v)).to eql(v)
103
- end
104
- end
105
-
106
- it 'should delete some of the stored values' do
107
- del = [ 55514, 35488, 64583, 59245, 43911, 3035, 2848, 3584, 6813, 61754, 877, 28118, 52626, 4454, 19024, 7467, 23426, 200, 16835, 38979, 31961, 60080, 45667, 6165, 38354 ]
108
- del.each do |v|
109
- @ref.delete(v)
110
- expect(@t.delete_value(v)).to be true
111
- end
112
- del.each do |v|
113
- expect(@t.get_value(v)).to be_nil
114
- end
115
- end
116
-
117
- end
118
-