This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
mri, initial offsets #95
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8b7a31a
add mri script
21190d7
randomize integration test topic
752123b
allow choosing of an inital offset in the MRI consumer
8e89b75
add a type to the invalid offset error
8832ad2
update rdoc section with :offset documentation
3fbe696
update tests with InvalidOffsetError
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -24,14 +24,18 @@ class Consumer | |
| # | ||
| def initialize(topic, opts = {}) | ||
| @topic = topic | ||
|
|
||
| offset = opts.delete(:offset) | ||
| raise "Bad offset: #{offset}" unless valid_offset?(offset) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind typing this exception and defining it in |
||
|
|
||
| if Hermann.jruby? | ||
| zookeepers, group_id = require_values_at(opts, :zookeepers, :group_id) | ||
|
|
||
| @internal = Hermann::Provider::JavaSimpleConsumer.new(zookeepers, group_id, topic, opts) | ||
| else | ||
| brokers, partition = require_values_at(opts, :brokers, :partition) | ||
|
|
||
| @internal = Hermann::Lib::Consumer.new(topic, brokers, partition) | ||
| @internal = Hermann::Lib::Consumer.new(topic, brokers, partition, offset) | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -49,6 +53,12 @@ def shutdown | |
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def valid_offset?(offset) | ||
| offset.nil? || offset.is_a?(Fixnum) || offset == :start || offset == :end | ||
| end | ||
|
|
||
| def require_values_at(opts, *args) | ||
| args.map do |a| | ||
| raise "Please provide :#{a} option!" unless opts[a] | ||
|
|
||
This file contains hidden or 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' | ||
|
|
||
| $LOAD_PATH << File.dirname(__FILE__) + "/../lib" | ||
| $LOAD_PATH << File.dirname(__FILE__) + "/../ext" | ||
| require 'hermann' | ||
| require 'hermann/consumer' | ||
|
|
||
| t1 = 0 | ||
| threads = [] | ||
| 100.times do |i| | ||
| threads << Thread.new do | ||
| puts "booting #{i}" | ||
| c = Hermann::Consumer.new( "maxwell", brokers: "localhost:9092", partition: i, offset: :start) | ||
| c.consume() do | ||
| |msg| puts("Received: #{msg}") | ||
| if(t1 == 0) | ||
| t1 = Time.now | ||
| end | ||
| t2 = Time.now | ||
| elapsed = t2 - t1 | ||
| puts("Total elapsed time: #{elapsed} seconds") | ||
| end | ||
| end | ||
| end | ||
| threads.each(&:join) |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,8 @@ | |
| let(:topic) { 'rspec' } | ||
| let(:brokers) { 'localhost:1337' } | ||
| let(:partition) { 1 } | ||
| let(:opts) { { :brokers => brokers, :partition => partition } } | ||
| let(:offset) { nil } | ||
| let(:opts) { { :brokers => brokers, :partition => partition, :offset => offset } } | ||
|
|
||
|
|
||
| context "on C ruby", :platform => :mri do | ||
|
|
@@ -36,6 +37,11 @@ | |
| let(:topic) { '' } | ||
| it_behaves_like 'an error condition' | ||
| end | ||
|
|
||
| context 'with a bad offset' do | ||
| let(:offset) { :foo } | ||
| it_behaves_like 'an error condition' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this test needs to be updated per Travis failures |
||
| end | ||
| end | ||
|
|
||
| describe '#shutdown' do | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you update the RDoc to include the :
offsetoption documentation including mention of:startand:end