ramdo 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ramdo.rb +2 -7
- data/lib/ramdo/disk_instance.rb +38 -0
- data/lib/ramdo/exceptions.rb +0 -2
- data/lib/ramdo/store.rb +11 -9
- data/lib/ramdo/version.rb +1 -1
- data/spec/disk_instance_spec.rb +51 -0
- data/spec/spec_helper.rb +1 -5
- data/spec/store_spec.rb +29 -9
- metadata +5 -15
- data/lib/ramdo/ramdisk/darwin_wrapper.rb +0 -71
- data/lib/ramdo/ramdisk/factory.rb +0 -16
- data/lib/ramdo/ramdisk/generic_wrapper.rb +0 -41
- data/lib/ramdo/ramdisk/instance.rb +0 -24
- data/lib/ramdo/ramdisk/linux_wrapper.rb +0 -56
- data/spec/darwin_wrapper_spec.rb +0 -67
- data/spec/generic_wrapper_spec.rb +0 -62
- data/spec/linux_wrapper_spec.rb +0 -67
- data/spec/ramdisk_factory_spec.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2129b580a4383759f7120ff3cd47fb3711dd4df
|
4
|
+
data.tar.gz: 7036c489c8caf72890532d9268d2f7d4d42a37d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2675e7b359e41493f6118b8cdb87cee66edf8a6001c79a1d29d58616b2c4b3e759c0d4adc443618c0ab09d658a92d86c5e00eff29060f47e570b0954932bd8
|
7
|
+
data.tar.gz: 3c64dd96d19a4c6848ed19b1bdb2f994a4ceea2a1616c5f8eca86ec80da97abb4183d4f450caa8c07d619679b0c7dde87ce38b30c37904e1262c58185670fa67
|
data/lib/ramdo.rb
CHANGED
@@ -6,17 +6,12 @@ require 'fileutils'
|
|
6
6
|
|
7
7
|
require 'ramdo/version'
|
8
8
|
require 'ramdo/exceptions'
|
9
|
-
require 'ramdo/
|
10
|
-
require 'ramdo/ramdisk/instance'
|
11
|
-
require 'ramdo/ramdisk/darwin_wrapper'
|
12
|
-
require 'ramdo/ramdisk/linux_wrapper'
|
13
|
-
require 'ramdo/ramdisk/generic_wrapper'
|
9
|
+
require 'ramdo/disk_instance'
|
14
10
|
require 'ramdo/store'
|
15
11
|
require 'ramdo/cleaner'
|
16
12
|
|
17
13
|
module Ramdo
|
18
14
|
DEFAULTS = {
|
19
|
-
|
20
|
-
ttl: 120 # In seconds
|
15
|
+
ttl: 3600 # In seconds
|
21
16
|
}
|
22
17
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Ramdo
|
2
|
+
class DiskInstance
|
3
|
+
NAME_PATTERN = /^ramdo_disk_([a-z0-9]+)$/
|
4
|
+
|
5
|
+
def self.list
|
6
|
+
disks = []
|
7
|
+
Dir.glob('/tmp/*').each do |dir|
|
8
|
+
if dir.split(File::SEPARATOR).last =~ NAME_PATTERN
|
9
|
+
disks << self.new(dir)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
disks
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create
|
17
|
+
path = File.join('/tmp', self.generate_name)
|
18
|
+
Dir.mkdir(path)
|
19
|
+
|
20
|
+
self.new(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.generate_name
|
24
|
+
"ramdo_disk_#{SecureRandom.hex(4)}"
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :path
|
28
|
+
|
29
|
+
def initialize(path)
|
30
|
+
@path = path
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy!
|
34
|
+
return false unless Dir.exist? @path
|
35
|
+
FileUtils.rm_r @path, :force => true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/ramdo/exceptions.rb
CHANGED
data/lib/ramdo/store.rb
CHANGED
@@ -5,16 +5,12 @@ module Ramdo
|
|
5
5
|
attr_reader :file, :dir
|
6
6
|
|
7
7
|
def initialize(opts = {})
|
8
|
-
|
9
|
-
list = wrapper.list
|
8
|
+
list = DiskInstance.list
|
10
9
|
disk = nil
|
11
10
|
if list.length <= 0
|
12
|
-
|
13
|
-
disk = wrapper.create(DEFAULTS[:disk_size])
|
11
|
+
disk = DiskInstance.create
|
14
12
|
else
|
15
|
-
|
16
|
-
list.each { |d| disk = d if d.size >= Filesize.from(DEFAULTS[:disk_size]) }
|
17
|
-
disk = wrapper.create(DEFAULTS[:disk_size]) if disk.nil?
|
13
|
+
disk = list.first
|
18
14
|
end
|
19
15
|
|
20
16
|
# Every time a new store is created we check if any other store is out of date
|
@@ -27,14 +23,20 @@ module Ramdo
|
|
27
23
|
@file = File.join(@dir, "store.#{ext}")
|
28
24
|
|
29
25
|
Dir.mkdir(@dir)
|
26
|
+
|
27
|
+
if opts.has_key?(:data)
|
28
|
+
self.data = opts[:data]
|
29
|
+
elsif opts.has_key?(:file)
|
30
|
+
FileUtils.cp opts[:file], @file
|
31
|
+
end
|
30
32
|
end
|
31
33
|
|
32
34
|
def data=(data)
|
33
|
-
IO.
|
35
|
+
IO.binwrite(@file, data)
|
34
36
|
end
|
35
37
|
|
36
38
|
def data
|
37
|
-
IO.
|
39
|
+
IO.binread(@file)
|
38
40
|
end
|
39
41
|
|
40
42
|
def truncate
|
data/lib/ramdo/version.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Ramdo
|
4
|
+
describe DiskInstance do
|
5
|
+
before(:each) do
|
6
|
+
DiskInstance.list.each do |disk|
|
7
|
+
disk.destroy!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
it 'should check if a ramdisk already exists' do
|
13
|
+
disks = DiskInstance.list
|
14
|
+
expect(disks).to be_an(Array)
|
15
|
+
expect(disks.length).to be_a(Integer)
|
16
|
+
expect(disks.length).to be(0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should create a new disk and save a file to it' do
|
20
|
+
disk = DiskInstance.create
|
21
|
+
|
22
|
+
expect(disk).to be_an(DiskInstance)
|
23
|
+
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should remove a RAM disk' do
|
27
|
+
disk = DiskInstance.create
|
28
|
+
|
29
|
+
count = DiskInstance.list.length
|
30
|
+
expect(disk.destroy!).to be_truthy
|
31
|
+
expect(disk.destroy!).to be_falsey # Should not work another time
|
32
|
+
|
33
|
+
expect(DiskInstance.list.length).to be(count - 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should list all available disks' do
|
37
|
+
disk = DiskInstance.create
|
38
|
+
|
39
|
+
list = DiskInstance.list
|
40
|
+
expect(list.length).to eq(1)
|
41
|
+
expect(Dir.exist?(list.first.path)).to be_truthy
|
42
|
+
|
43
|
+
disk = DiskInstance.create
|
44
|
+
|
45
|
+
list = DiskInstance.list
|
46
|
+
expect(list.length).to eq(2)
|
47
|
+
expect(Dir.exist?(list.last.path)).to be_truthy
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/store_spec.rb
CHANGED
@@ -3,22 +3,37 @@ require 'spec_helper'
|
|
3
3
|
include Ramdo
|
4
4
|
describe Store do
|
5
5
|
after(:all) do
|
6
|
-
|
7
|
-
wrapper.list.each do |disk|
|
6
|
+
DiskInstance.list.each do |disk|
|
8
7
|
disk.destroy!
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
11
|
it 'should create a new store and append data to it' do
|
13
|
-
test_data =
|
12
|
+
test_data = "make me sexy"
|
14
13
|
|
15
14
|
store = Store.new
|
15
|
+
expect(File.exist?(store.file)).to be_falsey
|
16
|
+
|
16
17
|
store.data = test_data
|
17
18
|
|
19
|
+
expect(File.exist?(store.file)).to be_truthy
|
18
20
|
expect(IO.read(store.file)).to eq(test_data)
|
19
21
|
expect(store.data).to eq(test_data)
|
20
22
|
end
|
21
23
|
|
24
|
+
it 'should create a new store and append empty data to it' do
|
25
|
+
test_data = nil
|
26
|
+
|
27
|
+
store = Store.new
|
28
|
+
expect(File.exist?(store.file)).to be_falsey
|
29
|
+
|
30
|
+
store.data = test_data
|
31
|
+
|
32
|
+
expect(File.exist?(store.file)).to be_truthy
|
33
|
+
expect(IO.read(store.file)).to eq("")
|
34
|
+
expect(store.data).to eq("")
|
35
|
+
end
|
36
|
+
|
22
37
|
it 'should create a new store with a specific file extension' do
|
23
38
|
extension = '.bin'
|
24
39
|
|
@@ -26,6 +41,13 @@ describe Store do
|
|
26
41
|
expect(File.extname(store.file)).to eq(extension)
|
27
42
|
end
|
28
43
|
|
44
|
+
it 'should create a new store with data' do
|
45
|
+
test_data = 'make me sexy'
|
46
|
+
|
47
|
+
store = Store.new(data: test_data)
|
48
|
+
expect(IO.read(store.file)).to eq(test_data)
|
49
|
+
end
|
50
|
+
|
29
51
|
it 'should create a new store and write data to it' do
|
30
52
|
test_data = 'make me sexy'
|
31
53
|
|
@@ -45,14 +67,12 @@ describe Store do
|
|
45
67
|
end
|
46
68
|
|
47
69
|
it 'should use existing RAM disk if available' do
|
48
|
-
|
49
|
-
|
50
|
-
wrapper.list.each { |disk| disk.destroy! }
|
51
|
-
expect(wrapper.list.length).to eq(0)
|
70
|
+
DiskInstance.list.each { |disk| disk.destroy! }
|
71
|
+
expect(DiskInstance.list.length).to eq(0)
|
52
72
|
store_1 = Store.new
|
53
|
-
expect(
|
73
|
+
expect(DiskInstance.list.length).to eq(1)
|
54
74
|
store_2 = Store.new
|
55
|
-
expect(
|
75
|
+
expect(DiskInstance.list.length).to eq(1)
|
56
76
|
end
|
57
77
|
|
58
78
|
it 'should allow to define a specific file extension' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramdo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Franken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocaine
|
@@ -137,20 +137,13 @@ files:
|
|
137
137
|
- Rakefile
|
138
138
|
- lib/ramdo.rb
|
139
139
|
- lib/ramdo/cleaner.rb
|
140
|
+
- lib/ramdo/disk_instance.rb
|
140
141
|
- lib/ramdo/exceptions.rb
|
141
|
-
- lib/ramdo/ramdisk/darwin_wrapper.rb
|
142
|
-
- lib/ramdo/ramdisk/factory.rb
|
143
|
-
- lib/ramdo/ramdisk/generic_wrapper.rb
|
144
|
-
- lib/ramdo/ramdisk/instance.rb
|
145
|
-
- lib/ramdo/ramdisk/linux_wrapper.rb
|
146
142
|
- lib/ramdo/store.rb
|
147
143
|
- lib/ramdo/version.rb
|
148
144
|
- ramdo.gemspec
|
149
145
|
- spec/cleaner_spec.rb
|
150
|
-
- spec/
|
151
|
-
- spec/generic_wrapper_spec.rb
|
152
|
-
- spec/linux_wrapper_spec.rb
|
153
|
-
- spec/ramdisk_factory_spec.rb
|
146
|
+
- spec/disk_instance_spec.rb
|
154
147
|
- spec/spec_helper.rb
|
155
148
|
- spec/store_spec.rb
|
156
149
|
- tmp/.gitkeep
|
@@ -180,10 +173,7 @@ specification_version: 4
|
|
180
173
|
summary: Fast temporary store powered by RAM disks
|
181
174
|
test_files:
|
182
175
|
- spec/cleaner_spec.rb
|
183
|
-
- spec/
|
184
|
-
- spec/generic_wrapper_spec.rb
|
185
|
-
- spec/linux_wrapper_spec.rb
|
186
|
-
- spec/ramdisk_factory_spec.rb
|
176
|
+
- spec/disk_instance_spec.rb
|
187
177
|
- spec/spec_helper.rb
|
188
178
|
- spec/store_spec.rb
|
189
179
|
has_rdoc:
|
@@ -1,71 +0,0 @@
|
|
1
|
-
module Ramdo
|
2
|
-
module Ramdisk
|
3
|
-
class DarwinWrapper
|
4
|
-
def initialize
|
5
|
-
end
|
6
|
-
|
7
|
-
def list
|
8
|
-
disks = []
|
9
|
-
|
10
|
-
line = Cocaine::CommandLine.new("hdiutil", "info")
|
11
|
-
line.run.each_line do |line|
|
12
|
-
if line =~ /^[=]+$/
|
13
|
-
disks << {}
|
14
|
-
elsif line =~ /^image-path[\s]+:[\s]+(ram:\/\/[0-9]+)/
|
15
|
-
disks.last[:is_ram_disk] = true
|
16
|
-
elsif line =~ /^(\/dev\/disk[0-9]+)[\s]+(\/Volumes\/[A-Za-z0-9_-]+)/
|
17
|
-
disks.last[:path] = Regexp.last_match[2].strip
|
18
|
-
disks.last[:device] = Regexp.last_match[1].strip
|
19
|
-
elsif line =~ /^blockcount[\s]+:[\s]+([0-9]+)/
|
20
|
-
size_in_mb = Regexp.last_match[1].to_i / 2048
|
21
|
-
disks.last[:size] = Filesize.from("#{size_in_mb} MB")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
disks.map { |d| Instance.new(self, d) if d.has_key? :is_ram_disk }.compact
|
26
|
-
end
|
27
|
-
|
28
|
-
def create(size)
|
29
|
-
size = Filesize.from(size) if size.is_a? String
|
30
|
-
raise NotEnoughFreeRamException.new unless enough_ram? size
|
31
|
-
|
32
|
-
# Allocate new RAM space
|
33
|
-
line = Cocaine::CommandLine.new("hdiutil", "attach -nomount ram://#{(size.to('MB') * 2048).to_i}")
|
34
|
-
device = line.run
|
35
|
-
device.strip!
|
36
|
-
|
37
|
-
# Format RAM disk
|
38
|
-
line = Cocaine::CommandLine.new("diskutil", "erasevolume HFS+ '#{Instance.generate_name}' #{device}")
|
39
|
-
line.run
|
40
|
-
|
41
|
-
# Receive all disk and select just created one
|
42
|
-
list().select { |disk| disk.device == device }.first
|
43
|
-
end
|
44
|
-
|
45
|
-
def destroy(instance)
|
46
|
-
return false unless File.exist? instance.device
|
47
|
-
|
48
|
-
line = Cocaine::CommandLine.new("hdiutil", "detach :device")
|
49
|
-
line.run(device: instance.device)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def enough_ram?(size)
|
54
|
-
size = Filesize.from(size) if size.is_a? String
|
55
|
-
pages_free = 0
|
56
|
-
page_size = 0
|
57
|
-
|
58
|
-
line = Cocaine::CommandLine.new("vm_stat")
|
59
|
-
line.run.each_line do |line|
|
60
|
-
if line =~ /^Pages free:[\s]+([0-9]+)./
|
61
|
-
pages_free = Regexp.last_match[1].to_i
|
62
|
-
elsif line =~ /^Mach Virtual Memory Statistics: +\(page size of ([0-9]+) bytes\)/
|
63
|
-
page_size = Regexp.last_match[1].to_i
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
Filesize.new(pages_free * page_size) > size
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Ramdo
|
2
|
-
module Ramdisk
|
3
|
-
class GenericWrapper
|
4
|
-
def initialize
|
5
|
-
@tmp_path = '/tmp'
|
6
|
-
raise GeneralRamdiskException.new("tmp path not found") unless @tmp_path && Dir.exist?(@tmp_path)
|
7
|
-
end
|
8
|
-
|
9
|
-
def list
|
10
|
-
disks = []
|
11
|
-
Dir.glob(@tmp_path + '/*').each do |dir|
|
12
|
-
if dir.split(File::SEPARATOR).last =~ Instance::NAME_PATTERN
|
13
|
-
disks << Instance.new(self, path: dir, device: @tmp_path, size: Filesize.from("1 GB"))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
disks
|
18
|
-
end
|
19
|
-
|
20
|
-
def create(size)
|
21
|
-
# Create new directory as dedicated space
|
22
|
-
path = [@tmp_path, Instance.generate_name].join('/')
|
23
|
-
Dir.mkdir(path)
|
24
|
-
|
25
|
-
# Receive all disk and select just created one
|
26
|
-
list().select { |disk| disk.path == path }.first
|
27
|
-
end
|
28
|
-
|
29
|
-
def destroy(instance)
|
30
|
-
return false unless Dir.exist? instance.path
|
31
|
-
FileUtils.rm_r instance.path, :force => true
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
def enough_ram?(size)
|
36
|
-
# As the generic wrapper does not use RAM always return true
|
37
|
-
true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Ramdo
|
2
|
-
module Ramdisk
|
3
|
-
class Instance
|
4
|
-
NAME_PATTERN = /^ramdo_disk_([a-z0-9]+)$/
|
5
|
-
|
6
|
-
def self.generate_name
|
7
|
-
"ramdo_disk_#{SecureRandom.hex(4)}"
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_accessor :device, :path, :size
|
11
|
-
|
12
|
-
def initialize(wrapper, info = {})
|
13
|
-
@wrapper = wrapper
|
14
|
-
@device = info[:device]
|
15
|
-
@path = info[:path]
|
16
|
-
@size = info[:size]
|
17
|
-
end
|
18
|
-
|
19
|
-
def destroy!
|
20
|
-
@wrapper.destroy self
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Ramdo
|
2
|
-
module Ramdisk
|
3
|
-
class LinuxWrapper
|
4
|
-
def initialize
|
5
|
-
line = Cocaine::CommandLine.new("cat", "/proc/mounts")
|
6
|
-
line.run.each_line do |line|
|
7
|
-
@shm_path = Regexp.last_match[1] if line =~ /(\/[a-z]+\/shm)[\s]tmpfs[\s]rw/
|
8
|
-
end
|
9
|
-
raise GeneralRamdiskException.new("shm path not found") unless @shm_path
|
10
|
-
end
|
11
|
-
|
12
|
-
def list
|
13
|
-
disks = []
|
14
|
-
Dir.glob(@shm_path + '/*').each do |dir|
|
15
|
-
if dir.split(File::SEPARATOR).last =~ Instance::NAME_PATTERN
|
16
|
-
disks << Instance.new(self, path: dir, device: @shm_path, size: Filesize.from("1 GB"))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
disks
|
21
|
-
end
|
22
|
-
|
23
|
-
def create(size)
|
24
|
-
size = Filesize.from(size) if size.is_a? String
|
25
|
-
raise NotEnoughFreeRamException.new unless enough_ram? size
|
26
|
-
|
27
|
-
# Create new directory as dedicated space
|
28
|
-
path = [@shm_path, Instance.generate_name].join('/')
|
29
|
-
Dir.mkdir(path)
|
30
|
-
|
31
|
-
# Receive all disk and select just created one
|
32
|
-
list().select { |disk| disk.path == path }.first
|
33
|
-
end
|
34
|
-
|
35
|
-
def destroy(instance)
|
36
|
-
return false unless File.exist? instance.path
|
37
|
-
FileUtils.rm_r instance.path, :force => true
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
def enough_ram?(size)
|
42
|
-
size = Filesize.from(size) if size.is_a? String
|
43
|
-
free_mem = ""
|
44
|
-
|
45
|
-
line = Cocaine::CommandLine.new("cat", "/proc/meminfo")
|
46
|
-
line.run.each_line do |line|
|
47
|
-
if line =~ /^MemFree:[\s]+([0-9]+ kB)/
|
48
|
-
free_mem = Regexp.last_match[1]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
Filesize.from(free_mem) > size
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/spec/darwin_wrapper_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include Ramdo
|
4
|
-
describe Ramdisk::DarwinWrapper, if: os?(/darwin/) do
|
5
|
-
before(:each) do
|
6
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
7
|
-
wrapper.list.each do |disk|
|
8
|
-
disk.destroy!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
it 'should check if a ramdisk already exists' do
|
14
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
15
|
-
disks = wrapper.list
|
16
|
-
expect(disks).to be_an(Array)
|
17
|
-
expect(disks.length).to be_a(Integer)
|
18
|
-
expect(disks.length).to be(0)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should check if enough RAM space is free' do
|
22
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
23
|
-
expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
|
24
|
-
expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should create a new RAM disk and save a file to it' do
|
28
|
-
size = '100 MB'
|
29
|
-
|
30
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
31
|
-
disk = wrapper.create(size)
|
32
|
-
|
33
|
-
expect(disk).to be_an(Ramdisk::Instance)
|
34
|
-
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should remove a RAM disk' do
|
38
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
39
|
-
disk = wrapper.create('100 MB')
|
40
|
-
|
41
|
-
count = wrapper.list.length
|
42
|
-
expect(disk.destroy!).to be_truthy
|
43
|
-
expect(disk.destroy!).to be_falsey # Should not work another time
|
44
|
-
|
45
|
-
expect(wrapper.list.length).to be(count - 1)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should list all available RAM disks' do
|
49
|
-
wrapper = Ramdisk::DarwinWrapper.new
|
50
|
-
disk = wrapper.create('100 MB')
|
51
|
-
|
52
|
-
list = wrapper.list
|
53
|
-
expect(list.length).to eq(1)
|
54
|
-
expect(list.first.device).not_to be_empty
|
55
|
-
expect(File.exist?(list.first.device)).to be_truthy
|
56
|
-
expect(Dir.exist?(list.first.path)).to be_truthy
|
57
|
-
|
58
|
-
disk = wrapper.create('200 MB')
|
59
|
-
|
60
|
-
list = wrapper.list
|
61
|
-
expect(list.length).to eq(2)
|
62
|
-
expect(list.last.device).not_to be_empty
|
63
|
-
expect(File.exist?(list.last.device)).to be_truthy
|
64
|
-
expect(Dir.exist?(list.last.path)).to be_truthy
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include Ramdo
|
4
|
-
describe Ramdisk::GenericWrapper, focus: true do
|
5
|
-
before(:each) do
|
6
|
-
wrapper = Ramdisk::GenericWrapper.new
|
7
|
-
wrapper.list.each do |disk|
|
8
|
-
disk.destroy!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
it 'should check if a ramdisk already exists' do
|
14
|
-
wrapper = Ramdisk::GenericWrapper.new
|
15
|
-
disks = wrapper.list
|
16
|
-
expect(disks).to be_an(Array)
|
17
|
-
expect(disks.length).to be_a(Integer)
|
18
|
-
expect(disks.length).to be(0)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should create a new disk and save a file to it' do
|
22
|
-
size = '100 MB'
|
23
|
-
|
24
|
-
wrapper = Ramdisk::GenericWrapper.new
|
25
|
-
disk = wrapper.create(size)
|
26
|
-
|
27
|
-
expect(disk).to be_an(Ramdisk::Instance)
|
28
|
-
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should remove a RAM disk' do
|
32
|
-
wrapper = Ramdisk::GenericWrapper.new
|
33
|
-
disk = wrapper.create('100 MB')
|
34
|
-
|
35
|
-
count = wrapper.list.length
|
36
|
-
expect(disk.destroy!).to be_truthy
|
37
|
-
expect(disk.destroy!).to be_falsey # Should not work another time
|
38
|
-
|
39
|
-
expect(wrapper.list.length).to be(count - 1)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should list all available RAM disks' do
|
43
|
-
wrapper = Ramdisk::GenericWrapper.new
|
44
|
-
disk = wrapper.create('100 MB')
|
45
|
-
|
46
|
-
list = wrapper.list
|
47
|
-
expect(list.length).to eq(1)
|
48
|
-
expect(list.first.device).not_to be_empty
|
49
|
-
expect(File.exist?(list.first.device)).to be_truthy
|
50
|
-
expect(Dir.exist?(list.first.path)).to be_truthy
|
51
|
-
|
52
|
-
disk = wrapper.create('200 MB')
|
53
|
-
|
54
|
-
list = wrapper.list
|
55
|
-
expect(list.length).to eq(2)
|
56
|
-
expect(list.last.device).not_to be_empty
|
57
|
-
expect(File.exist?(list.last.device)).to be_truthy
|
58
|
-
expect(Dir.exist?(list.last.path)).to be_truthy
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
data/spec/linux_wrapper_spec.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include Ramdo
|
4
|
-
describe Ramdisk::LinuxWrapper, if: os?(/linux/) do
|
5
|
-
before(:each) do
|
6
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
7
|
-
wrapper.list.each do |disk|
|
8
|
-
disk.destroy!
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
it 'should check if a ramdisk already exists' do
|
14
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
15
|
-
disks = wrapper.list
|
16
|
-
expect(disks).to be_an(Array)
|
17
|
-
expect(disks.length).to be_a(Integer)
|
18
|
-
expect(disks.length).to be(0)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should check if enough RAM space is free' do
|
22
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
23
|
-
expect(wrapper.send(:enough_ram?, '100 MB')).to be_truthy
|
24
|
-
expect(wrapper.send(:enough_ram?, '100 GB')).to be_falsey
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should create a new RAM disk and save a file to it' do
|
28
|
-
size = '100 MB'
|
29
|
-
|
30
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
31
|
-
disk = wrapper.create(size)
|
32
|
-
|
33
|
-
expect(disk).to be_an(Ramdisk::Instance)
|
34
|
-
expect { IO.write("#{disk.path}/test.bin", IO.read('/dev/urandom', 100000)) }.not_to raise_error
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should remove a RAM disk' do
|
38
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
39
|
-
disk = wrapper.create('100 MB')
|
40
|
-
|
41
|
-
count = wrapper.list.length
|
42
|
-
expect(disk.destroy!).to be_truthy
|
43
|
-
expect(disk.destroy!).to be_falsey # Should not work another time
|
44
|
-
|
45
|
-
expect(wrapper.list.length).to be(count - 1)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should list all available RAM disks' do
|
49
|
-
wrapper = Ramdisk::LinuxWrapper.new
|
50
|
-
disk = wrapper.create('100 MB')
|
51
|
-
|
52
|
-
list = wrapper.list
|
53
|
-
expect(list.length).to eq(1)
|
54
|
-
expect(list.first.device).not_to be_empty
|
55
|
-
expect(File.exist?(list.first.device)).to be_truthy
|
56
|
-
expect(Dir.exist?(list.first.path)).to be_truthy
|
57
|
-
|
58
|
-
disk = wrapper.create('200 MB')
|
59
|
-
|
60
|
-
list = wrapper.list
|
61
|
-
expect(list.length).to eq(2)
|
62
|
-
expect(list.last.device).not_to be_empty
|
63
|
-
expect(File.exist?(list.last.device)).to be_truthy
|
64
|
-
expect(Dir.exist?(list.last.path)).to be_truthy
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include Ramdo
|
4
|
-
describe Ramdisk::Factory do
|
5
|
-
|
6
|
-
it 'should receive wrapper for the current OS' do
|
7
|
-
wrapper = Ramdisk::Factory.get
|
8
|
-
|
9
|
-
if RUBY_PLATFORM =~ /linux/
|
10
|
-
expect(wrapper).to be_a(Ramdisk::LinuxWrapper)
|
11
|
-
elsif RUBY_PLATFORM =~ /darwin/
|
12
|
-
expect(wrapper).to be_a(Ramdisk::DarwinWrapper)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|