Sha256: 3ebda2423871cbdebbc44257fcdab4b6d08fdf64c1d0f9e361c0398ce322a469

Contents?: true

Size: 764 Bytes

Versions: 12

Compression:

Stored size: 764 Bytes

Contents

require "logstash/devutils/rspec/spec_helper"
require "socket"

class StatsdServer

  attr_reader :received, :port

  def initialize
    @sync_lock = Mutex.new
    @terminated = false
    @received   = []
  end

  def register(port)
    @port   = port
    @socket = UDPSocket.new
    @socket.bind("127.0.0.1", port)
  end

  def run(port)
    register(port)
    Thread.new do
      while(!closed?)
        metric, _ = @socket.recvfrom(100)
        append(metric)
      end
    end
    self
  end

  def append(metric)
    @sync_lock.synchronize do
      @received << metric
    end
  end

  def close
    @sync_lock.synchronize do
      @terminated = true
    end
  end

  def closed?
    @terminated == true
  end

end

RSpec.configure do |c|
  srand(c.seed)
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
logstash-output-statsd-3.1.5 spec/spec_helper.rb
logstash-output-statsd-3.1.4 spec/spec_helper.rb
logstash-output-statsd-3.1.3 spec/spec_helper.rb
logstash-output-statsd-3.1.2 spec/spec_helper.rb
logstash-output-statsd-3.1.1 spec/spec_helper.rb
logstash-output-statsd-3.0.1 spec/spec_helper.rb
logstash-output-statsd-3.0.0 spec/spec_helper.rb
logstash-output-statsd-2.0.7 spec/spec_helper.rb
logstash-output-statsd-2.0.5 spec/spec_helper.rb
logstash-output-statsd-2.0.4 spec/spec_helper.rb
logstash-output-statsd-2.0.3 spec/spec_helper.rb
logstash-output-statsd-2.0.2 spec/spec_helper.rb