test/EquiBlobsFile_spec.rb in perobs-4.0.0 vs test/EquiBlobsFile_spec.rb in perobs-4.1.0
- old
+ new
@@ -25,17 +25,21 @@
require 'fileutils'
require 'spec_helper'
require 'perobs/EquiBlobsFile'
+require 'perobs/ProgressMeter'
describe PEROBS::EquiBlobsFile do
before(:all) do
+ PEROBS.log.level = Logger::ERROR
+ PEROBS.log.open($stderr)
@db_dir = generate_db_name('EquiBlobsFile')
FileUtils.mkdir_p(@db_dir)
- @bf = PEROBS::EquiBlobsFile.new(@db_dir, 'EquiBlobsFile', 8)
+ @bf = PEROBS::EquiBlobsFile.new(@db_dir, 'EquiBlobsFile',
+ PEROBS::ProgressMeter.new, 8)
end
after(:all) do
FileUtils.rm_rf(@db_dir)
end
@@ -132,10 +136,16 @@
expect(@bf.total_entries).to eql(4)
expect(@bf.check).to be true
end
+ it 'should support deleting reserved blobs' do
+ adr = @bf.free_address
+ @bf.delete_blob(adr)
+ expect(@bf.check).to be true
+ end
+
it 'should support clearing the file' do
@bf.clear
expect(@bf.total_entries).to eql(0)
expect(@bf.total_spaces).to eql(0)
expect(@bf.check).to be true
@@ -186,9 +196,103 @@
expect(@bf.total_entries).to eql(0)
expect(@bf.total_spaces).to eql(0)
expect(@bf.check).to be true
@bf.store_blob(1,'XXXXXXXX')
expect(@bf.total_entries).to eql(1)
+ expect(@bf.check).to be true
+ end
+
+ it 'should support custom offsets' do
+ @bf.close
+ @bf.erase
+ @bf.clear_custom_data
+ @bf.register_custom_data('foo', 42)
+ @bf.register_custom_data('bar', 43)
+ @bf.open
+ expect(@bf.total_entries).to eql(0)
+ expect(@bf.total_spaces).to eql(0)
+ expect(@bf.check).to be true
+ expect(@bf.free_address).to eql(1)
+ @bf.store_blob(1,'11111111')
+ expect(@bf.free_address).to eql(2)
+ @bf.store_blob(2,'22222222')
+ expect(@bf.free_address).to eql(3)
+ @bf.store_blob(3,'33333333')
+ expect(@bf.check).to be true
+ expect(@bf.total_entries).to eql(3)
+ expect(@bf.total_spaces).to eql(0)
+ @bf.delete_blob(2)
+ expect(@bf.check).to be true
+ expect(@bf.total_entries).to eql(2)
+ expect(@bf.total_spaces).to eql(1)
+ expect(@bf.free_address).to eql(2)
+ @bf.store_blob(2,'44444444')
+ expect(@bf.total_entries).to eql(3)
+ expect(@bf.total_spaces).to eql(0)
+ expect(@bf.check).to be true
+ end
+
+ it 'should support a mix of adds and deletes' do
+ @bf.close
+ @bf.erase
+ @bf.clear_custom_data
+ @bf.register_custom_data('foo', 42)
+ @bf.register_custom_data('bar', 43)
+ @bf.open
+
+ entries = {}
+ 1000.times do |i|
+ rand(30).times do
+ adr = @bf.free_address
+ expect(entries[adr]).to be nil
+ val = rand(2 ** 64)
+ @bf.store_blob(adr, [ val ].pack('Q'))
+ entries[adr] = val
+ #expect(@bf.check).to be true
+ end
+
+ rand(15).times do
+ unless entries.empty?
+ addresses = entries.keys
+ adr = addresses[rand(addresses.length)]
+ expect(@bf.retrieve_blob(adr).unpack('Q').first).to eql(entries[adr])
+ @bf.delete_blob(adr)
+ entries.delete(adr)
+ #expect(@bf.check).to be true
+ end
+ end
+
+ rand(5).times do
+ unless entries.empty?
+ addresses = entries.keys
+ adr = addresses[rand(addresses.length)]
+ val = rand(2 ** 64)
+ @bf.store_blob(adr, [ val ].pack('Q'))
+ entries[adr] = val
+ #expect(@bf.check).to be true
+ end
+ end
+
+ if rand(100) == 0
+ expect(@bf.check).to be true
+ end
+
+ if rand(100) == 0
+ @bf.first_entry = i
+ @bf.set_custom_data('foo', i)
+ end
+
+ if rand(50) == 0
+ @bf.close
+ @bf.open
+ end
+
+ if rand(500) == 0
+ @bf.clear
+ entries = {}
+ end
+ end
+
expect(@bf.check).to be true
end
end