From dev-return-2295-archive-asf-public=cust-asf.ponee.io@servicecomb.apache.org Thu Mar 1 01:05:12 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 6FD95180657 for ; Thu, 1 Mar 2018 01:05:11 +0100 (CET) Received: (qmail 95605 invoked by uid 500); 1 Mar 2018 00:05:10 -0000 Mailing-List: contact dev-help@servicecomb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@servicecomb.apache.org Delivered-To: mailing list dev@servicecomb.apache.org Received: (qmail 95594 invoked by uid 99); 1 Mar 2018 00:05:10 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2018 00:05:10 +0000 From: GitBox To: dev@servicecomb.apache.org Subject: [GitHub] zhengyangyong commented on a change in pull request #562: [SCB-358] fix bug for monitor output id that register only name without any tags Message-ID: <151986270998.18766.8429162428185965775.gitbox@gitbox.apache.org> Date: Thu, 01 Mar 2018 00:05:09 -0000 zhengyangyong commented on a change in pull request #562: [SCB-358] fix bug for monitor output id that register only name without any tags URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/562#discussion_r171427152 ########## File path: foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/TestMetric.java ########## @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.servicecomb.foundation.metrics.publish; + +import org.apache.servicecomb.foundation.common.exceptions.ServiceCombException; +import org.junit.Assert; +import org.junit.Test; + +public class TestMetric { + + @Test + public void testNewMetric() throws Exception { + + Metric metric = new Metric("Key", 100); + Assert.assertEquals(0, metric.getTagsCount()); + + metric = new Metric("Key(A=1)", 100); + Assert.assertEquals(1, metric.getTagsCount()); + Assert.assertEquals(true, metric.containsTagKey("A")); + + metric = new Metric("Key(A=1,B=X)", 100); + Assert.assertEquals(2, metric.getTagsCount()); + Assert.assertEquals(true, metric.containsTagKey("A")); + Assert.assertEquals(true, metric.containsTagKey("B")); + Assert.assertEquals("1", metric.getTagValue("A")); + Assert.assertEquals("X", metric.getTagValue("B")); + + checkBadIdFormat("Key("); + checkBadIdFormat("Key)"); + checkBadIdFormat("Key()"); + + checkBadIdFormat("Key(X)"); + checkBadIdFormat("Key(X"); + checkBadIdFormat("Key(X))"); + checkBadIdFormat("Key((X)"); + + checkBadIdFormat("Key(X=)"); + checkBadIdFormat("Key(X="); + checkBadIdFormat("Key(X=))"); + checkBadIdFormat("Key((X=)"); + + checkBadIdFormat("Key(X=,)"); + checkBadIdFormat("Key(X=,"); + checkBadIdFormat("Key(X=,))"); + checkBadIdFormat("Key((X=,)"); + + checkBadIdFormat("Key(X=,Y)"); + checkBadIdFormat("Key(X=,Y"); + checkBadIdFormat("Key(X=,Y))"); + checkBadIdFormat("Key((X=,Y)"); + + checkBadIdFormat("Key(X=1,Y)"); + checkBadIdFormat("Key(X=1,Y"); + checkBadIdFormat("Key(X=1,Y))"); + checkBadIdFormat("Key((X=1,Y)"); + + checkBadIdFormat("Key(X=1))"); + checkBadIdFormat("Key((X=1)"); + + checkBadIdFormat("Key(X=1) "); + checkBadIdFormat("Key(X=1,Y=2)Z"); + + checkBadIdFormat("Key(X=1)()"); + checkBadIdFormat("Key(X=1)(Y=1)"); + } + + @Test + public void checkMetricContainsTag() throws Exception { + Metric metric = new Metric("Key(A=1,B=X)", 100); + Assert.assertEquals(true, metric.containsTag("A", "1")); + + try { + metric.containsTag("A"); + throw new Exception("CheckFailed"); + } + //ignore because throw exception is correct + catch (ServiceCombException ignore) { + } + + try { + metric.containsTag("A", "1", "B"); + throw new Exception("CheckFailed"); + } + //ignore because throw exception is correct + catch (ServiceCombException ignore) { + } + + try { + metric.containsTag("A", "1", "B", "X", "C"); + throw new Exception("CheckFailed"); + } + //ignore because throw exception is correct + catch (ServiceCombException ignore) { + } + } + + private void checkBadIdFormat(String id) throws Exception { + try { + new Metric(id, 100); + throw new Exception("CheckFailed"); Review comment: Done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services