lib/deimos/test_helpers.rb in deimos-ruby-1.16.3 vs lib/deimos/test_helpers.rb in deimos-ruby-1.16.4
- old
+ new
@@ -18,10 +18,11 @@
def sent_messages
Deimos::Backends::Test.sent_messages
end
# Set the config to the right settings for a unit test
+ # @return [void]
def unit_test!
Deimos.configure do |deimos_config|
deimos_config.logger = Logger.new(STDOUT)
deimos_config.consumers.reraise_errors = true
deimos_config.kafka.seed_brokers ||= ['test_broker']
@@ -29,18 +30,20 @@
deimos_config.producers.backend = :test
end
end
# Kafka test config with avro schema registry
+ # @return [void]
def full_integration_test!
Deimos.configure do |deimos_config|
deimos_config.producers.backend = :kafka
deimos_config.schema.backend = :avro_schema_registry
end
end
# Set the config to the right settings for a kafka test
+ # @return [void]
def kafka_test!
Deimos.configure do |deimos_config|
deimos_config.producers.backend = :kafka
deimos_config.schema.backend = :avro_validation
end
@@ -60,32 +63,37 @@
end
end
# @deprecated
+ # @!visibility private
def stub_producers_and_consumers!
warn('stub_producers_and_consumers! is no longer necessary and this method will be removed in 3.0')
end
# @deprecated
+ # @!visibility private
def stub_producer(_klass)
warn('Stubbing producers is no longer necessary and this method will be removed in 3.0')
end
# @deprecated
+ # @!visibility private
def stub_consumer(_klass)
warn('Stubbing consumers is no longer necessary and this method will be removed in 3.0')
end
# @deprecated
+ # @!visibility private
def stub_batch_consumer(_klass)
warn('Stubbing batch consumers is no longer necessary and this method will be removed in 3.0')
end
# get the difference of 2 hashes.
# @param hash1 [Hash]
# @param hash2 [Hash]
+ # @!visibility private
def _hash_diff(hash1, hash2)
if hash1.nil? || !hash1.is_a?(Hash)
hash2
elsif hash2.nil? || !hash2.is_a?(Hash)
hash1
@@ -94,11 +102,11 @@
delete_if { |k, v| hash2[k] == v }.
merge!(hash2.dup.delete_if { |k, _v| hash1.key?(k) })
end
end
- # :nodoc:
+ # @!visibility private
def _frk_failure_message(topic, message, key=nil, partition_key=nil, was_negated=false)
messages = Deimos::Backends::Test.sent_messages.
select { |m| m[:topic] == topic }.
map { |m| m.except(:topic) }
message_string = ''
@@ -160,27 +168,29 @@
end
end
# Clear all sent messages - e.g. if we want to check that
# particular messages were sent or not sent after a point in time.
+ # @return [void]
def clear_kafka_messages!
Deimos::Backends::Test.sent_messages.clear
end
# Test that a given handler will consume a given payload correctly, i.e.
# that the schema is correct. If
# a block is given, that block will be executed when `consume` is called.
# Otherwise it will just confirm that `consume` is called at all.
- # @param handler_class_or_topic [Class|String] Class which inherits from
+ # @param handler_class_or_topic [Class, String] Class which inherits from
# Deimos::Consumer or the topic as a string
# @param payload [Hash] the payload to consume
# @param call_original [Boolean] if true, allow the consume handler
# to continue as normal. Not compatible with a block.
- # @param ignore_expectation [Boolean] Set to true to not place any
+ # @param skip_expectation [Boolean] Set to true to not place any
# expectations on the consumer. Primarily used internally to Deimos.
# @param key [Object] the key to use.
# @param partition_key [Object] the partition key to use.
+ # @return [void]
def test_consume_message(handler_class_or_topic,
payload,
call_original: false,
key: nil,
partition_key: nil,
@@ -223,10 +233,11 @@
end
# Check to see that a given message will fail due to validation errors.
# @param handler_class [Class]
# @param payload [Hash]
+ # @return [void]
def test_consume_invalid_message(handler_class, payload)
expect {
handler_class.decoder.validate(payload,
schema: handler_class.decoder.schema)
}.to raise_error(Avro::SchemaValidator::ValidationError)
@@ -234,13 +245,18 @@
# Test that a given handler will consume a given batch payload correctly,
# i.e. that the schema is correct. If
# a block is given, that block will be executed when `consume` is called.
# Otherwise it will just confirm that `consume` is called at all.
- # @param handler_class_or_topic [Class|String] Class which inherits from
+ # @param handler_class_or_topic [Class, String] Class which inherits from
# Deimos::Consumer or the topic as a string
# @param payloads [Array<Hash>] the payload to consume
+ # @param keys [Array<Hash,String>]
+ # @param partition_keys [Array<Integer>]
+ # @param call_original [Boolean]
+ # @param skip_expectation [Boolean]
+ # @return [void]
def test_consume_batch(handler_class_or_topic,
payloads,
keys: [],
partition_keys: [],
call_original: false,
@@ -295,9 +311,10 @@
end
# Check to see that a given message will fail due to validation errors.
# @param handler_class [Class]
# @param payloads [Array<Hash>]
+ # @return [void]
def test_consume_batch_invalid_message(handler_class, payloads)
topic_name = 'my-topic'
handler = handler_class.new
allow(handler_class).to receive(:new).and_return(handler)
listener = double('listener',