File: 12adapter-tee.t

package info (click to toggle)
libmetrics-any-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 220 kB
  • sloc: perl: 1,295; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download
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
#!/usr/bin/perl

use v5.14;  # package NAME {BLOCK}
use warnings;

use Test2::V0;

use Metrics::Any '$metrics', strict => 0;

package Metrics::Any::Adapter::_ToHash {
   sub new {
      my $class = shift;
      return bless { h => shift }, $class;
   }

   sub make_counter {}
   sub make_distribution {}
   sub make_gauge {}
   sub make_timer {}

   sub _inc { $_[0]->{h}->{$_[1]} += $_[2] }
   no warnings 'once';
   *inc_counter_by = *report_distribution = *inc_gauge_by = *report_timer = \&_inc;
}

my %metrics1;
my %metrics2;

require Metrics::Any::Adapter;
Metrics::Any::Adapter->import( Tee =>
   [ _ToHash => \%metrics1 ],
   [ _ToHash => \%metrics2 ],
);

$metrics->inc_counter( counter => );
$metrics->report_distribution( distribution => 5 );
$metrics->inc_gauge( gauge => );
$metrics->report_timer( timer => 0.1 );

my %expect = (
   'main/counter'      => 1,
   'main/distribution' => 5,
   'main/gauge'        => 1,
   'main/timer'        => 0.1,
);

is( \%metrics1, \%expect, 'Metrics reported to first adapter' );
is( \%metrics2, \%expect, 'Metrics reported to second adapter' );

done_testing;