Class: TestRunner::TestResources
- Inherits:
-
Object
- Object
- TestRunner::TestResources
- Defined in:
- lib/test-runner/test_resources.rb
Instance Attribute Summary collapse
- #cpus ⇒ Integer readonly
- #machines ⇒ Integer readonly
- #max_machine_memory_mib ⇒ Integer readonly
- #memory_mib ⇒ Integer readonly
- #shm_mib ⇒ Integer readonly
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #format_mib(value) ⇒ Object protected
-
#initialize(machines: 0, memory_mib: 0, shm_mib: memory_mib, max_machine_memory_mib: 0, cpus: 0) ⇒ TestResources
constructor
A new instance of TestResources.
- #summary ⇒ Object
- #zero? ⇒ Boolean
Constructor Details
#initialize(machines: 0, memory_mib: 0, shm_mib: memory_mib, max_machine_memory_mib: 0, cpus: 0) ⇒ TestResources
Returns a new instance of TestResources.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/test-runner/test_resources.rb', line 35 def initialize( machines: 0, memory_mib: 0, shm_mib: memory_mib, max_machine_memory_mib: 0, cpus: 0 ) @machines = machines @memory_mib = memory_mib @shm_mib = shm_mib @max_machine_memory_mib = max_machine_memory_mib @cpus = cpus end |
Instance Attribute Details
#cpus ⇒ Integer (readonly)
16 17 18 |
# File 'lib/test-runner/test_resources.rb', line 16 def cpus @cpus end |
#machines ⇒ Integer (readonly)
4 5 6 |
# File 'lib/test-runner/test_resources.rb', line 4 def machines @machines end |
#max_machine_memory_mib ⇒ Integer (readonly)
13 14 15 |
# File 'lib/test-runner/test_resources.rb', line 13 def max_machine_memory_mib @max_machine_memory_mib end |
#memory_mib ⇒ Integer (readonly)
7 8 9 |
# File 'lib/test-runner/test_resources.rb', line 7 def memory_mib @memory_mib end |
#shm_mib ⇒ Integer (readonly)
10 11 12 |
# File 'lib/test-runner/test_resources.rb', line 10 def shm_mib @shm_mib end |
Class Method Details
.from_h(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/test-runner/test_resources.rb', line 18 def self.from_h(data) data ||= {} memory_mib = data.fetch('memoryMiB', data.fetch(:memory_mib, 0)).to_i new( machines: data.fetch('machines', 0).to_i, memory_mib:, shm_mib: data.fetch('shmMiB', data.fetch(:shm_mib, memory_mib)).to_i, max_machine_memory_mib: data.fetch( 'maxMachineMemoryMiB', data.fetch(:max_machine_memory_mib, 0) ).to_i, cpus: data.fetch('cpus', 0).to_i ) end |
Instance Method Details
#+(other) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/test-runner/test_resources.rb', line 49 def +(other) self.class.new( machines: machines + other.machines, memory_mib: memory_mib + other.memory_mib, shm_mib: shm_mib + other.shm_mib, max_machine_memory_mib: [max_machine_memory_mib, other.max_machine_memory_mib].max, cpus: cpus + other.cpus ) end |
#-(other) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/test-runner/test_resources.rb', line 59 def -(other) self.class.new( machines: machines - other.machines, memory_mib: memory_mib - other.memory_mib, shm_mib: shm_mib - other.shm_mib, max_machine_memory_mib: max_machine_memory_mib, cpus: cpus - other.cpus ) end |
#format_mib(value) ⇒ Object (protected)
80 81 82 83 84 |
# File 'lib/test-runner/test_resources.rb', line 80 def format_mib(value) return "#{value} MiB" if value < 1024 format('%.1f GiB', value / 1024.0) end |
#summary ⇒ Object
73 74 75 76 |
# File 'lib/test-runner/test_resources.rb', line 73 def summary "machines=#{machines}, memory=#{format_mib(memory_mib)}, " \ "shm=#{format_mib(shm_mib)}, cpus=#{cpus}" end |
#zero? ⇒ Boolean
69 70 71 |
# File 'lib/test-runner/test_resources.rb', line 69 def zero? machines <= 0 && memory_mib <= 0 && shm_mib <= 0 && cpus <= 0 end |