torigoya_kit 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d4f04b119248b9626c36d386acf2a58cbebf981
4
- data.tar.gz: c7927f74006ab262a6a22170dae8cc7fa005e93a
3
+ metadata.gz: 0aa0f7efd0c88bda5d262a9f2c42ee3c3388f5b6
4
+ data.tar.gz: 2009f7b75e8a64d10dd2bda8cd5ff60194b29760
5
5
  SHA512:
6
- metadata.gz: e437399ea10d5d32f3bfe18817d3496f12f03983156d081b36fcc677b8c489a60ccdc6cb67c9b7d487c296d579345b13a70f18e10fb0729a34d2464a077b151d
7
- data.tar.gz: ed6c43ba3742d282910d534b2fa668bb4fcfdc885b0875f979cf2a075d1960e8918080697a10fa9f46238c162d70f58e5750d09772fa6d3e7d0b5ab5b6d2cb80
6
+ metadata.gz: ccd1fb54a675325055769b58e82e6eec137de1046e659920b204cded3ea4b772cc19e0e531039749dc44e268d19558cd3279587cb19752ce2ba09e2363e20afc
7
+ data.tar.gz: 604ba0afdd976e90bf39c39dc550603cc9d37d6158bc3cb98921b22343b7db4733e5be3b4240b4f123cfe7c9dfcb603bfa3e5446b74ce0898617fdf42e5e3cf4
@@ -30,20 +30,71 @@ module TorigoyaKit
30
30
  def to_msgpack(out = '')
31
31
  return to_tuple.to_msgpack(out)
32
32
  end
33
+
34
+ def ==(rhs)
35
+ return @name == rhs.name &&
36
+ @code == rhs.code &&
37
+ @is_compressed && rhs.is_compressed
38
+ end
39
+
40
+ private
41
+ def validate
42
+ raise InvalidFormatError.new("name must be String") unless @name.is_a?(String)
43
+ raise InvalidFormatError.new("code must be String") unless @code.is_a?(String)
44
+ raise InvalidFormatError.new("is_compressed must be Boolean") unless @is_compressed.is_a?(TrueClass) && @is_compressed.is_a?(FalseClass)
45
+ end
46
+ end
47
+
48
+ #
49
+ class Command
50
+ def initialize(key_or_value, value=nil)
51
+ unless value.nil?
52
+ @key = key_or_value
53
+ @value = value
54
+ else
55
+ @value = key_or_value
56
+ end
57
+
58
+ validate
59
+ end
60
+ attr_reader :key, :value
61
+
62
+ def to_tuple
63
+ unless @key.nil?
64
+ return [@key, @value]
65
+ else
66
+ return [@value]
67
+ end
68
+ end
69
+
70
+ def ==(rhs)
71
+ return @key == rhs.key && @value == rhs.value
72
+ end
73
+
74
+ private
75
+ def validate
76
+ unless @key.nil?
77
+ raise InvalidFormatError.new("key must be String") unless @key.is_a?(String)
78
+ end
79
+ raise InvalidFormatError.new("value must be String") unless @value.is_a?(String)
80
+ end
33
81
  end
34
82
 
35
83
  #
36
84
  class ExecutionSetting
37
85
  def initialize(command_line, structured_command, cpu_limit, memory_limit)
38
86
  @command_line = command_line # String
39
- @structured_command = structured_command # Array!(Array!String)
87
+ @structured_command = structured_command # Array!Command
40
88
  @cpu_limit = cpu_limit # uint64 / sec
41
89
  @memory_limit = memory_limit # uint64 / bytes
90
+
91
+ validate
42
92
  end
93
+ attr_reader :command_line, :structured_command, :cpu_limit, :memory_limit
43
94
 
44
95
  def to_tuple
45
96
  return [@command_line,
46
- @structured_command,
97
+ @structured_command.map {|x| x.to_tuple},
47
98
  @cpu_limit,
48
99
  @memory_limit
49
100
  ]
@@ -52,6 +103,34 @@ module TorigoyaKit
52
103
  def to_msgpack(out = '')
53
104
  return to_tuple.to_msgpack(out)
54
105
  end
106
+
107
+ def ==(rhs)
108
+ return @command_line == rhs.command_line &&
109
+ @structured_command == rhs.structured_command &&
110
+ @cpu_limit == rhs.cpu_limit &&
111
+ @memory_limit == rhs.memory_limit
112
+ end
113
+
114
+ private
115
+ def validate
116
+ unless @command_line.nil?
117
+ raise InvalidFormatError.new("type of command_line must be String") unless @command_line.is_a?(String)
118
+ else
119
+ @command_line = ""
120
+ end
121
+
122
+ unless @structured_command.nil?
123
+ raise InvalidFormatError.new("type of structured_command must be Array") unless @structured_command.is_a?(Array)
124
+ @structured_command.each do |e|
125
+ raise InvalidFormatError.new("type of element of structured_command must be Command") unless e.is_a?(Command)
126
+ end
127
+ else
128
+ @structured_command = []
129
+ end
130
+
131
+ raise InvalidFormatError.new("type of cpu_limit must be Integer") unless @cpu_limit.is_a?(Integer)
132
+ raise InvalidFormatError.new("type of memory_limit must be Integer") unless @memory_limit.is_a?(Integer)
133
+ end
55
134
  end
