fiveruns-starling 0.9.7.5

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.
@@ -0,0 +1,237 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'fileutils'
6
+ require 'memcache'
7
+ require 'digest/md5'
8
+
9
+ require 'starling/server'
10
+ require 'starling/client'
11
+ require 'starling/worker'
12
+
13
+ class StarlingServer::PersistentQueue
14
+ remove_const :SOFT_LOG_MAX_SIZE
15
+ SOFT_LOG_MAX_SIZE = 16 * 1024 # 16 KB
16
+ end
17
+
18
+ def safely_fork(&block)
19
+ # anti-race juice:
20
+ blocking = true
21
+ Signal.trap("USR1") { blocking = false }
22
+
23
+ pid = Process.fork(&block)
24
+
25
+ while blocking
26
+ sleep 0.1
27
+ end
28
+
29
+ pid
30
+ end
31
+
32
+ describe "StarlingWorker" do
33
+ before do
34
+ @tmp_path = File.join(File.dirname(__FILE__), "tmp")
35
+ @templates_path = File.join(File.dirname(__FILE__), "templates")
36
+ @workers_path = File.join(File.dirname(__FILE__), "workers")
37
+
38
+ begin
39
+ Dir::mkdir(@tmp_path)
40
+ rescue Errno::EEXIST
41
+ end
42
+
43
+ @server_pid = safely_fork do
44
+ server = StarlingServer::Base.new(:host => '127.0.0.1',
45
+ :port => 22133,
46
+ :path => @tmp_path,
47
+ :logger => Logger.new(STDERR),
48
+ :log_level => Logger::FATAL)
49
+ Signal.trap("INT") { server.stop }
50
+ Process.kill("USR1", Process.ppid)
51
+ server.run
52
+ end
53
+
54
+ @client = StarlingClient::Base.new(:host => '127.0.0.1',
55
+ :port => 22133,
56
+ :templates_path => @templates_path,
57
+ :workers_path => @workers_path)
58
+
59
+ @client.load_templates
60
+ @client.load_workers
61
+
62
+ @worker = StarlingWorker::Base.new(:host => '127.0.0.1',
63
+ :port => 22133,
64
+ :continues_processing => false,
65
+ :incoming_remote_queue_name => "worker_messages_coming_in",
66
+ :outgoing_remote_queue_name => "worker_messages_going_out")
67
+
68
+ @starling = @client.starling
69
+ end
70
+
71
+ it "should add and remove messages from local queue" do
72
+ @worker.add_message_to_local_queue("message").should be_true
73
+ @worker.local_queue.size.should eql(1)
74
+ @worker.get_message_from_local_queue.should eql("message")
75
+ end
76
+
77
+ it "should add and remove messages from remote queue" do
78
+ @worker.add_message_to_incoming_remote_queue("message").should be_true
79
+ @worker.get_message_from_incoming_remote_queue.should eql("message")
80
+
81
+ Thread.new do
82
+ @worker.get_message_from_outgoing_remote_queue.should eql("test")
83
+ end
84
+ sleep 0.1
85
+ @worker.add_message_to_outgoing_remote_queue("test")
86
+ end
87
+
88
+ it "should have a remote queue name" do
89
+ @worker.incoming_remote_queue_name.should eql("worker_messages_coming_in")
90
+ @worker.outgoing_remote_queue_name.should eql("worker_messages_going_out")
91
+ end
92
+
93
+ it "should have threadpool size" do
94
+ @worker.threadpool.should_not be_nil
95
+ end
96
+
97
+ it "should pass from remote queue to process" do
98
+ @worker.add_message_to_incoming_remote_queue("test")
99
+ @worker.from_remote_queue_to_process.should eql("test")
100
+ end
101
+
102
+ it "should pass from local queue to remote queue" do
103
+ @worker.add_message_to_local_queue("test")
104
+
105
+ @worker.from_local_queue_to_remote_queue
106
+
107
+ @starling.sizeof(@worker.outgoing_remote_queue_name).should eql(1)
108
+
109
+ @worker.get_message_from_outgoing_remote_queue.should eql("test")
110
+
111
+ @starling.sizeof(@worker.outgoing_remote_queue_name).should eql(0)
112
+ end
113
+
114
+ it "should process message with block and add to local queue" do
115
+ @worker.process_as_thread("test") do |message|
116
+ message.should eql("test")
117
+ message
118
+ end
119
+
120
+ @worker.get_message_from_local_queue.should eql("test")
121
+ end
122
+
123
+ it "should be able to enq_thread with block" do
124
+ @worker.add_message_to_incoming_remote_queue("test")
125
+
126
+ @worker.process_message_from_incoming_remote_queue do |message|
127
+ message.should eql("test")
128
+ message
129
+ end
130
+
131
+ @worker.get_message_from_local_queue.should eql("test")
132
+ end
133
+
134
+ it "should be able to deq_thread with block" do
135
+ @worker.add_message_to_local_queue("test")
136
+
137
+ @worker.process_message_from_local_queue_to_outgoing_remote_queue
138
+
139
+ @worker.get_message_from_outgoing_remote_queue.should eql("test")
140
+ end
141
+
142
+ it "should process worker" do
143
+ @worker.add_message_to_incoming_remote_queue("**")
144
+
145
+ @worker.process do |message|
146
+ message.should eql("**")
147
+ message
148
+ end
149
+
150
+ @worker.run
151
+
152
+ @starling.sizeof(@worker.outgoing_remote_queue_name).should eql(1)
153
+ end
154
+
155
+ it "should pass from process to local queue" do
156
+ @worker.from_process_to_local_queue("test")
157
+ @worker.get_message_from_local_queue.should eql("test")
158
+ end
159
+
160
+ it "should run workers that implemented process" do
161
+
162
+ worker = StarlingWorker::PushDataToSomeApi.new(:host => '127.0.0.1',
163
+ :port => 22133,
164
+ :continues_processing => false,
165
+ :incoming_remote_queue_name => "worker_messages_coming_in",
166
+ :outgoing_remote_queue_name => "worker_messages_going_out")
167
+
168
+ worker.add_message_to_incoming_remote_queue("**")
169
+ worker.run
170
+
171
+
172
+ worker = StarlingWorker::GetDataFromSomeApi.new(:host => '127.0.0.1',
173
+ :port => 22133,
174
+ :continues_processing => false,
175
+ :incoming_remote_queue_name => "worker_messages_coming_in",
176
+ :outgoing_remote_queue_name => "worker_messages_going_out")
177
+
178
+ worker.add_message_to_incoming_remote_queue("**")
179
+ worker.run
180
+ end
181
+
182
+ it "should run without incoming queue" do
183
+ worker = StarlingWorker::Base.new(:host => '127.0.0.1',
184
+ :port => 22133,
185
+ :continues_processing => false,
186
+ :outgoing_remote_queue_name => "worker_messages_going_test_out")
187
+
188
+ worker.process do
189
+ "test"
190
+ end
191
+
192
+ worker.run
193
+
194
+ @starling.sizeof(worker.incoming_remote_queue_name).should eql(0)
195
+ @starling.sizeof(worker.outgoing_remote_queue_name).should eql(1)
196
+ end
197
+
198
+ it "should run without outgoing queue" do
199
+ worker = StarlingWorker::Base.new(:host => '127.0.0.1',
200
+ :port => 22133,
201
+ :continues_processing => false,
202
+ :incoming_remote_queue_name => "worker_messages_incoming_test_in")
203
+
204
+ worker.process do |message|
205
+ message.should eql("**")
206
+ message
207
+ end
208
+
209
+ worker.add_message_to_incoming_remote_queue("**")
210
+
211
+ worker.run
212
+
213
+ @starling.sizeof(worker.local_queue.length).should eql(0)
214
+ @starling.sizeof(worker.outgoing_remote_queue_name).should eql(0)
215
+ end
216
+
217
+ it "should run without incoming and outgoing queue" do
218
+ worker = StarlingWorker::Base.new(:host => '127.0.0.1',
219
+ :port => 22133,
220
+ :continues_processing => false)
221
+
222
+ worker.process do
223
+ sleep 0.01
224
+ end
225
+
226
+ worker.run
227
+
228
+ @starling.sizeof(worker.local_queue.length).should eql(0)
229
+ @starling.sizeof(worker.outgoing_remote_queue_name).should eql(0)
230
+ end
231
+
232
+ after do
233
+ Process.kill("INT", @server_pid)
234
+ Process.wait(@server_pid)
235
+ FileUtils.rm(Dir.glob(File.join(@tmp_path, '*')))
236
+ end
237
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fiveruns-starling
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.7.5
5
+ platform: ruby
6
+ authors:
7
+ - Blaine Cook
8
+ - Chris Wanstrath
9
+ - anotherbritt
10
+ - Glenn Rempe
11
+ - Abdul-Rahman Advany
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2008-05-14 00:00:00 -07:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: fiveruns-memcache-client
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ version:
28
+ - !ruby/object:Gem::Dependency
29
+ name: SyslogLogger
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ - !ruby/object:Gem::Dependency
38
+ name: eventmachine
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ description: Starling is a lightweight, transactional, distributed queue server
47
+ email:
48
+ - blaine@twitter.com
49
+ - chris@ozmm.org
50
+ - abdulrahman@advany.com
51
+ executables:
52
+ - starling
53
+ - starling_client
54
+ - starling_top
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.rdoc
59
+ - CHANGELOG
60
+ - LICENSE
61
+ files:
62
+ - README.rdoc
63
+ - LICENSE
64
+ - CHANGELOG
65
+ - Rakefile
66
+ - lib/starling/handler.rb
67
+ - lib/starling/persistent_queue.rb
68
+ - lib/starling/queue_collection.rb
69
+ - lib/starling/server_runner.rb
70
+ - lib/starling/server.rb
71
+ - lib/starling/client_runner.rb
72
+ - lib/starling/client.rb
73
+ - lib/starling/worker.rb
74
+ - lib/starling/thread_pool.rb
75
+ - lib/starling.rb
76
+ - etc/starling.redhat
77
+ - etc/starling.ubuntu
78
+ has_rdoc: true
79
+ homepage: http://github.com/fiveruns/starling/
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --quiet
83
+ - --title
84
+ - starling documentation
85
+ - --opname
86
+ - index.html
87
+ - --line-numbers
88
+ - --main
89
+ - README.rdoc
90
+ - --inline-source
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.0.1
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: Starling is a lightweight, transactional, distributed queue server
112
+ test_files:
113
+ - test/test_starling_server.rb
114
+ - test/test_starling_client.rb
115
+ - test/test_starling_worker.rb