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
|
//go:build !functional
package sarama
import (
"testing"
"github.com/rcrowley/go-metrics"
)
func TestGetOrRegisterHistogram(t *testing.T) {
metricRegistry := metrics.NewRegistry()
histogram := getOrRegisterHistogram("name", metricRegistry)
if histogram == nil {
t.Error("Unexpected nil histogram")
}
// Fetch the metric
foundHistogram := metricRegistry.Get("name")
if foundHistogram != histogram {
t.Error("Unexpected different histogram", foundHistogram, histogram)
}
// Try to register the metric again
sameHistogram := getOrRegisterHistogram("name", metricRegistry)
if sameHistogram != histogram {
t.Error("Unexpected different histogram", sameHistogram, histogram)
}
}
func TestGetMetricNameForBroker(t *testing.T) {
metricName := getMetricNameForBroker("name", &Broker{id: 1})
if metricName != "name-for-broker-1" {
t.Error("Unexpected metric name", metricName)
}
}
func Benchmark_getMetricNameForTopic(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
name := getMetricNameForTopic("sarama", "says.hello")
if name != "sarama-for-topic-says_hello" {
b.Fail()
}
}
}
func Benchmark_getMetricNameForBroker(b *testing.B) {
broker := &Broker{id: 1965}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
name := getMetricNameForBroker("summer", broker)
if name != "summer-for-broker-1965" {
b.Fail()
}
}
}
|