Skip to content

Commit

Permalink
Loosen privacy of Client#write to protected so subclasses can decorat…
Browse files Browse the repository at this point in the history
…e metrics before the transport
  • Loading branch information
Sean Treadway committed Jun 18, 2012
1 parent 3ddbe0b commit b24a1a3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/statsy.rb
@@ -1,7 +1,7 @@
# Client to access statsd service authored by etsy. Yay etsy!
# https://github.com/etsy/statsd
module Statsy
VERSION="0.1.2"
VERSION="0.1.3"

module Transport
require 'socket'
Expand Down Expand Up @@ -119,7 +119,7 @@ def batch
self
end

private
protected
def write(stat, value, modifier, sampling)
if sampling < 1
if Kernel.rand < sampling
Expand Down
26 changes: 26 additions & 0 deletions test/statsy_test.rb
@@ -1,6 +1,32 @@
require 'test/unit'
require File.expand_path('../../lib/statsy', __FILE__)

class SubclassUnit < Test::Unit::TestCase
class Frob < Statsy::Client
protected
def write(stat, value, modifier, sampling)
super("frob", value, modifier, sampling)
end
end

def setup
@transport = Statsy::Transport::Queue.new
@client = Frob.new(@transport)
end

def test_subclass_should_override_write_with_full_frobbing
transport = Statsy::Transport::Queue.new
client = Statsy::Client.new()

@client.increment("foo.stat", 1)
@client.measure("foo.mess", 100)

assert_equal 2, @transport.size
assert_equal "frob:1|c", @transport.shift
assert_equal "frob:100|ms", @transport.shift
end
end

class Unit < Test::Unit::TestCase
def setup
@transport = Statsy::Transport::Queue.new
Expand Down

0 comments on commit b24a1a3

Please sign in to comment.