Update vendor/ for the last commit
[debiancodesearch.git] / vendor / github.com / uber / jaeger-client-go / rpcmetrics / metrics_test.go
blob45059139453546356e13e21504c565d81d1ec9f9
1 // Copyright (c) 2017 Uber Technologies, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
21 package rpcmetrics
23 import (
24 "testing"
26 "github.com/stretchr/testify/assert"
27 "github.com/uber/jaeger-lib/metrics"
28 "github.com/uber/jaeger-lib/metrics/testutils"
31 // E.g. tags("key", "value", "key", "value")
32 func tags(kv ...string) map[string]string {
33 m := make(map[string]string)
34 for i := 0; i < len(kv)-1; i += 2 {
35 m[kv[i]] = kv[i+1]
37 return m
40 func endpointTags(endpoint string, kv ...string) map[string]string {
41 return tags(append([]string{"endpoint", endpoint}, kv...)...)
44 func TestMetricsByEndpoint(t *testing.T) {
45 met := metrics.NewLocalFactory(0)
46 mbe := newMetricsByEndpoint(met, DefaultNameNormalizer, 2)
48 m1 := mbe.get("abc1")
49 m2 := mbe.get("abc1") // from cache
50 m2a := mbe.getWithWriteLock("abc1") // from cache in double-checked lock
51 assert.Equal(t, m1, m2)
52 assert.Equal(t, m1, m2a)
54 m3 := mbe.get("abc3")
55 m4 := mbe.get("overflow")
56 m5 := mbe.get("overflow2")
58 for _, m := range []*Metrics{m1, m2, m2a, m3, m4, m5} {
59 m.RequestCountSuccess.Inc(1)
62 testutils.AssertCounterMetrics(t, met,
63 testutils.ExpectedMetric{Name: "requests", Tags: endpointTags("abc1", "error", "false"), Value: 3},
64 testutils.ExpectedMetric{Name: "requests", Tags: endpointTags("abc3", "error", "false"), Value: 1},
65 testutils.ExpectedMetric{Name: "requests", Tags: endpointTags("other", "error", "false"), Value: 2},