redcar 0.3.4.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +45 -0
- data/README.md +2 -1
- data/ROADMAP.md +0 -1
- data/Rakefile +10 -4
- data/bin/redcar +2 -2
- data/lib/openssl/build.properties +7 -0
- data/lib/plugin_manager/lib/plugin_manager.rb +10 -0
- data/lib/plugin_manager/lib/plugin_manager/plugin_definition.rb +1 -13
- data/lib/redcar.rb +12 -8
- data/lib/redcar/installer.rb +16 -15
- data/lib/redcar/ruby_extensions.rb +146 -1
- data/lib/redcar/runner.rb +16 -7
- data/lib/redcar/usage.rb +4 -7
- data/lib/redcar_quick_start.rb +5 -5
- data/lib/regex_replace.rb +0 -7
- data/plugins/application/features/step_definitions/command_steps.rb +5 -0
- data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
- data/plugins/application/features/step_definitions/filter_list_dialog_steps.rb +38 -0
- data/plugins/application/features/step_definitions/window_steps.rb +1 -1
- data/plugins/application/features/support/env.rb +44 -8
- data/plugins/application/lib/application.rb +32 -33
- data/plugins/application/lib/application/command.rb +32 -2
- data/plugins/application/lib/application/command/executor.rb +2 -12
- data/plugins/application/lib/application/dialog.rb +14 -14
- data/plugins/application/lib/application/event_spewer.rb +32 -0
- data/plugins/application/lib/application/menu.rb +5 -5
- data/plugins/application/lib/application/menu/builder.rb +5 -0
- data/plugins/application/lib/application/menu/lazy_menu.rb +24 -0
- data/plugins/application/lib/application/notebook.rb +4 -3
- data/plugins/application/lib/application/tab.rb +6 -2
- data/plugins/application/lib/application/window.rb +8 -4
- data/plugins/application/spec/application/menu/builder_spec.rb +17 -1
- data/plugins/application/spec/application/notebook_spec.rb +1 -1
- data/plugins/application_swt/build.xml +74 -0
- data/plugins/application_swt/lib/application_swt.rb +79 -0
- data/plugins/application_swt/lib/application_swt/cucumber_patches.rb +6 -1
- data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +25 -17
- data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +50 -12
- data/plugins/application_swt/lib/application_swt/html_tab.rb +20 -0
- data/plugins/application_swt/lib/application_swt/menu.rb +26 -2
- data/plugins/application_swt/lib/application_swt/notebook.rb +10 -12
- data/plugins/application_swt/lib/application_swt/window.rb +11 -11
- data/plugins/application_swt/src/com/redcareditor/application_swt/CocoaUIEnhancer.java +313 -0
- data/plugins/auto_completer/lib/auto_completer.rb +74 -67
- data/plugins/auto_completer/lib/auto_completer/current_document_completion_source.rb +19 -0
- data/plugins/auto_completer/lib/auto_completer/document_controller.rb +2 -2
- data/plugins/auto_completer/lib/auto_completer/word_list.rb +8 -1
- data/plugins/auto_indenter/features/ruby_style_indentation.feature +24 -0
- data/plugins/auto_indenter/features/step_definitions/indentation_steps.rb +6 -0
- data/plugins/auto_indenter/features/support/env.rb +2 -0
- data/plugins/auto_indenter/lib/auto_indenter.rb +86 -0
- data/plugins/auto_indenter/lib/auto_indenter/analyzer.rb +91 -0
- data/plugins/auto_indenter/lib/auto_indenter/commands.rb +34 -0
- data/plugins/auto_indenter/lib/auto_indenter/document_controller.rb +67 -12
- data/plugins/auto_indenter/lib/auto_indenter/rules.rb +41 -0
- data/plugins/auto_indenter/spec/auto_indenter/analyzer_spec.rb +151 -0
- data/plugins/auto_indenter/spec/spec_helper.rb +5 -0
- data/plugins/auto_pairer/lib/auto_pairer.rb +1 -0
- data/plugins/auto_pairer/lib/auto_pairer/document_controller.rb +43 -42
- data/plugins/auto_pairer/lib/auto_pairer/pairs_for_scope.rb +1 -5
- data/plugins/core/lib/core.rb +12 -1
- data/plugins/core/lib/core/observable.rb +7 -7
- data/plugins/core/lib/core/persistent_cache.rb +14 -2
- data/plugins/core/lib/core/plugin.rb +7 -0
- data/plugins/core/lib/core/resource.rb +78 -0
- data/plugins/core/lib/core/task.rb +62 -0
- data/plugins/core/lib/core/task_queue.rb +72 -0
- data/plugins/core/spec/core/resource_spec.rb +124 -0
- data/plugins/core/spec/core/task_queue_spec.rb +202 -0
- data/plugins/core/spec/spec_helper.rb +23 -1
- data/plugins/declarations/TODO +3 -0
- data/plugins/declarations/lib/declarations.rb +144 -0
- data/plugins/declarations/lib/declarations/completion_source.rb +22 -0
- data/plugins/declarations/lib/declarations/file.rb +68 -0
- data/plugins/declarations/lib/declarations/parser.rb +94 -0
- data/plugins/declarations/lib/declarations/select_tag_dialog.rb +44 -0
- data/plugins/declarations/plugin.rb +7 -0
- data/plugins/declarations/spec/declarations/file_spec.rb +62 -0
- data/plugins/declarations/spec/fixtures/federalist.rb +15 -0
- data/plugins/declarations/spec/spec_helper.rb +4 -0
- data/plugins/edit_view/features/indentation_commands.feature +40 -0
- data/plugins/edit_view/features/line_delimiter.feature +40 -0
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +16 -4
- data/plugins/edit_view/features/step_definitions/notebook_steps.rb +1 -1
- data/plugins/edit_view/features/step_definitions/tab_steps.rb +1 -1
- data/plugins/edit_view/features/step_definitions/window_steps.rb +5 -1
- data/plugins/edit_view/features/support/env.rb +3 -5
- data/plugins/edit_view/features/undo_and_redo.feature +21 -0
- data/plugins/edit_view/lib/edit_view.rb +57 -4
- data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +19 -3
- data/plugins/edit_view/lib/edit_view/document.rb +46 -11
- data/plugins/edit_view/lib/edit_view/document/indentation.rb +35 -0
- data/plugins/edit_view/lib/edit_view/modified_tabs_checker.rb +35 -0
- data/plugins/edit_view/lib/edit_view/tab_settings.rb +13 -3
- data/plugins/edit_view/spec/edit_view/document/indentation_spec.rb +112 -0
- data/plugins/edit_view/spec/edit_view/document_spec.rb +22 -0
- data/plugins/edit_view/spec/spec_helper.rb +1 -0
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +59 -7
- data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +3 -3
- data/plugins/edit_view_swt/lib/edit_view_swt/word_movement.rb +2 -2
- data/plugins/edit_view_swt/vendor/java-mateview.rb +3 -2
- data/plugins/encryption/encryption.rb +13 -6
- data/plugins/execute_current_tab/lib/execute_current_tab.rb +25 -15
- data/plugins/html_view/assets/redcar.css +32 -1
- data/plugins/html_view/lib/html_view.rb +23 -3
- data/plugins/html_view/lib/html_view/html_tab.rb +4 -0
- data/plugins/my_plugin/lib/my_plugin.rb +4 -12
- data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +1 -0
- data/plugins/plugin_manager_ui/views/index.html.erb +30 -37
- data/plugins/project/features/find_file.feature +75 -0
- data/plugins/project/features/open_and_save_files.feature +7 -7
- data/plugins/project/features/open_directory_tree.feature +11 -3
- data/plugins/project/features/refresh_directory_tree.feature +7 -1
- data/plugins/project/features/step_definitions/directory_steps.rb +11 -1
- data/plugins/project/features/step_definitions/file_steps.rb +10 -0
- data/plugins/project/features/support/env.rb +6 -1
- data/plugins/project/features/watch_for_modified_files.feature +79 -0
- data/plugins/project/lib/project.rb +72 -306
- data/plugins/project/lib/project/commands.rb +128 -0
- data/plugins/project/lib/project/dir_mirror.rb +5 -1
- data/plugins/project/lib/project/drb_service.rb +21 -31
- data/plugins/project/lib/project/file_list.rb +76 -0
- data/plugins/project/lib/project/file_mirror.rb +13 -1
- data/plugins/project/lib/project/find_file_dialog.rb +22 -52
- data/plugins/project/lib/project/manager.rb +210 -0
- data/plugins/project/lib/project/recent_directories.rb +16 -3
- data/plugins/project/plugin.rb +1 -1
- data/plugins/project/spec/fixtures/myproject/README +2 -0
- data/plugins/project/spec/fixtures/myproject/lib/foo_lib.rb +1 -0
- data/plugins/project/spec/fixtures/myproject/spec/foo_spec.rb +1 -0
- data/plugins/project/{features → spec}/fixtures/winter.txt +0 -0
- data/plugins/project/spec/project/dir_mirror_spec.rb +1 -12
- data/plugins/project/spec/project/file_list_spec.rb +140 -0
- data/plugins/project/spec/spec_helper.rb +20 -0
- data/plugins/redcar/plugin.rb +1 -0
- data/plugins/redcar/redcar.rb +254 -84
- data/plugins/redcar_debug/lib/redcar_debug.rb +58 -11
- data/plugins/redcar_debug/vendor/jruby-prof/README +46 -0
- data/plugins/redcar_debug/vendor/jruby-prof/Rakefile +36 -0
- data/plugins/redcar_debug/vendor/jruby-prof/build.xml +31 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.html +22677 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/call_tree.txt +589 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/flat.txt +28 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/graph.html +1670 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/graph.txt +125 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/pidigits.rb +92 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/test.rb +28 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/test2.rb +29 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/test_exception.rb +28 -0
- data/plugins/redcar_debug/vendor/jruby-prof/example/test_overhead.rb +43 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof.rb +66 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/abstract_printer.rb +21 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/flat_text_printer.rb +35 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_html_printer.rb +123 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/graph_text_printer.rb +45 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/invocation_set.rb +34 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/method.rb +107 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/profile_invocation.rb +43 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/simple_tree_printer.rb +27 -0
- data/plugins/redcar_debug/vendor/jruby-prof/lib/jruby-prof/tree_html_printer.rb +144 -0
- data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/Invocation.java +14 -0
- data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/JRubyProf.java +94 -0
- data/plugins/redcar_debug/vendor/jruby-prof/src/org/jruby/prof/ProfEventHook.java +49 -0
- data/plugins/redcar_debug/vendor/jruby-prof/templates/graph_row.html.erb +18 -0
- data/plugins/redcar_debug/vendor/jruby-prof/test/basic_test.rb +291 -0
- data/plugins/redcar_debug/views/history.html.erb +33 -0
- data/plugins/redcar_debug/views/index.html.erb +33 -0
- data/plugins/repl/lib/repl/internal_mirror.rb +3 -15
- data/plugins/repl/spec/repl/internal_mirror_spec.rb +2 -2
- data/plugins/snippets/lib/snippets.rb +0 -1
- data/plugins/snippets/lib/snippets/document_controller.rb +7 -1
- data/plugins/task_manager/lib/task_manager.rb +28 -0
- data/plugins/task_manager/plugin.rb +11 -0
- data/plugins/task_manager/views/index.html.erb +67 -0
- data/plugins/textmate/lib/textmate.rb +17 -21
- data/plugins/textmate/lib/textmate/plist.rb +1 -2
- data/plugins/textmate/lib/textmate/preference.rb +5 -1
- data/plugins/textmate/lib/textmate/snippet.rb +6 -1
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +0 -6
- data/textmate/Bundles/Cucumber.tmbundle/Preferences/Comments.tmPreferences +1 -1
- data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Cucumber_Plain_Text_Feature_Completions.tmPreferences +30 -0
- data/textmate/Bundles/Cucumber.tmbundle/Preferences/next_Symbol_list___Scenario.tmPreferences +19 -0
- data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Plain_Text_Feature.tmLanguage +221 -0
- data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/next_Cucumber_Steps.tmLanguage +424 -0
- data/textmate/Bundles/Cucumber.tmbundle/Syntaxes/plaintext_template.erb +19 -77
- data/textmate/Bundles/Cucumber.tmbundle/info.plist +1 -20
- data/textmate/Bundles/Perl.tmbundle/Syntaxes/Perl.plist +1 -1
- data/textmate/Themes/Emacs Strict.tmTheme +241 -0
- data/textmate/Themes/IR_White.tmTheme +792 -0
- data/textmate/Themes/Monokai.tmTheme +291 -0
- data/textmate/Themes/WhysPoignant.tmTheme +191 -0
- metadata +92 -7
- data/plugins/application/features/main_window.feature +0 -8
- data/plugins/project/lib/project/project_command.rb +0 -5
- data/textmate/Bundles/Cucumber.tmbundle/Snippets/Scenario.tmSnippet +0 -22
- data/textmate/Bundles/Cucumber.tmbundle/Snippets/Story.tmSnippet +0 -25
data/plugins/core/lib/core.rb
CHANGED
@@ -14,7 +14,19 @@ require "core/persistent_cache"
|
|
14
14
|
require "core/plugin"
|
15
15
|
require "core/plugin/storage"
|
16
16
|
|
17
|
+
require "core/task"
|
18
|
+
require "core/task_queue"
|
19
|
+
require "core/resource"
|
20
|
+
|
17
21
|
module Redcar
|
22
|
+
def self.tmp_dir
|
23
|
+
path = File.join(Redcar.user_dir, "tmp")
|
24
|
+
unless File.exists?(path)
|
25
|
+
FileUtils.mkdir(path)
|
26
|
+
end
|
27
|
+
path
|
28
|
+
end
|
29
|
+
|
18
30
|
class Core
|
19
31
|
include HasLogger
|
20
32
|
|
@@ -25,6 +37,5 @@ module Redcar
|
|
25
37
|
end
|
26
38
|
PersistentCache.storage_dir = File.join(Redcar.user_dir, "cache")
|
27
39
|
end
|
28
|
-
|
29
40
|
end
|
30
41
|
end
|
@@ -66,11 +66,11 @@ module Redcar
|
|
66
66
|
def add_listener(*event_names, &block)
|
67
67
|
if event_names.first.is_a?(Hash)
|
68
68
|
event_names.first.each do |aspect, event_name|
|
69
|
-
|
69
|
+
observable_events(event_name.to_s)[ASPECTS[aspect]] << block
|
70
70
|
end
|
71
71
|
else
|
72
72
|
event_names.each do |event_name|
|
73
|
-
|
73
|
+
observable_events(event_name.to_s)[ASPECTS[:after]] << block
|
74
74
|
end
|
75
75
|
end
|
76
76
|
block
|
@@ -91,19 +91,19 @@ module Redcar
|
|
91
91
|
# @param [Symbol] name of event being run
|
92
92
|
# @param [*Object] event parameters
|
93
93
|
def notify_listeners(event_name, *args)
|
94
|
-
|
94
|
+
observable_run_blocks(event_name, :before, args)
|
95
95
|
yield if block_given?
|
96
|
-
|
96
|
+
observable_run_blocks(event_name, :after, args)
|
97
97
|
end
|
98
98
|
|
99
99
|
private
|
100
100
|
|
101
|
-
def
|
102
|
-
blocks =
|
101
|
+
def observable_run_blocks(event_name, aspect, args)
|
102
|
+
blocks = observable_events(event_name.to_s)[ASPECTS[aspect]].clone
|
103
103
|
blocks.each {|b| b.call(*args) }
|
104
104
|
end
|
105
105
|
|
106
|
-
def
|
106
|
+
def observable_events(event_name)
|
107
107
|
@events ||= {}
|
108
108
|
@events[event_name.to_s] ||= [[], []]
|
109
109
|
end
|
@@ -18,8 +18,8 @@ module Redcar
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def cache
|
21
|
-
if
|
22
|
-
|
21
|
+
if result = read_cache_file
|
22
|
+
result
|
23
23
|
else
|
24
24
|
result = yield
|
25
25
|
write_cache_file(Marshal.dump(result))
|
@@ -41,5 +41,17 @@ module Redcar
|
|
41
41
|
FileUtils.mkdir_p(PersistentCache.storage_dir)
|
42
42
|
File.open(cache_file_name, "w") {|f| f.puts contents }
|
43
43
|
end
|
44
|
+
|
45
|
+
def read_cache_file
|
46
|
+
if File.exist?(cache_file_name)
|
47
|
+
begin
|
48
|
+
Marshal.load(File.read(cache_file_name))
|
49
|
+
rescue => e
|
50
|
+
puts "WARNING: couldn't load #{cache_file_name}, despite it existing."
|
51
|
+
puts e.class.name + " " + e.message
|
52
|
+
puts e.backtrace
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
44
56
|
end
|
45
57
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Resource
|
4
|
+
attr_reader :block, :task
|
5
|
+
|
6
|
+
def self.task_queue
|
7
|
+
Redcar.app.task_queue
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(description=nil, &block)
|
11
|
+
@description = description
|
12
|
+
@block = block
|
13
|
+
@value = nil
|
14
|
+
@future = nil
|
15
|
+
@task = nil
|
16
|
+
@mutex = Mutex.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def value
|
20
|
+
return @value if @value
|
21
|
+
|
22
|
+
object = nil
|
23
|
+
@mutex.synchronize do
|
24
|
+
if @future
|
25
|
+
if @task.pending?
|
26
|
+
@task.cancel
|
27
|
+
@future = nil
|
28
|
+
@task = nil
|
29
|
+
object = @block
|
30
|
+
else
|
31
|
+
object = @future
|
32
|
+
end
|
33
|
+
else
|
34
|
+
object = @block
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
case object
|
39
|
+
when Proc
|
40
|
+
@value = object.call
|
41
|
+
else
|
42
|
+
@value = object.get
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def compute
|
47
|
+
@mutex.synchronize do
|
48
|
+
unless @task and @task.pending?
|
49
|
+
@task = Resource::Task.new(self)
|
50
|
+
@task.description = @description
|
51
|
+
@future = Resource.task_queue.submit(@task)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Task < Redcar::Task
|
57
|
+
def initialize(resource)
|
58
|
+
@resource = resource
|
59
|
+
end
|
60
|
+
|
61
|
+
def execute
|
62
|
+
result = @resource.block.call
|
63
|
+
@resource.send(:set_value_from_background, result)
|
64
|
+
result
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def set_value_from_background(value)
|
71
|
+
@mutex.synchronize do
|
72
|
+
@value = value
|
73
|
+
@future = nil
|
74
|
+
@task = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Task
|
4
|
+
include java.util.concurrent.Callable
|
5
|
+
|
6
|
+
attr_accessor :_queue, :enqueue_time, :start_time, :completed_time, :description
|
7
|
+
attr_reader :error
|
8
|
+
|
9
|
+
def pending?
|
10
|
+
@enqueue_time and !@start_time
|
11
|
+
end
|
12
|
+
|
13
|
+
def in_process?
|
14
|
+
@start_time and !@completed_time
|
15
|
+
end
|
16
|
+
|
17
|
+
def completed?
|
18
|
+
@completed_time
|
19
|
+
end
|
20
|
+
|
21
|
+
def cancel
|
22
|
+
@cancelled = true
|
23
|
+
_queue.send(:completed_task, self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def cancelled?
|
27
|
+
@cancelled
|
28
|
+
end
|
29
|
+
|
30
|
+
def call
|
31
|
+
begin
|
32
|
+
unless cancelled?
|
33
|
+
_queue.send(:started_task, self)
|
34
|
+
@start_time = Time.now
|
35
|
+
result = execute
|
36
|
+
@completed_time = Time.now
|
37
|
+
_queue.send(:completed_task, self)
|
38
|
+
result
|
39
|
+
end
|
40
|
+
rescue Object => e
|
41
|
+
@error = e
|
42
|
+
@completed_time = Time.now
|
43
|
+
_queue.send(:completed_task, self)
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def execute
|
49
|
+
raise "implement me!"
|
50
|
+
end
|
51
|
+
|
52
|
+
def inspect
|
53
|
+
"<Task>"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def _set_cancelled
|
59
|
+
@cancelled = true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class TaskQueue
|
4
|
+
MAX_COMPLETED_LENGTH = 20
|
5
|
+
|
6
|
+
attr_reader :in_process, :mutex
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@executor = java.util.concurrent.Executors.newSingleThreadExecutor
|
10
|
+
@mutex = Mutex.new
|
11
|
+
@pending = []
|
12
|
+
@completed = []
|
13
|
+
@in_process = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def submit(task)
|
17
|
+
@mutex.synchronize do
|
18
|
+
@pending << task
|
19
|
+
task._queue = self
|
20
|
+
task.enqueue_time = Time.now
|
21
|
+
future = @executor.submit(task)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def pending
|
26
|
+
@mutex.synchronize do
|
27
|
+
@pending.dup
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def completed
|
32
|
+
@mutex.synchronize do
|
33
|
+
@completed.dup
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
@mutex.synchronize do
|
39
|
+
@executor.shutdown_now
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def cancel_all
|
44
|
+
@mutex.synchronize do
|
45
|
+
@pending.each {|task| task.send(:_set_cancelled) }
|
46
|
+
@completed += @pending
|
47
|
+
@pending = []
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def started_task(task)
|
54
|
+
@mutex.synchronize do
|
55
|
+
@in_process = task
|
56
|
+
@pending.delete(task)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def completed_task(task)
|
61
|
+
@mutex.synchronize do
|
62
|
+
@pending.delete(task)
|
63
|
+
@in_process = nil if @in_process == task
|
64
|
+
@completed << task
|
65
|
+
if @completed.length > MAX_COMPLETED_LENGTH
|
66
|
+
@completed = @completed[(-1*MAX_COMPLETED_LENGTH)..-1]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
|
2
|
+
require 'java'
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), *%w".. spec_helper")
|
5
|
+
|
6
|
+
TaskQueue = Redcar::TaskQueue
|
7
|
+
Task = Redcar::Task
|
8
|
+
Resource = Redcar::Resource
|
9
|
+
|
10
|
+
describe Resource do
|
11
|
+
before do
|
12
|
+
$started_tasks = []
|
13
|
+
@block_runs = 0
|
14
|
+
@started_flag = false
|
15
|
+
@finish_flag = false
|
16
|
+
$wait_task_finish = false
|
17
|
+
@q = TaskQueue.new
|
18
|
+
Resource.stub!(:task_queue).and_return(@q)
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
@q.stop
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "synchronous get" do
|
26
|
+
it "should let you synchronously get the value" do
|
27
|
+
resource = Resource.new { 101 }
|
28
|
+
resource.value.should == 101
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should cache the value across multiple calls" do
|
32
|
+
resource = Resource.new { @block_runs += 1; 101 }
|
33
|
+
resource.value
|
34
|
+
resource.value
|
35
|
+
resource.value.should == 101
|
36
|
+
@block_runs.should == 1
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should wait for a background job to finish if one is already in progress" do
|
40
|
+
resource = Resource.new do
|
41
|
+
@block_runs += 1
|
42
|
+
1 until @finish_flag
|
43
|
+
end
|
44
|
+
resource.compute
|
45
|
+
Thread.new do
|
46
|
+
resource.value
|
47
|
+
end
|
48
|
+
sleep 0.1
|
49
|
+
@finish_flag = true
|
50
|
+
@block_runs.should == 1
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not wait for a background job if it pending, because it may have a long wait" do
|
54
|
+
@q.submit(BlockingTask.new)
|
55
|
+
resource = Resource.new do
|
56
|
+
@block_runs += 1
|
57
|
+
911
|
58
|
+
end
|
59
|
+
resource.compute
|
60
|
+
Thread.new do
|
61
|
+
resource.value
|
62
|
+
end
|
63
|
+
sleep 0.1
|
64
|
+
resource.value.should == 911
|
65
|
+
@block_runs.should == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should cancel background jobs that it overtakes" do
|
69
|
+
@q.submit(BlockingTask.new)
|
70
|
+
resource = Resource.new do
|
71
|
+
@block_runs += 1
|
72
|
+
911
|
73
|
+
end
|
74
|
+
resource.compute
|
75
|
+
task = resource.task
|
76
|
+
Thread.new do
|
77
|
+
resource.value
|
78
|
+
end
|
79
|
+
sleep 0.1
|
80
|
+
task.should be_cancelled
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should let you compute the resource in the background" do
|
85
|
+
resource = Resource.new do
|
86
|
+
1 until @started_flag
|
87
|
+
@block_runs += 1
|
88
|
+
@finish_flag = true
|
89
|
+
end
|
90
|
+
resource.compute
|
91
|
+
@block_runs.should == 0
|
92
|
+
@started_flag = true
|
93
|
+
1 until @finish_flag
|
94
|
+
@block_runs.should == 1
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have the background computed value" do
|
98
|
+
resource = Resource.new do
|
99
|
+
@block_runs += 1
|
100
|
+
@started_flag = true
|
101
|
+
999
|
102
|
+
end
|
103
|
+
resource.compute
|
104
|
+
1 until @started_flag
|
105
|
+
sleep 0.1
|
106
|
+
resource.value.should == 999
|
107
|
+
@block_runs.should == 1
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should not compute lots of times" do
|
111
|
+
resource = Resource.new do
|
112
|
+
@block_runs += 1
|
113
|
+
1 until @finish_flag
|
114
|
+
999
|
115
|
+
end
|
116
|
+
20.times { resource.compute }
|
117
|
+
@finish_flag = true
|
118
|
+
resource.value.should == 999
|
119
|
+
1 until @block_runs == 2
|
120
|
+
@block_runs.should == 2
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|