Sha256: 8934c315e9930ef875b858c12b5d3998370e9d0690f2bccfbcf585ff9ca1fa01

Contents?: true

Size: 793 Bytes

Versions: 2

Compression:

Stored size: 793 Bytes

Contents

module DeliveryBoy

  # A fake implementation that is useful for testing.
  class Fake
    FakeMessage = Struct.new(:value, :topic, :key, :offset, :partition, :partition_key)

    def initialize
      @messages = Hash.new {|h, k| h[k] = [] }
    end

    def deliver(value, topic:, key: nil, partition: nil, partition_key: nil)
      offset = @messages[topic].count
      message = FakeMessage.new(value, topic, key, offset, partition, partition_key)

      @messages[topic] << message

      nil
    end

    alias deliver_async! deliver

    def shutdown
      clear
    end

    # Clear all messages stored in memory.
    def clear
      @messages.clear
    end

    # Return all messages written to the specified topic.
    def messages_for(topic)
      @messages[topic]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
delivery_boy-0.2.6 lib/delivery_boy/fake.rb
delivery_boy-0.2.5 lib/delivery_boy/fake.rb