Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
196 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--colour | ||
--order rand | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'nsq-ruby', git: 'https://github.com/aemadrid/nsq-ruby.git', ref: '4fe4079' | ||
gem 'nsq-ruby', git: 'https://github.com/aemadrid/nsq-ruby.git', ref: 'eb74b53eec' | ||
|
||
# Specify your gem's dependencies in tiki.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,5 +92,7 @@ def logger | |
@logger ||= Logger.new(STDOUT).tap { |x| x.level = Logger::INFO } | ||
end | ||
|
||
logger | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
describe 'simple consumers', integration: true do | ||
let(:consumer) { SimpleConsumer } | ||
let(:consumers) { [MultipleFirstConsumer, MultipleSecondConsumer] } | ||
|
||
it 'receives multiple messages' do | ||
(1..4).each { |nr| Tiki::Torch.publish consumer.topic, "a#{nr}" } | ||
max = 4 | ||
max.times { |nr| Tiki::Torch.publish consumers.first.topic, "a#{nr + 1}" } | ||
sleep 1 | ||
|
||
# Get all messages | ||
expect($messages.payloads).to eq %w{ a1 a2 a3 a4 } | ||
expect($messages.payloads.sort).to eq %w{ a1 a1 a2 a2 a3 a3 a4 a4 } | ||
# All different threads | ||
expect($messages.thread_ids.uniq.size).to eq 4 | ||
expect($messages.thread_ids.uniq.size).to eq $messages.size | ||
# For one consumer | ||
expect($messages.consumer_count(consumers.first.name)).to eq max | ||
expect($messages.consumer_count(consumers.last.name)).to eq max | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
describe 'simple consumers', integration: true do | ||
let(:consumer) { SimpleConsumer } | ||
|
||
it 'receives multiple messages' do | ||
max = 4 | ||
max.times { |nr| Tiki::Torch.publish consumer.topic, "a#{nr + 1}" } | ||
sleep 1 | ||
|
||
# Got all messages | ||
expect($messages.payloads).to eq %w{ a1 a2 a3 a4 } | ||
# For one consumer | ||
expect($messages.consumer_count(consumer.name)).to eq max | ||
# All different threads | ||
expect($messages.thread_ids.uniq.size).to eq $messages.size | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
|
||
ENV['APP_NAME'] = 'Alice' | ||
|
||
Bundler.require(:default, :development, :test) | ||
|
||
require 'tiki_torch' | ||
|
||
require 'support/helpers' | ||
require 'support/consumers' | ||
|
||
RSpec.configure do |config| | ||
config.mock_with :rspec do |mocks| | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
config.before(:each, :integration => true) do | ||
$messages = TestingHelpers::Messages.new | ||
setup_torch | ||
end | ||
config.after(:each, :integration => true) do | ||
take_down_torch | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class SimpleConsumer < Tiki::Torch::Consumer | ||
|
||
topic 'test.single.events' | ||
channel 'events' | ||
max_in_flight 1 | ||
|
||
def process | ||
debug "message : #{message.local_methods}" | ||
debug "message : #{message.inspect}" | ||
$messages.add self.class.name, event | ||
sleep payload[:sleep_time] if payload.is_a?(Hash) && payload[:sleep_time] | ||
end | ||
|
||
end | ||
|
||
class MultipleFirstConsumer < Tiki::Torch::Consumer | ||
|
||
topic 'test.multiple.events' | ||
channel 'first' | ||
max_in_flight 1 | ||
|
||
def process | ||
$messages.add self.class.name, event | ||
sleep payload[:sleep_time] if payload.is_a?(Hash) && payload[:sleep_time] | ||
end | ||
|
||
end | ||
|
||
class MultipleSecondConsumer < Tiki::Torch::Consumer | ||
|
||
topic 'test.multiple.events' | ||
channel 'second' | ||
max_in_flight 1 | ||
|
||
def process | ||
$messages.add self.class.name, event | ||
sleep payload[:sleep_time] if payload.is_a?(Hash) && payload[:sleep_time] | ||
end | ||
|
||
end | ||
|
||
Nsq::Message | ||
Nsq::Connection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module TestingHelpers | ||
class Messages | ||
|
||
Message = Struct.new :consumer, :id, :payload, :properties, :thread_id | ||
|
||
attr_reader :all | ||
|
||
def initialize | ||
@all = ThreadSafe::Array.new | ||
end | ||
|
||
def size | ||
all.size | ||
end | ||
|
||
def add(class_name, event) | ||
all << Message.new(class_name, event.message_id, event.payload, event.properties, Thread.current.object_id) | ||
end | ||
|
||
def add_payload(class_name, payload) | ||
all << Message.new(class_name, nil, payload, nil, Thread.current.object_id) | ||
end | ||
|
||
def message_ids | ||
all.map { |x| x.message_id } | ||
end | ||
|
||
def payloads | ||
all.map { |x| x.payload } | ||
end | ||
|
||
def properties | ||
all.map { |x| x.properties } | ||
end | ||
|
||
def thread_ids | ||
all.map { |x| x.thread_id } | ||
end | ||
|
||
def consumer_count(class_name) | ||
all.count { |x| x.consumer == class_name } | ||
end | ||
|
||
end | ||
end | ||
|
||
def setup_torch | ||
Tiki::Torch.configure do |c| | ||
if (lkd = ENV['NSLOOKUPD_ADDRESS']) | ||
c.nsqlookupd = lkd | ||
elsif (nsd = ENV['NSQD_ADDRESS']) | ||
c.nsqd = nsd | ||
else | ||
c.nsqd = 'localhost:4150' | ||
end | ||
c.colorized = false | ||
end | ||
# Tiki::Torch.logger.level = Logger::DEBUG | ||
Tiki::Torch.start_polling | ||
end | ||
|
||
def take_down_torch | ||
Tiki::Torch.shutdown | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters