cuboid 0.0.0 → 0.0.1alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +0 -0
- data/Gemfile +20 -5
- data/LICENSE.md +22 -0
- data/README.md +158 -19
- data/Rakefile +56 -3
- data/config/paths.yml +15 -0
- data/cuboid.gemspec +61 -23
- data/lib/cuboid.rb +96 -4
- data/lib/cuboid/application.rb +326 -0
- data/lib/cuboid/application/parts/data.rb +18 -0
- data/lib/cuboid/application/parts/report.rb +29 -0
- data/lib/cuboid/application/parts/state.rb +274 -0
- data/lib/cuboid/application/runtime.rb +25 -0
- data/lib/cuboid/banner.rb +13 -0
- data/lib/cuboid/data.rb +86 -0
- data/lib/cuboid/data/application.rb +52 -0
- data/lib/cuboid/error.rb +9 -0
- data/lib/cuboid/option_group.rb +129 -0
- data/lib/cuboid/option_groups.rb +8 -0
- data/lib/cuboid/option_groups/datastore.rb +23 -0
- data/lib/cuboid/option_groups/dispatcher.rb +38 -0
- data/lib/cuboid/option_groups/output.rb +14 -0
- data/lib/cuboid/option_groups/paths.rb +184 -0
- data/lib/cuboid/option_groups/report.rb +39 -0
- data/lib/cuboid/option_groups/rpc.rb +105 -0
- data/lib/cuboid/option_groups/scheduler.rb +27 -0
- data/lib/cuboid/option_groups/snapshot.rb +13 -0
- data/lib/cuboid/option_groups/system.rb +10 -0
- data/lib/cuboid/options.rb +254 -0
- data/lib/cuboid/processes.rb +13 -0
- data/lib/cuboid/processes/dispatchers.rb +140 -0
- data/lib/cuboid/processes/executables/base.rb +54 -0
- data/lib/cuboid/processes/executables/dispatcher.rb +5 -0
- data/lib/cuboid/processes/executables/instance.rb +12 -0
- data/lib/cuboid/processes/executables/rest_service.rb +13 -0
- data/lib/cuboid/processes/executables/scheduler.rb +5 -0
- data/lib/cuboid/processes/helpers.rb +4 -0
- data/lib/cuboid/processes/helpers/dispatchers.rb +23 -0
- data/lib/cuboid/processes/helpers/instances.rb +39 -0
- data/lib/cuboid/processes/helpers/processes.rb +23 -0
- data/lib/cuboid/processes/helpers/schedulers.rb +23 -0
- data/lib/cuboid/processes/instances.rb +203 -0
- data/lib/cuboid/processes/manager.rb +262 -0
- data/lib/cuboid/processes/schedulers.rb +128 -0
- data/lib/cuboid/report.rb +220 -0
- data/lib/cuboid/rest/server.rb +165 -0
- data/lib/cuboid/rest/server/instance_helpers.rb +99 -0
- data/lib/cuboid/rest/server/routes/dispatcher.rb +41 -0
- data/lib/cuboid/rest/server/routes/grid.rb +41 -0
- data/lib/cuboid/rest/server/routes/instances.rb +131 -0
- data/lib/cuboid/rest/server/routes/scheduler.rb +140 -0
- data/lib/cuboid/rpc/client.rb +3 -0
- data/lib/cuboid/rpc/client/base.rb +58 -0
- data/lib/cuboid/rpc/client/dispatcher.rb +58 -0
- data/lib/cuboid/rpc/client/instance.rb +100 -0
- data/lib/cuboid/rpc/client/instance/service.rb +37 -0
- data/lib/cuboid/rpc/client/scheduler.rb +46 -0
- data/lib/cuboid/rpc/serializer.rb +92 -0
- data/lib/cuboid/rpc/server/active_options.rb +38 -0
- data/lib/cuboid/rpc/server/application_wrapper.rb +138 -0
- data/lib/cuboid/rpc/server/base.rb +63 -0
- data/lib/cuboid/rpc/server/dispatcher.rb +317 -0
- data/lib/cuboid/rpc/server/dispatcher/node.rb +247 -0
- data/lib/cuboid/rpc/server/dispatcher/service.rb +145 -0
- data/lib/cuboid/rpc/server/instance.rb +338 -0
- data/lib/cuboid/rpc/server/output.rb +92 -0
- data/lib/cuboid/rpc/server/scheduler.rb +482 -0
- data/lib/cuboid/ruby.rb +4 -0
- data/lib/cuboid/ruby/array.rb +17 -0
- data/lib/cuboid/ruby/hash.rb +41 -0
- data/lib/cuboid/ruby/object.rb +32 -0
- data/lib/cuboid/snapshot.rb +186 -0
- data/lib/cuboid/state.rb +94 -0
- data/lib/cuboid/state/application.rb +309 -0
- data/lib/cuboid/state/options.rb +27 -0
- data/lib/cuboid/support.rb +11 -0
- data/lib/cuboid/support/buffer.rb +3 -0
- data/lib/cuboid/support/buffer/autoflush.rb +61 -0
- data/lib/cuboid/support/buffer/base.rb +91 -0
- data/lib/cuboid/support/cache.rb +7 -0
- data/lib/cuboid/support/cache/base.rb +226 -0
- data/lib/cuboid/support/cache/least_cost_replacement.rb +77 -0
- data/lib/cuboid/support/cache/least_recently_pushed.rb +21 -0
- data/lib/cuboid/support/cache/least_recently_used.rb +31 -0
- data/lib/cuboid/support/cache/preference.rb +31 -0
- data/lib/cuboid/support/cache/random_replacement.rb +20 -0
- data/lib/cuboid/support/crypto.rb +2 -0
- data/lib/cuboid/support/crypto/rsa_aes_cbc.rb +86 -0
- data/lib/cuboid/support/database.rb +5 -0
- data/lib/cuboid/support/database/base.rb +177 -0
- data/lib/cuboid/support/database/categorized_queue.rb +195 -0
- data/lib/cuboid/support/database/hash.rb +300 -0
- data/lib/cuboid/support/database/queue.rb +149 -0
- data/lib/cuboid/support/filter.rb +3 -0
- data/lib/cuboid/support/filter/base.rb +110 -0
- data/lib/cuboid/support/filter/set.rb +29 -0
- data/lib/cuboid/support/glob.rb +27 -0
- data/lib/cuboid/support/mixins.rb +8 -0
- data/lib/cuboid/support/mixins/observable.rb +99 -0
- data/lib/cuboid/support/mixins/parts.rb +20 -0
- data/lib/cuboid/support/mixins/profiler.rb +93 -0
- data/lib/cuboid/support/mixins/spec_instances.rb +65 -0
- data/lib/cuboid/support/mixins/terminal.rb +57 -0
- data/lib/cuboid/system.rb +119 -0
- data/lib/cuboid/system/platforms.rb +84 -0
- data/lib/cuboid/system/platforms/linux.rb +26 -0
- data/lib/cuboid/system/platforms/mixins/unix.rb +46 -0
- data/lib/cuboid/system/platforms/osx.rb +25 -0
- data/lib/cuboid/system/platforms/windows.rb +81 -0
- data/lib/cuboid/system/slots.rb +143 -0
- data/lib/cuboid/ui/output.rb +52 -0
- data/lib/cuboid/ui/output_interface.rb +43 -0
- data/lib/cuboid/ui/output_interface/abstract.rb +68 -0
- data/lib/cuboid/ui/output_interface/controls.rb +84 -0
- data/lib/cuboid/ui/output_interface/error_logging.rb +119 -0
- data/lib/cuboid/ui/output_interface/implemented.rb +58 -0
- data/lib/cuboid/ui/output_interface/personalization.rb +62 -0
- data/lib/cuboid/utilities.rb +155 -0
- data/lib/cuboid/version.rb +4 -3
- data/lib/version +1 -0
- data/logs/placeholder +0 -0
- data/spec/cuboid/application/parts/data_spec.rb +12 -0
- data/spec/cuboid/application/parts/report_spec.rb +6 -0
- data/spec/cuboid/application/parts/state_spec.rb +192 -0
- data/spec/cuboid/application/runtime_spec.rb +21 -0
- data/spec/cuboid/application_spec.rb +37 -0
- data/spec/cuboid/data/application_spec.rb +22 -0
- data/spec/cuboid/data_spec.rb +47 -0
- data/spec/cuboid/error_spec.rb +23 -0
- data/spec/cuboid/option_groups/datastore_spec.rb +54 -0
- data/spec/cuboid/option_groups/dispatcher_spec.rb +12 -0
- data/spec/cuboid/option_groups/output_spec.rb +11 -0
- data/spec/cuboid/option_groups/paths_spec.rb +184 -0
- data/spec/cuboid/option_groups/report_spec.rb +26 -0
- data/spec/cuboid/option_groups/rpc_spec.rb +53 -0
- data/spec/cuboid/option_groups/snapshot_spec.rb +26 -0
- data/spec/cuboid/option_groups/system.rb +12 -0
- data/spec/cuboid/options_spec.rb +218 -0
- data/spec/cuboid/report_spec.rb +221 -0
- data/spec/cuboid/rest/server_spec.rb +1205 -0
- data/spec/cuboid/rpc/client/base_spec.rb +151 -0
- data/spec/cuboid/rpc/client/dispatcher_spec.rb +13 -0
- data/spec/cuboid/rpc/client/instance_spec.rb +38 -0
- data/spec/cuboid/rpc/server/active_options_spec.rb +21 -0
- data/spec/cuboid/rpc/server/base_spec.rb +60 -0
- data/spec/cuboid/rpc/server/dispatcher/node_spec.rb +222 -0
- data/spec/cuboid/rpc/server/dispatcher/service_spec.rb +112 -0
- data/spec/cuboid/rpc/server/dispatcher_spec.rb +317 -0
- data/spec/cuboid/rpc/server/instance_spec.rb +307 -0
- data/spec/cuboid/rpc/server/output_spec.rb +32 -0
- data/spec/cuboid/rpc/server/scheduler_spec.rb +400 -0
- data/spec/cuboid/ruby/array_spec.rb +77 -0
- data/spec/cuboid/ruby/hash_spec.rb +63 -0
- data/spec/cuboid/ruby/object_spec.rb +22 -0
- data/spec/cuboid/snapshot_spec.rb +123 -0
- data/spec/cuboid/state/application_spec.rb +538 -0
- data/spec/cuboid/state/options_spec.rb +37 -0
- data/spec/cuboid/state_spec.rb +53 -0
- data/spec/cuboid/support/buffer/autoflush_spec.rb +78 -0
- data/spec/cuboid/support/buffer/base_spec.rb +193 -0
- data/spec/cuboid/support/cache/least_cost_replacement_spec.rb +61 -0
- data/spec/cuboid/support/cache/least_recently_pushed_spec.rb +90 -0
- data/spec/cuboid/support/cache/least_recently_used_spec.rb +80 -0
- data/spec/cuboid/support/cache/preference_spec.rb +37 -0
- data/spec/cuboid/support/cache/random_replacement_spec.rb +42 -0
- data/spec/cuboid/support/crypto/rsa_aes_cbc_spec.rb +28 -0
- data/spec/cuboid/support/database/categorized_queue_spec.rb +327 -0
- data/spec/cuboid/support/database/hash_spec.rb +204 -0
- data/spec/cuboid/support/database/scheduler_spec.rb +325 -0
- data/spec/cuboid/support/filter/set_spec.rb +19 -0
- data/spec/cuboid/support/glob_spec.rb +75 -0
- data/spec/cuboid/support/mixins/observable_spec.rb +95 -0
- data/spec/cuboid/system/platforms/linux_spec.rb +31 -0
- data/spec/cuboid/system/platforms/osx_spec.rb +32 -0
- data/spec/cuboid/system/platforms/windows_spec.rb +41 -0
- data/spec/cuboid/system/slots_spec.rb +202 -0
- data/spec/cuboid/system_spec.rb +105 -0
- data/spec/cuboid/utilities_spec.rb +131 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/factories/placeholder +0 -0
- data/spec/support/factories/scan_report.rb +18 -0
- data/spec/support/fixtures/empty/placeholder +0 -0
- data/spec/support/fixtures/executables/node.rb +50 -0
- data/spec/support/fixtures/mock_app.rb +61 -0
- data/spec/support/fixtures/mock_app/test_service.rb +64 -0
- data/spec/support/fixtures/services/echo.rb +64 -0
- data/spec/support/helpers/framework.rb +3 -0
- data/spec/support/helpers/matchers.rb +5 -0
- data/spec/support/helpers/misc.rb +3 -0
- data/spec/support/helpers/paths.rb +15 -0
- data/spec/support/helpers/request_helpers.rb +38 -0
- data/spec/support/helpers/requires.rb +8 -0
- data/spec/support/helpers/resets.rb +52 -0
- data/spec/support/helpers/web_server.rb +15 -0
- data/spec/support/lib/factory.rb +107 -0
- data/spec/support/lib/web_server_client.rb +41 -0
- data/spec/support/lib/web_server_dispatcher.rb +25 -0
- data/spec/support/lib/web_server_manager.rb +118 -0
- data/spec/support/logs/placeholder +0 -0
- data/spec/support/pems/cacert.pem +37 -0
- data/spec/support/pems/client/cert.pem +37 -0
- data/spec/support/pems/client/foo-cert.pem +39 -0
- data/spec/support/pems/client/foo-key.pem +51 -0
- data/spec/support/pems/client/key.pem +51 -0
- data/spec/support/pems/server/cert.pem +37 -0
- data/spec/support/pems/server/key.pem +51 -0
- data/spec/support/reports/placeholder +0 -0
- data/spec/support/shared/application.rb +10 -0
- data/spec/support/shared/component.rb +31 -0
- data/spec/support/shared/component/options/base.rb +187 -0
- data/spec/support/shared/option_group.rb +98 -0
- data/spec/support/shared/support/cache.rb +419 -0
- data/spec/support/shared/support/filter.rb +143 -0
- data/spec/support/shared/system/platforms/base.rb +25 -0
- data/spec/support/shared/system/platforms/mixins/unix.rb +37 -0
- data/spec/support/snapshots/placeholder +0 -0
- metadata +566 -21
- data/.gitignore +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
@@ -0,0 +1,58 @@
|
|
1
|
+
module Cuboid
|
2
|
+
module UI
|
3
|
+
module OutputInterface
|
4
|
+
|
5
|
+
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
6
|
+
module Implemented
|
7
|
+
|
8
|
+
# Prints the backtrace of an exception as error messages.
|
9
|
+
#
|
10
|
+
# @param [Exception] e
|
11
|
+
def print_error_backtrace( e )
|
12
|
+
e.backtrace.each { |line| print_error( line ) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def print_exception( e )
|
16
|
+
print_error "[#{e.class}] #{e}"
|
17
|
+
print_error_backtrace( e )
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_debug_level_1( str = '' )
|
21
|
+
print_debug( str, 1 )
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_debug_level_2( str = '' )
|
25
|
+
print_debug( str, 2 )
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_debug_level_3( str = '' )
|
29
|
+
print_debug( str, 3 )
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_debug_level_4( str = '' )
|
33
|
+
print_debug( str, 4 )
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_debug_exception( e, level = 1 )
|
37
|
+
return if !debug?
|
38
|
+
|
39
|
+
print_debug( "[#{e.class}] #{e}", level )
|
40
|
+
print_debug_backtrace( e, level )
|
41
|
+
end
|
42
|
+
|
43
|
+
# Prints the backtrace of an exception as debugging messages.
|
44
|
+
#
|
45
|
+
# @param [Exception] e
|
46
|
+
#
|
47
|
+
# @see #debug?
|
48
|
+
# @see #debug
|
49
|
+
def print_debug_backtrace( e, level = 1 )
|
50
|
+
return if !debug?
|
51
|
+
e.backtrace.each { |line| print_debug( line, level ) }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Cuboid
|
2
|
+
module UI
|
3
|
+
module OutputInterface
|
4
|
+
|
5
|
+
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
6
|
+
module Personalization
|
7
|
+
|
8
|
+
def included( base )
|
9
|
+
base.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def personalize_output!
|
14
|
+
@personalize_output = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def personalize_output?
|
18
|
+
@personalize_output
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def personalize_output( message )
|
25
|
+
return message if !self.class.respond_to?( :personalize_output? )
|
26
|
+
|
27
|
+
self.class.personalize_output? ?
|
28
|
+
"#{self.class.name.split('::').last}: #{message}" : message
|
29
|
+
end
|
30
|
+
|
31
|
+
def output_root
|
32
|
+
@output_root ||=
|
33
|
+
File.expand_path( File.dirname( __FILE__ ) + '/../../../../' ) + '/'
|
34
|
+
end
|
35
|
+
|
36
|
+
def caller_location
|
37
|
+
file = nil
|
38
|
+
line = nil
|
39
|
+
caller_method = nil
|
40
|
+
Kernel.caller.each do |c|
|
41
|
+
file, line, method = *c.scan( /(.*):(\d+):in `(?:.*\s)?(.*)'/ ).flatten
|
42
|
+
next if file == output_provider_file
|
43
|
+
|
44
|
+
caller_method = method
|
45
|
+
break
|
46
|
+
end
|
47
|
+
|
48
|
+
file.gsub!( output_root, '' )
|
49
|
+
|
50
|
+
context = nil
|
51
|
+
if caller_method
|
52
|
+
context = "[#{file}##{caller_method}:#{line}]"
|
53
|
+
end
|
54
|
+
|
55
|
+
context
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'digest/sha2'
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module Cuboid
|
6
|
+
|
7
|
+
# Includes some useful methods for the system.
|
8
|
+
#
|
9
|
+
# @author Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>
|
10
|
+
module Utilities
|
11
|
+
|
12
|
+
# @return [String]
|
13
|
+
# Filename (without extension) of the caller.
|
14
|
+
def caller_name
|
15
|
+
File.basename( caller_path( 3 ), '.rb' )
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
# Filepath of the caller.
|
20
|
+
def caller_path( offset = 2 )
|
21
|
+
::Kernel.caller[offset].split( /:(\d+):in/ ).first
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] random HEX (SHA2) string
|
25
|
+
def random_seed
|
26
|
+
@@random_seed ||= generate_token
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Fixnum]
|
30
|
+
# Random available port number.
|
31
|
+
def available_port( range = nil )
|
32
|
+
available_port_mutex.synchronize do
|
33
|
+
loop do
|
34
|
+
port = self.rand_port( range )
|
35
|
+
return port if port_available?( port )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.available_port_mutex
|
41
|
+
@available_port_mutex ||= Mutex.new
|
42
|
+
end
|
43
|
+
available_port_mutex
|
44
|
+
|
45
|
+
# @return [Integer]
|
46
|
+
# Random port within the user specified range.
|
47
|
+
def rand_port( range = nil )
|
48
|
+
range ||= [1025, 65535]
|
49
|
+
first, last = range
|
50
|
+
range = (first..last).to_a
|
51
|
+
|
52
|
+
range[ rand( range.last - range.first ) ]
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_token
|
56
|
+
SecureRandom.hex
|
57
|
+
end
|
58
|
+
|
59
|
+
# Checks whether the port number is available.
|
60
|
+
#
|
61
|
+
# @param [Fixnum] port
|
62
|
+
#
|
63
|
+
# @return [Bool]
|
64
|
+
def port_available?( port )
|
65
|
+
begin
|
66
|
+
socket = ::Socket.new( :INET, :STREAM, 0 )
|
67
|
+
socket.bind( ::Socket.sockaddr_in( port, '127.0.0.1' ) )
|
68
|
+
socket.close
|
69
|
+
true
|
70
|
+
rescue Errno::EADDRINUSE, Errno::EACCES
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param [String, Float, Integer] seconds
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
# Time in `00:00:00` (`hours:minutes:seconds`) format.
|
79
|
+
def seconds_to_hms( seconds )
|
80
|
+
seconds = seconds.to_i
|
81
|
+
[seconds / 3600, seconds / 60 % 60, seconds % 60].
|
82
|
+
map { |t| t.to_s.rjust( 2, '0' ) }.join( ':' )
|
83
|
+
end
|
84
|
+
|
85
|
+
def hms_to_seconds( time )
|
86
|
+
a = [1, 60, 3600] * 2
|
87
|
+
time.split( /[:\.]/ ).map { |t| t.to_i * a.pop }.inject(&:+)
|
88
|
+
rescue
|
89
|
+
0
|
90
|
+
end
|
91
|
+
|
92
|
+
def bytes_to_megabytes( bytes )
|
93
|
+
(bytes / 1024.0 / 1024.0).round( 3 )
|
94
|
+
end
|
95
|
+
|
96
|
+
def bytes_to_kilobytes( bytes )
|
97
|
+
(bytes / 1024.0 ).round( 3 )
|
98
|
+
end
|
99
|
+
|
100
|
+
# Wraps the `block` in exception handling code and runs it.
|
101
|
+
#
|
102
|
+
# @param [Bool] raise_exception
|
103
|
+
# Re-raise exception?
|
104
|
+
# @param [Block] block
|
105
|
+
def exception_jail( raise_exception = true, &block )
|
106
|
+
block.call
|
107
|
+
rescue => e
|
108
|
+
if respond_to?( :print_error ) && respond_to?( :print_exception )
|
109
|
+
print_exception e
|
110
|
+
print_error
|
111
|
+
print_error 'Parent:'
|
112
|
+
print_error self.class.to_s
|
113
|
+
print_error
|
114
|
+
print_error 'Block:'
|
115
|
+
print_error block.to_s
|
116
|
+
print_error
|
117
|
+
print_error 'Caller:'
|
118
|
+
::Kernel.caller.each { |l| print_error l }
|
119
|
+
print_error '-' * 80
|
120
|
+
end
|
121
|
+
|
122
|
+
raise e if raise_exception
|
123
|
+
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def regexp_array_match( regexps, str )
|
128
|
+
regexps = [regexps].flatten.compact.
|
129
|
+
map { |s| s.is_a?( Regexp ) ? s : Regexp.new( s.to_s ) }
|
130
|
+
return true if regexps.empty?
|
131
|
+
|
132
|
+
cnt = 0
|
133
|
+
regexps.each { |filter| cnt += 1 if filter.match? str }
|
134
|
+
cnt == regexps.size
|
135
|
+
end
|
136
|
+
|
137
|
+
def remove_constants( mod, skip = [] )
|
138
|
+
return if skip.include?( mod )
|
139
|
+
return if !(mod.is_a?( Class ) || mod.is_a?( Module )) ||
|
140
|
+
!mod.to_s.start_with?( 'Cuboid' )
|
141
|
+
|
142
|
+
parent = Object
|
143
|
+
mod.to_s.split( '::' )[0..-2].each do |ancestor|
|
144
|
+
parent = parent.const_get( ancestor.to_sym )
|
145
|
+
end
|
146
|
+
|
147
|
+
mod.constants.each { |m| mod.send( :remove_const, m ) }
|
148
|
+
nil
|
149
|
+
end
|
150
|
+
|
151
|
+
extend self
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
data/lib/cuboid/version.rb
CHANGED
data/lib/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1alpha
|
data/logs/placeholder
ADDED
File without changes
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Application::Parts::Data do
|
4
|
+
include_examples 'application'
|
5
|
+
|
6
|
+
describe '#data' do
|
7
|
+
it "returns #{Cuboid::Data::Application}" do
|
8
|
+
expect(subject.data).to be_kind_of Cuboid::Data::Application
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cuboid::Application::Parts::State do
|
4
|
+
include_examples 'application'
|
5
|
+
|
6
|
+
describe '#running?' do
|
7
|
+
it "delegates to #{Cuboid::State::Application}#scanning?" do
|
8
|
+
allow(subject.state).to receive(:running?) { :stuff }
|
9
|
+
expect(subject.running?).to eq(:stuff)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#done?' do
|
14
|
+
it "delegates to #{Cuboid::State::Application}#done?" do
|
15
|
+
allow(subject.state).to receive(:done?) { :stuff }
|
16
|
+
expect(subject.done?).to eq(:stuff)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#paused?' do
|
21
|
+
it "delegates to #{Cuboid::State::Application}#paused?" do
|
22
|
+
allow(subject.state).to receive(:paused?) { :stuff }
|
23
|
+
expect(subject.paused?).to eq(:stuff)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#state' do
|
28
|
+
it "returns #{Cuboid::State::Application}" do
|
29
|
+
expect(subject.state).to be_kind_of Cuboid::State::Application
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#abort!' do
|
34
|
+
it 'sets #status to :aborting' do
|
35
|
+
MockApp.safe do |f|
|
36
|
+
t = Thread.new do
|
37
|
+
f.run
|
38
|
+
end
|
39
|
+
|
40
|
+
sleep 1 while f.status == :ready
|
41
|
+
|
42
|
+
f.abort!
|
43
|
+
expect(f.status).to eq(:aborted)
|
44
|
+
|
45
|
+
t.join
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#suspend!' do
|
51
|
+
it 'suspends the system' do
|
52
|
+
snapshot = nil
|
53
|
+
MockApp.safe do |f|
|
54
|
+
t = Thread.new do
|
55
|
+
f.run
|
56
|
+
end
|
57
|
+
|
58
|
+
sleep 1 while f.status != :running
|
59
|
+
|
60
|
+
snapshot = f.suspend!
|
61
|
+
expect(f.status).to eq(:suspended)
|
62
|
+
|
63
|
+
t.join
|
64
|
+
end
|
65
|
+
|
66
|
+
expect(Cuboid::Snapshot.load( snapshot )).to be_truthy
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when #{Cuboid::OptionGroups::Paths}#snapshots" do
|
70
|
+
context 'is a directory' do
|
71
|
+
it 'stores the snapshot under it' do
|
72
|
+
Cuboid::Options.snapshot.path = Dir.tmpdir
|
73
|
+
|
74
|
+
snapshot = nil
|
75
|
+
MockApp.safe do |f|
|
76
|
+
t = Thread.new do
|
77
|
+
f.run
|
78
|
+
end
|
79
|
+
|
80
|
+
sleep 0.1 while f.status != :running
|
81
|
+
|
82
|
+
snapshot = f.suspend!
|
83
|
+
t.join
|
84
|
+
end
|
85
|
+
|
86
|
+
expect(File.dirname( snapshot )).to eq(Dir.tmpdir)
|
87
|
+
expect(Cuboid::Snapshot.load( snapshot )).to be_truthy
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'is a file path' do
|
92
|
+
it 'stores the snapshot there' do
|
93
|
+
Cuboid::Options.snapshot.path = "#{Dir.tmpdir}/snapshot"
|
94
|
+
|
95
|
+
snapshot = nil
|
96
|
+
MockApp.safe do |f|
|
97
|
+
t = Thread.new do
|
98
|
+
f.run
|
99
|
+
end
|
100
|
+
|
101
|
+
sleep 0.1 while f.status != :running
|
102
|
+
|
103
|
+
snapshot = f.suspend!
|
104
|
+
t.join
|
105
|
+
end
|
106
|
+
|
107
|
+
expect(snapshot).to eq("#{Dir.tmpdir}/snapshot")
|
108
|
+
expect(Cuboid::Snapshot.load( snapshot )).to be_truthy
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#restore!' do
|
115
|
+
it 'restores options' do
|
116
|
+
options_hash = nil
|
117
|
+
|
118
|
+
snapshot = nil
|
119
|
+
MockApp.safe do |f|
|
120
|
+
Cuboid::Options.datastore.my_custom_option = 'my custom value'
|
121
|
+
|
122
|
+
t = Thread.new { f.run }
|
123
|
+
sleep 0.1 while f.status != :running
|
124
|
+
|
125
|
+
snapshot = f.suspend!
|
126
|
+
|
127
|
+
t.join
|
128
|
+
end
|
129
|
+
|
130
|
+
MockApp.restore!( snapshot ) do |f|
|
131
|
+
opts = Cuboid::Options.to_h
|
132
|
+
expect(opts[:datastore][:my_custom_option]).to eq('my custom value')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#pause!' do
|
138
|
+
it 'pauses the system' do
|
139
|
+
MockApp.safe do |f|
|
140
|
+
t = Thread.new do
|
141
|
+
f.run
|
142
|
+
end
|
143
|
+
sleep 0.1 while f.status != :running
|
144
|
+
|
145
|
+
f.pause!
|
146
|
+
expect(f.status).to eq(:paused)
|
147
|
+
expect(f.running?).to be_truthy
|
148
|
+
|
149
|
+
f.resume!
|
150
|
+
t.join
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#resume!' do
|
156
|
+
it 'resumes the scan' do
|
157
|
+
MockApp.safe do |f|
|
158
|
+
t = Thread.new do
|
159
|
+
f.run
|
160
|
+
end
|
161
|
+
sleep( 1 ) while f.status == :ready
|
162
|
+
|
163
|
+
f.pause!
|
164
|
+
expect(f.status).to eq(:paused)
|
165
|
+
|
166
|
+
f.resume!
|
167
|
+
Timeout.timeout 5 do
|
168
|
+
sleep 0.1 while f.status != :done
|
169
|
+
end
|
170
|
+
|
171
|
+
t.join
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#clean_up' do
|
177
|
+
it 'sets the status to cleanup' do
|
178
|
+
MockApp.safe do |f|
|
179
|
+
f.clean_up
|
180
|
+
expect(f.status).to eq(:cleanup)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'sets #running? to false' do
|
185
|
+
MockApp.safe do |f|
|
186
|
+
f.clean_up
|
187
|
+
expect(f).not_to be_running
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|