File: riemann_reporter_test.rb

package info (click to toggle)
ruby-metriks 0.9.9.8-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: ruby: 1,877; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 2,129 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require 'test_helper'
require 'thread_error_handling_tests'

require 'metriks/reporter/riemann'

class RiemannReporterTest < Test::Unit::TestCase
  include ThreadErrorHandlingTests

  def build_reporter(options={})
    Metriks::Reporter::Riemann.new({
      :host => "foo",
      :port => 1234,
      :registry => @registry,
      :default_event => {:host => "h"}
    }.merge(options))
  end

  def setup
    @registry = Metriks::Registry.new
    @reporter = build_reporter
  end

  def teardown
    @reporter.stop
    @registry.stop
  end

  def test_init
    assert_equal @reporter.client.host, "foo"
    assert_equal @reporter.client.port, 1234
  end

  def test_write
    @registry.meter('meter.testing').mark
    @registry.counter('counter.testing').increment
    @registry.timer('timer.testing').update(1.5)
    @registry.histogram('histogram.testing').update(1.5)
    @registry.utilization_timer('utilization_timer.testing').update(1.5)
    @registry.gauge('gauge.testing') { 123 }

    @reporter.client.expects(:<<).at_least_once
    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "meter.testing count",
      :metric => 1,
      :tags => ["meter"],
      :ttl => 90
    )
    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "counter.testing count",
      :metric => 1,
      :tags => ["counter"],
      :ttl => 90
    )
    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "timer.testing max",
      :metric => 1.5,
      :tags => ["timer"],
      :ttl => 90
    )
    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "histogram.testing max",
      :metric => 1.5,
      :tags => ["histogram"],
      :ttl => 90
    )
    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "utilization_timer.testing mean",
      :metric => 1.5,
      :tags => ["utilization_timer"],
      :ttl => 90
    )

    @reporter.client.expects(:<<).with(
      :host => "h",
      :service => "gauge.testing value",
      :metric => 123,
      :tags => ["gauge"],
      :ttl => 90
    )

    @reporter.write
  end
end