@Test
public void testStartTiming() {

    CollectorRegistry registry = new CollectorRegistry();
    ConcurrentHashMap<String, Collector> namesToCollectors = new ConcurrentHashMap<>();
    String namespace = "metric_test";
    // 1. no labels (default)
    PrometheusMetric metric_1 = new PrometheusMetric(registry, namesToCollectors, null, namespace);
    String metricName_1 = "test_timer_1";
    String fullMetricName_1 = namespace + "_" + metricName_1 + "_" + PrometheusMetric.TIMER_UNIT + "_sum";
    String requestDomainName_1 = "request_domain_1";
    String principalDomainName_1 = "principal_domain_1";
    // assertions
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{requestDomainName_1, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{"", principalDomainName_1, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{requestDomainName_1, principalDomainName_1, "", "", ""}));
    metric_1.stopTiming(metric_1.startTiming(metricName_1, null));
    metric_1.stopTiming(metric_1.startTiming(metricName_1, requestDomainName_1));
    metric_1.stopTiming(metric_1.startTiming(metricName_1, null, principalDomainName_1));
    metric_1.stopTiming(metric_1.startTiming(metricName_1, requestDomainName_1, principalDomainName_1));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{requestDomainName_1, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{"", principalDomainName_1, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_1, this.labelNames, new String[]{requestDomainName_1, principalDomainName_1, "", "", ""}));
    // 2. only request domain
    PrometheusMetric metric_2 = new PrometheusMetric(registry, namesToCollectors, null, namespace, true, false, false, false, false);
    String metricName_2 = "test_timer_2";
    String fullMetricName_2 = namespace + "_" + metricName_2 + "_" + PrometheusMetric.TIMER_UNIT + "_sum";
    String requestDomainName_2 = "request_domain_2";
    String principalDomainName_2 = "principal_domain_2";
    // assertions
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{requestDomainName_2, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{"", principalDomainName_2, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{requestDomainName_2, principalDomainName_2, "", "", ""}));
    metric_2.stopTiming(metric_2.startTiming(metricName_2, null));
    metric_2.stopTiming(metric_2.startTiming(metricName_2, requestDomainName_2));
    metric_2.stopTiming(metric_2.startTiming(metricName_2, null, principalDomainName_2));
    metric_2.stopTiming(metric_2.startTiming(metricName_2, requestDomainName_2, principalDomainName_2));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{requestDomainName_2, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{"", principalDomainName_2, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_2, this.labelNames, new String[]{requestDomainName_2, principalDomainName_2, "", "", ""}));
    // 3. only principal domain
    PrometheusMetric metric_3 = new PrometheusMetric(registry, namesToCollectors, null, namespace, false, true, false, false, false);
    String metricName_3 = "test_timer_3";
    String fullMetricName_3 = namespace + "_" + metricName_3 + "_" + PrometheusMetric.TIMER_UNIT + "_sum";
    String requestDomainName_3 = "request_domain_3";
    String principalDomainName_3 = "principal_domain_3";
    // assertions
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{requestDomainName_3, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{"", principalDomainName_3, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{requestDomainName_3, principalDomainName_3, "", "", ""}));
    metric_3.stopTiming(metric_3.startTiming(metricName_3, null));
    metric_3.stopTiming(metric_3.startTiming(metricName_3, requestDomainName_3));
    metric_3.stopTiming(metric_3.startTiming(metricName_3, null, principalDomainName_3));
    metric_3.stopTiming(metric_3.startTiming(metricName_3, requestDomainName_3, principalDomainName_3));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{requestDomainName_3, "", "", "", ""}));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{"", principalDomainName_3, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_3, this.labelNames, new String[]{requestDomainName_3, principalDomainName_3, "", "", ""}));
    // 4. enable both labels
    PrometheusMetric metric_4 = new PrometheusMetric(registry, namesToCollectors, null, namespace, true, true, false, false, false);
    String metricName_4 = "test_timer_4";
    String fullMetricName_4 = namespace + "_" + metricName_4 + "_" + PrometheusMetric.TIMER_UNIT + "_sum";
    String requestDomainName_4 = "request_domain_4";
    String principalDomainName_4 = "principal_domain_4";
    // assertions
    Assert.assertNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{requestDomainName_4, "", "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{"", principalDomainName_4, "", "", ""}));
    Assert.assertNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{requestDomainName_4, principalDomainName_4, "", "", ""}));
    metric_4.stopTiming(metric_4.startTiming(metricName_4, null));
    metric_4.stopTiming(metric_4.startTiming(metricName_4, requestDomainName_4));
    metric_4.stopTiming(metric_4.startTiming(metricName_4, null, principalDomainName_4));
    metric_4.stopTiming(metric_4.startTiming(metricName_4, requestDomainName_4, principalDomainName_4));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{"", "", "", "", ""}));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{requestDomainName_4, "", "", "", ""}));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{"", principalDomainName_4, "", "", ""}));
    Assert.assertNotNull(registry.getSampleValue(fullMetricName_4, this.labelNames, new String[]{requestDomainName_4, principalDomainName_4, "", "", ""}));
}