Class: Polyn::Testing::MockPullSubscription
- Inherits:
-
Object
- Object
- Polyn::Testing::MockPullSubscription
- Defined in:
- lib/polyn/testing/mock_pull_subscription.rb
Overview
Mock Pull Subscription for applications to use in testing
Instance Method Summary collapse
- #fetch(batch = 1, **_params) ⇒ Object
-
#initialize(mock_nats, **opts) ⇒ MockPullSubscription
constructor
A new instance of MockPullSubscription.
- #update_cursor(end_pos) ⇒ Object
- #update_stream ⇒ Object
Constructor Details
#initialize(mock_nats, **opts) ⇒ MockPullSubscription
Returns a new instance of MockPullSubscription.
8 9 10 11 12 13 14 15 16 |
# File 'lib/polyn/testing/mock_pull_subscription.rb', line 8 def initialize(mock_nats, **opts) @mock_nats = mock_nats @real_nats = mock_nats.nats @subject = opts.fetch(:subject) @consumer_name = opts.fetch(:consumer_name) @stream = update_stream @delivery_cursor = 0 @mock_nats.add_consumer(self) end |
Instance Method Details
#fetch(batch = 1, **_params) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/polyn/testing/mock_pull_subscription.rb', line 18 def fetch(batch = 1, **_params) start_pos = @delivery_cursor end_pos = start_pos + batch - 1 update_cursor(end_pos) @stream[start_pos..end_pos] end |
#update_cursor(end_pos) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/polyn/testing/mock_pull_subscription.rb', line 32 def update_cursor(end_pos) next_pos = end_pos + 1 @delivery_cursor = if @stream[next_pos] next_pos else @stream.length end end |
#update_stream ⇒ Object
25 26 27 28 29 30 |
# File 'lib/polyn/testing/mock_pull_subscription.rb', line 25 def update_stream @stream = @mock_nats..filter do || Polyn::Naming.subject_matches?(.subject, @subject) end @stream end |