Class: JetstreamBridge::TestHelpers::MockNats::MockSubscription

Inherits:
Object
  • Object
show all
Defined in:
lib/jetstream_bridge/test_helpers/mock_nats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subject:, durable_name:, storage:, stream_name:, options:) ⇒ MockSubscription



413
414
415
416
417
418
419
420
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 413

def initialize(subject:, durable_name:, storage:, stream_name:, options:)
  @subject = subject
  @durable_name = durable_name
  @storage = storage
  @stream_name = stream_name
  @options = options
  @unsubscribed = false
end

Instance Attribute Details

#durable_nameObject (readonly)

Returns the value of attribute durable_name.



411
412
413
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 411

def durable_name
  @durable_name
end

#stream_nameObject (readonly)

Returns the value of attribute stream_name.



411
412
413
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 411

def stream_name
  @stream_name
end

#subjectObject (readonly)

Returns the value of attribute subject.



411
412
413
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 411

def subject
  @subject
end

Instance Method Details

#fetch(batch_size, timeout: 5) ⇒ Object



422
423
424
425
426
427
428
429
430
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 422

def fetch(batch_size, timeout: 5)
  raise NATS::JetStream::Error, 'consumer not found' if @unsubscribed

  @storage.fetch_messages(@subject, @durable_name, batch_size, timeout)
rescue StandardError => e
  raise NATS::IO::Timeout if timeout && e.is_a?(Timeout::Error)

  raise
end

#unsubscribeObject



432
433
434
# File 'lib/jetstream_bridge/test_helpers/mock_nats.rb', line 432

def unsubscribe
  @unsubscribed = true
end