wujimin commented on a change in pull request #575: [SCB-369] Extract info from spectator measurement URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/575#discussion_r173089137
########## File path: foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/publish/spectator/TestMeasurementTree.java ########## @@ -0,0 +1,88 @@ +/* + * 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.spectator; + +import java.util.concurrent.TimeUnit; + +import org.hamcrest.Matchers; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.netflix.spectator.api.ManualClock; +import com.netflix.spectator.api.Registry; +import com.netflix.spectator.api.Statistic; +import com.netflix.spectator.api.Timer; +import com.netflix.spectator.servo.ServoRegistry; + +public class TestMeasurementTree { + MeasurementTree tree = new MeasurementTree(); + + ManualClock clock = new ManualClock(); + + Registry registry = new ServoRegistry(clock); + + Timer timer; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setup() { + System.setProperty("servo.pollers", "1000"); + timer = registry.timer("id", + "g1", + "g1v", + "g2", + "g2v", + "t3", + "t3v", + "t4", + "t4v"); + registry.counter("id_notCare"); + } + + @Test + public void from() { + timer.record(10, TimeUnit.SECONDS); + timer.record(2, TimeUnit.SECONDS); + + clock.setWallTime(clock.wallTime() + 1000); + + MeasurementGroupConfig config = new MeasurementGroupConfig("id", "g1", "g2", Statistic.count.key()); + tree.from(registry.iterator(), config); + + Assert.assertEquals(1, tree.getChildren().size()); + + MeasurementNode node = tree.findChild("id", "g1v", "g2v"); + System.out.println(node.getMeasurements()); Review comment: already add spectator information to license file ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services