56
135
 
57
136
  #
@@ -59,7 +138,10 @@ module TorigoyaKit
59
138
  def initialize(compile_setting, link_setting)
60
139
  @compile_setting = compile_setting # ExecutionSetting
61
140
  @link_setting = link_setting # ExecutionSetting
141
+
142
+ validate
62
143
  end
144
+ attr_reader :compile_setting, :link_setting
63
145
 
64
146
  def to_tuple
65
147
  return [@compile_setting.to_tuple,
@@ -70,6 +152,17 @@ module TorigoyaKit
70
152
  def to_msgpack(out = '')
71
153
  return to_tuple.to_msgpack(out)
72
154
  end
155
+
156
+ def ==(rhs)
157
+ return @compile_setting == rhs.compile_setting &&
158
+ @link_setting == rhs.link_setting
159
+ end
160
+
161
+ private
162
+ def validate()
163
+ raise InvalidFormatError.new("type of compile_setting must be ExecutionSetting") unless @compile_setting.is_a?(ExecutionSetting)
164
+ raise InvalidFormatError.new("type of link_setting must be ExecutionSetting") unless @link_setting.is_a?(ExecutionSetting)
165
+ end
73
166
  end
74
167
 
75
168
  #
@@ -77,7 +170,10 @@ module TorigoyaKit
77
170
  def initialize(stdin, run_setting)
78
171
  @stdin = stdin # SourceData
79
172
  @run_setting = run_setting # ExecutionSetting
173
+
174
+ validate
80
175
  end
176
+ attr_reader :stdin, :run_setting
81
177
 
82
178
  def to_tuple
83
179
  return [@stdin, @run_setting]
@@ -86,13 +182,29 @@ module TorigoyaKit
86
182
  def to_msgpack(out = '')
87
183
  return to_tuple.to_msgpack(out)
88
184
  end
185
+
186
+ def ==(rhs)
187
+ return @stdin == rhs.stdin &&
188
+ @run_settings == rhs.run_settings
189
+ end
190
+
191
+ private
192
+ def validate()
193
+ unless @stdin.nil?
194
+ raise InvalidFormatError.new("type of stdin must be SourceData") unless @stdin.is_a?(SourceData)
195
+ end
196
+ raise InvalidFormatError.new("type of run_setting must be ExecutionSetting") unless @run_setting.is_a?(ExecutionSetting)
197
+ end
89
198
  end
90
199
 
91
200
  #
92
201
  class RunInstruction
93
202
  def initialize(inputs)
94
203
  @inputs = inputs # Array!Input
204
+
205
+ validate
95
206
  end
207
+ attr_reader :inputs
96
208
 
97
209
  def to_tuple
98
210
  return [@inputs.map {|x| x.to_tuple}]
@@ -101,6 +213,18 @@ module TorigoyaKit
101
213
  def to_msgpack(out = '')
102
214
  return to_tuple.to_msgpack(out)
103
215
  end
216
+
217
+ def ==(rhs)
218
+ return @inputs == rhs.inputs
219
+ end
220
+
221
+ private
222
+ def validate()
223
+ raise InvalidFormatError.new("type of inputs must be Array") unless @inputs.is_a?(Array)
224
+ @inputs.each do |e|
225
+ raise InvalidFormatError.new("type of element of inputs must be Input") unless e.is_a?(Input)
226
+ end
227
+ end
104
228
  end
105
229
 
106
230
  #
@@ -112,7 +236,10 @@ module TorigoyaKit
112
236
  @source_codes = source_codes # Array!SourceData
113
237
  @build_inst = build_inst # BuildInstruction
114
238
  @run_inst = run_inst # RunInstruction
239
+
240
+ validate
115
241
  end
242
+ attr_reader :base_name, :proc_id, :proc_version, :source_codes, :build_inst, :run_inst
116
243
 
117
244
  def to_tuple
118
245
  return [@base_name,
@@ -127,6 +254,34 @@ module TorigoyaKit
127
254
  def to_msgpack
128
255
  return to_tuple.to_msgpack()
129
256
  end
257
+
258
+ def ==(rhs)
259
+ return @base_name == rhs.base_name &&
260
+ @proc_id == rhs.proc_id &&
261
+ @proc_version == rhs.proc_version &&
262
+ @source_codes == rhs.source_codes &&
263
+ @build_inst == rhs.build_inst &&
264
+ @run_inst == rhs.run_inst
265
+ end
266
+
267
+ private
268
+ def validate()
269
+ raise InvalidFormatError.new("type of base_name must be String") unless @base_name.is_a?(String)
270
+ raise InvalidFormatError.new("type of proc_id must be Integer") unless @proc_id.is_a?(Integer)
271
+ raise InvalidFormatError.new("type of proc_version must be String") unless @proc_version.is_a?(String)
272
+ raise InvalidFormatError.new("type of source_codes must be Array") unless @source_codes.is_a?(Array)
273
+ @source_codes.each do |e|
274
+ raise InvalidFormatError.new("type of element of source_codes must be SourceData") unless e.is_a?(SourceData)
275
+ end
276
+ raise InvalidFormatError.new("type of build_inst must be BuildInstruction") unless @build_inst.is_a?(BuildInstruction)
277
+ raise InvalidFormatError.new("type of run_inst must be RunInstruction") unless @run_inst.is_a?(RunInstruction)
278
+ end
130
279
  end
131
280
 
281
+
282
+ class InvalidFormatError < StandardError
283
+ def initialize(*args)
284
+ super(*args)
285
+ end
286
+ end
132
287
  end # module TorigoyaKit
@@ -1,3 +1,3 @@
1
1
  module TorigoyaKit
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -5,7 +5,7 @@ require_relative '../spec_helper'
5
5
  describe :session do
6
6
  it "session proc exec_ticket" do
7
7
  s = TorigoyaKit::Session.new("localhost", 49800)
8
- p s.exec_ticket(make_ticket())
8
+ # p s.exec_ticket(make_ticket())
9
9
  end
10
10
 
11
11
  it "session proc update_proc_table" do
@@ -6,10 +6,76 @@ describe :ticket do
6
6
  ticket = make_ticket()
7
7
 
8
8
  it "aaa" do
9
- expect(ticket).not_to eq nil
9
+ expect(ticket).not_to be nil
10
10
  end
11
11
 
12
12
  it "aaa" do
13
13
  expect(ticket.to_msgpack).not_to eq nil
14
14
  end
15
+
16
+ #
17
+ dummy_es = TorigoyaKit::ExecutionSetting.new("", [], 0, 0)
18
+ dummy_bi = TorigoyaKit::BuildInstruction.new(dummy_es, dummy_es)
19
+ dummy_ri = TorigoyaKit::RunInstruction.new([])
20
+
21
+ it "construct ticket" do
22
+ expect do
23
+ TorigoyaKit::Ticket.new(nil, nil, nil, nil, nil, nil)
24
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
25
+
26
+ expect do
27
+ TorigoyaKit::Ticket.new("", nil, nil, nil, nil, nil)
28
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
29
+
30
+ expect do
31
+ TorigoyaKit::Ticket.new("", 0, nil, nil, nil, nil)
32
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
33
+
34
+ expect do
35
+ TorigoyaKit::Ticket.new("", 0, "", nil, nil, nil)
36
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
37
+
38
+ expect do
39
+ TorigoyaKit::Ticket.new("", 0, "", [], nil, nil)
40
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
41
+
42
+ expect do
43
+ TorigoyaKit::Ticket.new("", 0, "", [], dummy_bi, nil)
44
+ end.to raise_error(TorigoyaKit::InvalidFormatError)
45
+
46
+ expect do
47
+ TorigoyaKit::Ticket.new("", 0, "", [], dummy_bi, dummy_ri)
48
+ end.to_not raise_error
49
+ end
50
+
51
+ it "construct execution setting" do
52
+ commands = [TorigoyaKit::Command.new("A=", "B"),
53
+ TorigoyaKit::Command.new("unit")
54
+ ]
55
+ expected = TorigoyaKit::ExecutionSetting.new("test command", commands, 100, 200)
56
+
57
+ commands_dummy = [TorigoyaKit::Command.new("A=", "B"),
58
+ TorigoyaKit::Command.new("unit")
59
+ ]
60
+ expected_dummy = TorigoyaKit::ExecutionSetting.new("test command", commands, 100, 200)
61
+
62
+ expect(expected).to eq expected_dummy
63
+ end
64
+
65
+ it "setting" do
66
+ expected_es = TorigoyaKit::ExecutionSetting.new("", [], 0, 0)
67
+ expect(expected_es).to eq dummy_es
68
+ end
69
+
70
+ it "build inst" do
71
+ expected_es = TorigoyaKit::ExecutionSetting.new("", [], 0, 0)
72
+ expected_bi = TorigoyaKit::BuildInstruction.new(expected_es, expected_es)
73
+
74
+ expect(expected_bi).to eq dummy_bi
75
+ end
76
+
77
+ it "run inst" do
78
+ expected_ri = TorigoyaKit::RunInstruction.new([])
79
+ expect(expected_ri).to eq dummy_ri
80
+ end
15
81
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torigoya_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yutopp