This is an automated email from the ASF dual-hosted git repository. wujimin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 99ac3b75b5d02f7c5464ed737be0c2fcac4b7d77 Author: wujimin <wuji...@huawei.com> AuthorDate: Wed Apr 4 17:05:32 2018 +0800 SCB-445 delete old performance stat mechanism --- .../servicecomb/foundation/metrics/Metrics.java | 81 ----------- .../foundation/metrics/MetricsConfig.java | 46 ------ .../foundation/metrics/MetricsThread.java | 68 --------- .../foundation/metrics/performance/PerfResult.java | 93 ------------ .../foundation/metrics/performance/PerfStat.java | 37 ----- .../metrics/performance/PerfStatContext.java | 52 ------- .../metrics/performance/PerfStatData.java | 161 --------------------- .../metrics/performance/PerfStatImpl.java | 91 ------------ .../metrics/performance/PerfStatMonitor.java | 91 ------------ .../metrics/performance/PerfStatMonitorMgr.java | 83 ----------- .../metrics/performance/PerfStatSuccFail.java | 50 ------- .../resources/META-INF/spring/metrics.bean.xml | 27 ---- .../foundation/metrics/TestMetrics.java | 35 ----- .../foundation/metrics/TestMetricsThread.java | 47 ------ .../metrics/performance/TestPerfResult.java | 70 --------- .../metrics/performance/TestPerfStatContext.java | 68 --------- .../metrics/performance/TestPerfStatData.java | 83 ----------- .../metrics/performance/TestPerfStatImpl.java | 70 --------- .../metrics/performance/TestPerfStatMonitor.java | 56 ------- .../performance/TestPerfStatMonitorMgr.java | 68 --------- .../metrics/performance/TestPerfStatSuccFail.java | 48 ------ 21 files changed, 1425 deletions(-) diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/Metrics.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/Metrics.java deleted file mode 100644 index ae7a47f..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/Metrics.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.servicecomb.foundation.common.CommonThread; -import org.apache.servicecomb.foundation.metrics.performance.PerfStat; -import org.apache.servicecomb.foundation.metrics.performance.PerfStatMonitorMgr; -import org.apache.servicecomb.foundation.metrics.performance.PerfStatSuccFail; - -/** - * Metrics - * core layer performance logger - * - */ -public class Metrics extends CommonThread { - // 每个线程只在本线程内部做统计,不涉及多线程并发 - // 每个周期,统计线程会对所有线程做一次汇总,并与前一周期结果做对比,得出本周期的统计数据 - protected static final ThreadLocal<Map<String, PerfStatSuccFail>> LOCAL_PERF_STAT_MAP = new ThreadLocal<>(); - - private static PerfStatMonitorMgr perfMonitorMgr = new PerfStatMonitorMgr(); - - public static void onCycle() throws Exception { - long msNow = System.currentTimeMillis(); - - synchronized (perfMonitorMgr) { - perfMonitorMgr.onCycle(msNow, MetricsConfig.getMsCycle()); - } - } - - public static long getMsTick() { - return MetricsThread.getMsTick(); - } - - public static void registerPerfStat(PerfStat perfStat, int index) { - synchronized (perfMonitorMgr) { - perfMonitorMgr.registerPerfStat(perfStat, index); - } - } - - public static PerfStatSuccFail getOrCreateLocalPerfStat(String name, int index) { - Map<String, PerfStatSuccFail> map = LOCAL_PERF_STAT_MAP.get(); - if (map == null) { - map = new HashMap<>(); - LOCAL_PERF_STAT_MAP.set(map); - } - - PerfStatSuccFail perfStat = map.get(name); - if (perfStat == null) { - perfStat = new PerfStatSuccFail(name); - map.put(name, perfStat); - - registerPerfStat(perfStat, index); - } - - return perfStat; - } - - public static Map<String, PerfStat> getMonitorPerfStat() { - synchronized (perfMonitorMgr) { - return perfMonitorMgr.getMonitorPerfStat(); - } - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConfig.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConfig.java deleted file mode 100644 index 3787434..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsConfig.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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; - -import org.springframework.beans.factory.InitializingBean; - -import com.netflix.config.DynamicPropertyFactory; - -public class MetricsConfig implements InitializingBean { - - private static final int DEFAULT_METRICS_CYCLE = 60000; - - public static int getMsCycle() { - return DynamicPropertyFactory.getInstance() - .getIntProperty("cse.metrics.cycle.ms", DEFAULT_METRICS_CYCLE) - .get(); - } - - public static boolean isEnable() { - return DynamicPropertyFactory.getInstance().getBooleanProperty("cse.metrics.enabled", false).get(); - } - - @Override - public void afterPropertiesSet() throws Exception { - if (!isEnable()) { - return; - } - - new MetricsThread().start(); - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsThread.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsThread.java deleted file mode 100644 index a1e7c39..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/MetricsThread.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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; - -import org.apache.servicecomb.foundation.common.CommonThread; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MetricsThread extends CommonThread { - private static final Logger LOGGER = LoggerFactory.getLogger(MetricsThread.class); - - private static final long SECOND_MILLS = 1000; - - // 从进程启动开始,每秒加1000 - // 这不是一个精确值,用于不关注精度的超时检测 - private static long msTick = 0; - - public MetricsThread() { - setName("metrics"); - } - - @Override - public void run() { - while (isRunning()) { - waitOneCycle(); - - try { - Metrics.onCycle(); - } catch (Exception e) { - LOGGER.info(e.getMessage()); - } - } - } - - private void waitOneCycle() { - long msLastCycle = msTick; - for (;;) { - try { - sleep(SECOND_MILLS); - } catch (InterruptedException e) { - } - msTick += SECOND_MILLS; - - if (msTick - msLastCycle >= MetricsConfig.getMsCycle()) { - break; - } - } - } - - public static long getMsTick() { - return msTick; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfResult.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfResult.java deleted file mode 100644 index bc91ae4..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfResult.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.performance; - -/** - * PerfResult - * - * - */ -public class PerfResult { - private String name; - - private long callCount; - - private long msgCount; - - private long avgCallCount; - - private double msAvgLatency; - - private long[] msLatencySegments; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public long getCallCount() { - return callCount; - } - - public void setCallCount(long callCount) { - this.callCount = callCount; - } - - public long getMsgCount() { - return msgCount; - } - - public void setMsgCount(long msgCount) { - this.msgCount = msgCount; - } - - public long getAvgCallCount() { - return avgCallCount; - } - - public void setAvgCallCount(long avgCallCount) { - this.avgCallCount = avgCallCount; - } - - public double getMsAvgLatency() { - return msAvgLatency; - } - - public void setMsAvgLatency(double msAvgLatency) { - this.msAvgLatency = msAvgLatency; - } - - public long[] getMsLatencySegments() { - return msLatencySegments; - } - - public void setMsLatencySegments(long[] msLatencySegments) { - this.msLatencySegments = msLatencySegments; - } - - public String segmentsToString(String fmt) { - StringBuilder sb = new StringBuilder(); - for (long segCount : msLatencySegments) { - sb.append(String.format(fmt, segCount)); - } - return sb.toString(); - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStat.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStat.java deleted file mode 100644 index df999a3..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStat.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.performance; - -import java.util.List; - -/** - * PerfStat - * - * - */ -public interface PerfStat { - String getName(); - - List<PerfStatData> getPerfStatDataList(); - - void mergeFrom(PerfStat otherPerfStat); - - void calc(long msNow, List<PerfResult> perfResultList); - - void calc(PerfStat lastCycle, long msCycle, List<PerfResult> perfResultList); -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatContext.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatContext.java deleted file mode 100644 index 68d9f72..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatContext.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.performance; - -/** - * PerfStatContext - * - * - */ -public class PerfStatContext { - // 调用开始时间,用于统计 - protected long callBegin; - - // 本次统计涉及消息数量 - private int msgCount; - - public PerfStatContext() { - reset(); - } - - public long getLatency() { - return System.currentTimeMillis() - callBegin; - } - - public int getMsgCount() { - return msgCount; - } - - public void setMsgCount(int msgCount) { - this.msgCount = msgCount; - } - - public void reset() { - callBegin = System.currentTimeMillis(); - msgCount = 0; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatData.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatData.java deleted file mode 100644 index 53c28bf..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatData.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.performance; - -import java.util.Arrays; - -/** - * PerfStatData - * - * - */ -public class PerfStatData { - private static long processBegin = System.currentTimeMillis(); - - private static long[] segmentDef; - - private static final long[] SEGMENT_BOUNDRYS = new long[] {20, 100, 300, 500}; - - static { - setSegmentDef(SEGMENT_BOUNDRYS); - } - - //CodeDEX 不允许public static 非final的成员 - private static String strSegmentDef; - - private String name; - - private long callCount; - - private long msgCount; - - private long msLatency; - - private long[] msLatencySegments; - - private static final int MILLI_COUNT_IN_SECOND = 1000; - - public PerfStatData(String name) { - msLatencySegments = new long[segmentDef.length + 1]; - this.name = name; - } - - public static void setSegmentDef(long[] segmentDef) { - PerfStatData.segmentDef = segmentDef; - - StringBuilder sb = new StringBuilder(); - long last = 0; - for (long def : segmentDef) { - sb.append(String.format("%-10s", String.format("[%d,%d)", last, def))); - last = def; - } - sb.append(String.format("%-10s", String.format("[%d,...)", last))); - strSegmentDef = sb.toString(); - } - - public static String getStrSegmentDef() { - return strSegmentDef; - } - - public String getName() { - return name; - } - - public long getCallCount() { - return callCount; - } - - public long getMsgCount() { - return msgCount; - } - - public long getMsLatency() { - return msLatency; - } - - public long[] getMsLatencySegments() { - return msLatencySegments; - } - - protected int findSegmentIdx(long latency) { - long lastDef = 0; - for (int idx = 0; idx < segmentDef.length; idx++) { - long def = segmentDef[idx]; - if (latency >= lastDef && latency < def) { - return idx; - } - - lastDef = def; - } - - return segmentDef.length; - } - - public void add(int count, long latency) { - this.callCount++; - this.msgCount += count; - this.msLatency += latency; - - int segmentIdx = findSegmentIdx(latency); - this.msLatencySegments[segmentIdx]++; - } - - public void add(PerfStatContext context) { - add(context.getMsgCount(), context.getLatency()); - } - - public void mergeFrom(PerfStatData other) { - callCount += other.callCount; - msgCount += other.msgCount; - msLatency += other.msLatency; - for (int idx = 0; idx < msLatencySegments.length; idx++) { - msLatencySegments[idx] += other.msLatencySegments[idx]; - } - } - - public PerfResult calc(long msNow) { - PerfResult perf = new PerfResult(); - perf.setName(" all " + name + " :"); - perf.setCallCount(callCount); - perf.setMsgCount(msgCount); - perf.setAvgCallCount( - callCount * MILLI_COUNT_IN_SECOND / (msNow - processBegin > 0 ? msNow - processBegin : 1)); - perf.setMsAvgLatency((callCount != 0) ? (double) msLatency / callCount : 0); - perf.setMsLatencySegments(msLatencySegments); - return perf; - } - - public PerfResult calc(PerfStatData lastCycle, long msCycle) { - PerfResult perf = new PerfResult(); - - long diffCount = callCount - lastCycle.callCount; - perf.setName(" cycle " + name + ":"); - perf.setCallCount(diffCount); - perf.setMsgCount(msgCount - lastCycle.msgCount); - perf.setAvgCallCount(diffCount * MILLI_COUNT_IN_SECOND / msCycle); - perf.setMsAvgLatency((diffCount != 0) ? (double) (msLatency - lastCycle.msLatency) / diffCount : 0); - - long[] clone = Arrays.copyOf(msLatencySegments, msLatencySegments.length); - long[] lastCycleSegments = lastCycle.getMsLatencySegments(); - for (int idx = 0; idx < clone.length; idx++) { - clone[idx] -= lastCycleSegments[idx]; - } - perf.setMsLatencySegments(clone); - return perf; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatImpl.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatImpl.java deleted file mode 100644 index 1ba26b1..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.performance; - -import java.util.ArrayList; -import java.util.List; - -/** - * PerfStatImpl - * - * - */ -public class PerfStatImpl implements PerfStat { - // 接口或是场景名称 - private String name; - - private List<PerfStatData> dataList = new ArrayList<>(); - - public PerfStatImpl(String name) { - this.name = name; - } - - public PerfStatImpl(String name, PerfStatData data) { - this.name = name; - addPerfStatData(data); - } - - public void addPerfStatData(PerfStatData data) { - dataList.add(data); - } - - @Override - public String getName() { - return name; - } - - @Override - public List<PerfStatData> getPerfStatDataList() { - return dataList; - } - - @Override - public void mergeFrom(PerfStat otherPerfStat) { - name = otherPerfStat.getName(); - List<PerfStatData> otherDataList = otherPerfStat.getPerfStatDataList(); - if (dataList.isEmpty()) { - otherDataList.forEach(otherData -> dataList.add(new PerfStatData(otherData.getName()))); - } - - for (int idx = 0; idx < otherDataList.size(); idx++) { - dataList.get(idx).mergeFrom(otherDataList.get(idx)); - } - } - - @Override - public void calc(long msNow, List<PerfResult> perfResultList) { - for (PerfStatData data : dataList) { - perfResultList.add(data.calc(msNow)); - } - } - - @Override - public void calc(PerfStat lastCycle, long msCycle, List<PerfResult> perfResultList) { - if (lastCycle == null) { - return; - } - - List<PerfStatData> lastCycleDataList = lastCycle.getPerfStatDataList(); - for (int idx = 0; idx < dataList.size(); idx++) { - PerfStatData data = dataList.get(idx); - PerfStatData lastCycleData = lastCycleDataList.get(idx); - - perfResultList.add(data.calc(lastCycleData, msCycle)); - } - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitor.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitor.java deleted file mode 100644 index 33b575a..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitor.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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.performance; - -import java.util.ArrayList; -import java.util.List; - -/** - * PerfStatMonitor - * - * - */ -public class PerfStatMonitor { - // 各线程内部的统计数据 - private List<PerfStat> threadStats = new ArrayList<>(); - - private String name; - - private int index; - - // 每周期,对threadStats进行汇总,结果保存在这里 - private PerfStat sumStat; - - // 每周期计算产生的结果 - private List<PerfResult> perfResultList; - - public PerfStatMonitor(String name, int index) { - this.name = name; - this.index = index; - } - - public String getName() { - return name; - } - - public int getIndex() { - return index; - } - - public void addThreadStat(PerfStat threadStat) { - threadStats.add(threadStat); - } - - public void calcCycle(long msNow, long msCycle) { - PerfStat newSumStat = new PerfStatImpl(null); - for (PerfStat threadStat : threadStats) { - newSumStat.mergeFrom(threadStat); - } - - perfResultList = new ArrayList<>(); - newSumStat.calc(msNow, perfResultList); - newSumStat.calc(sumStat, msCycle, perfResultList); - - sumStat = newSumStat; - } - - public void format(StringBuilder sb, String fmt) { - for (PerfResult result : perfResultList) { - String msg = String.format(result.getName() + fmt, - result.getCallCount(), - result.getMsgCount(), - result.getAvgCallCount(), - result.getMsAvgLatency(), - result.segmentsToString("%-10d")); - sb.append(msg); - } - } - - public PerfStat getPerfStat() { - return sumStat; - } - - public List<PerfResult> getPerfResultList() { - return perfResultList; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitorMgr.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitorMgr.java deleted file mode 100644 index 2c88e79..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatMonitorMgr.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.performance; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * PerfStatMonitorMgr - * - * - */ -public class PerfStatMonitorMgr { - private static final Logger LOGGER = LoggerFactory.getLogger(PerfStatMonitorMgr.class); - - private Map<String, PerfStatMonitor> monitorMap = new HashMap<>(); - - private List<PerfStatMonitor> monitorList = new ArrayList<>(); - - private String header = String.format( - " call count msg count avg tps avg latency(ms) |%s", - PerfStatData.getStrSegmentDef()); - - private String statFmt = "%-16d %-16d %-10d %-16.3f %s\n"; - - public void registerPerfStat(PerfStat perfStat, int index) { - String name = perfStat.getName(); - PerfStatMonitor monitor = monitorMap.get(name); - if (monitor == null) { - monitor = new PerfStatMonitor(name, index); - monitorMap.put(name, monitor); - - monitorList.add(monitor); - - monitorList.sort(Comparator.comparingInt(PerfStatMonitor::getIndex)); - } - - monitor.addThreadStat(perfStat); - } - - public void onCycle(long msNow, long msCycle) { - StringBuilder sb = new StringBuilder(); - sb.append("Cycle stat output:\n" + header + "\n"); - for (PerfStatMonitor monitor : monitorList) { - monitor.calcCycle(msNow, msCycle); - - sb.append(" " + monitor.getName() + ":\n"); - monitor.format(sb, statFmt); - } - - LOGGER.info(sb.toString()); - } - - public Map<String, PerfStat> getMonitorPerfStat() { - return monitorList.stream().collect(Collectors.toMap(PerfStatMonitor::getName, PerfStatMonitor::getPerfStat)); - } - - public List<PerfStatMonitor> getMonitorList() { - return monitorList; - } -} diff --git a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatSuccFail.java b/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatSuccFail.java deleted file mode 100644 index a5eb015..0000000 --- a/foundations/foundation-metrics/src/main/java/org/apache/servicecomb/foundation/metrics/performance/PerfStatSuccFail.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.performance; - -/** - * PerfStatSuccFail - * - * - */ -public class PerfStatSuccFail extends PerfStatImpl { - - private PerfStatData succ = new PerfStatData("succ"); - - private PerfStatData fail = new PerfStatData("fail"); - - public PerfStatSuccFail(String name) { - super(name); - - addPerfStatData(succ); - addPerfStatData(fail); - } - - public void add(boolean isSucc, int msgCount, long latency) { - PerfStatData statData = succ; - if (!isSucc) { - msgCount = 0; - statData = fail; - } - statData.add(msgCount, latency); - } - - public void add(boolean isSucc, PerfStatContext context) { - add(isSucc, context.getMsgCount(), context.getLatency()); - } -} diff --git a/foundations/foundation-metrics/src/main/resources/META-INF/spring/metrics.bean.xml b/foundations/foundation-metrics/src/main/resources/META-INF/spring/metrics.bean.xml deleted file mode 100644 index c0c178f..0000000 --- a/foundations/foundation-metrics/src/main/resources/META-INF/spring/metrics.bean.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> - -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> - - <bean class="org.apache.servicecomb.foundation.metrics.MetricsConfig"> - </bean> -</beans> diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetrics.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetrics.java deleted file mode 100644 index e4a23bc..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetrics.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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; - -import org.apache.servicecomb.foundation.metrics.performance.PerfStatSuccFail; -import org.junit.Assert; -import org.junit.Test; - -public class TestMetrics { - - @Test - public void testOnCycle() throws Exception { - PerfStatSuccFail oPerfStatSuccFail = Metrics.getOrCreateLocalPerfStat("test", 1); - Metrics.onCycle(); - Assert.assertEquals(0, Metrics.getMsTick()); - Assert.assertEquals(1, Metrics.getMonitorPerfStat().size()); - Assert.assertEquals("test", oPerfStatSuccFail.getName()); - Assert.assertEquals(2, oPerfStatSuccFail.getPerfStatDataList().size()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsThread.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsThread.java deleted file mode 100644 index e184fbe..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/TestMetricsThread.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestMetricsThread { - - MetricsThread oMetricsThread = null; - - @Before - public void setUp() throws Exception { - oMetricsThread = new MetricsThread(); - } - - @After - public void tearDown() throws Exception { - oMetricsThread.shutdown(); - oMetricsThread = null; - } - - @Test - public void test() { - oMetricsThread.start(); - Assert.assertEquals(true, oMetricsThread.isRunning()); - oMetricsThread.shutdown(); - Assert.assertEquals(false, oMetricsThread.isRunning()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfResult.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfResult.java deleted file mode 100644 index 5c23ea5..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfResult.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.performance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfResult { - - PerfResult oPerfResult = null; - - @Before - public void setUp() throws Exception { - oPerfResult = new PerfResult(); - } - - @After - public void tearDown() throws Exception { - oPerfResult = null; - } - - @Test - public void testDefaultValues() { - Assert.assertNull(oPerfResult.getName()); - Assert.assertEquals(0, oPerfResult.getCallCount()); - Assert.assertEquals(0, oPerfResult.getMsAvgLatency(), 0); - Assert.assertEquals(0, oPerfResult.getAvgCallCount()); - Assert.assertNull(oPerfResult.getMsLatencySegments()); - Assert.assertEquals(0, oPerfResult.getMsgCount()); - } - - @Test - public void testIntializedValues() { - initializeObject(); //Initialize the object. - Assert.assertEquals("testPerf", oPerfResult.getName()); - Assert.assertEquals(1, oPerfResult.getCallCount()); - Assert.assertEquals(56, oPerfResult.getMsAvgLatency(), 0); - Assert.assertEquals(2, oPerfResult.getAvgCallCount()); - Assert.assertEquals(2, oPerfResult.getMsLatencySegments().length); - Assert.assertEquals(10, oPerfResult.getMsgCount()); - Assert.assertEquals("testStringtestString", oPerfResult.segmentsToString("testString")); - } - - private void initializeObject() { - long[] oLongLatencySegment = new long[] {123, 154}; - oPerfResult.setAvgCallCount(2); - oPerfResult.setCallCount(1); - oPerfResult.setMsAvgLatency(56); - oPerfResult.setMsgCount(10); - oPerfResult.setName("testPerf"); - oPerfResult.setMsLatencySegments(oLongLatencySegment); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatContext.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatContext.java deleted file mode 100644 index 38fd83b..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatContext.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.performance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import mockit.Mock; -import mockit.MockUp; - -public class TestPerfStatContext { - - PerfStatContext oPerfStatContext = null; - - @Before - public void setUp() throws Exception { - oPerfStatContext = new PerfStatContext(); - } - - @After - public void tearDown() throws Exception { - oPerfStatContext = null; - } - - @Test - public void testDefaultValues() { - Assert.assertEquals(0, oPerfStatContext.getMsgCount()); - Assert.assertTrue(oPerfStatContext.getLatency() >= 0); - } - - @Test - public void testIntializedValues() throws InterruptedException { - new MockUp<System>() { - int count = 0; - - @Mock - public long currentTimeMillis() { - if (count == 0) { - count++; - return 10; - } else { - return 20; - } - } - }; - PerfStatContext oPerfStatContext = new PerfStatContext(); - oPerfStatContext.setMsgCount(10); - Assert.assertEquals(10, oPerfStatContext.getMsgCount()); - Assert.assertEquals(10, oPerfStatContext.getLatency()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatData.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatData.java deleted file mode 100644 index 85bea31..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatData.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.performance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfStatData { - - PerfStatData oPerfStatData = null; - - @Before - public void setUp() throws Exception { - oPerfStatData = new PerfStatData("testData"); - } - - @After - public void tearDown() throws Exception { - oPerfStatData = null; - } - - @Test - public void testDefaultValues() { - Assert.assertEquals("testData", oPerfStatData.getName()); - Assert.assertEquals(0, oPerfStatData.getCallCount()); - Assert.assertEquals(0, oPerfStatData.getMsLatency()); - Assert.assertNotNull(oPerfStatData.getMsLatencySegments()); - Assert.assertEquals(0, oPerfStatData.getMsgCount()); - Assert.assertNotNull(PerfStatData.getStrSegmentDef()); - } - - @Test - public void testAdd() { - oPerfStatData.add(10, 100); - Assert.assertEquals(10, oPerfStatData.getMsgCount()); - Assert.assertEquals(100, oPerfStatData.getMsLatency()); - - //Test Add function with PerfStatContext - PerfStatContext oPerfStatContext = new PerfStatContext(); - oPerfStatContext.setMsgCount(30); - oPerfStatData.add(oPerfStatContext); - Assert.assertEquals(40, oPerfStatData.getMsgCount()); - } - - @Test - public void testMergeFrom() { - oPerfStatData.mergeFrom(new PerfStatData("anotherData")); - Assert.assertEquals(0, oPerfStatData.getMsgCount()); - Assert.assertEquals(0, oPerfStatData.getCallCount()); - Assert.assertEquals(0, oPerfStatData.getMsLatency()); - } - - @Test - public void testCalc() { - PerfResult oPerfResult = oPerfStatData.calc(System.currentTimeMillis() + 18989); - Assert.assertEquals(" all testData :", oPerfResult.getName()); - Assert.assertEquals(0, oPerfResult.getCallCount()); - Assert.assertEquals(0, oPerfResult.getMsgCount()); - - //test calc with another PerfStatData - oPerfResult = oPerfStatData.calc(new PerfStatData("anotherData"), System.currentTimeMillis() + 18989); - Assert.assertEquals(" cycle testData:", oPerfResult.getName()); - Assert.assertEquals(0, oPerfResult.getCallCount()); - Assert.assertEquals(0, oPerfResult.getMsgCount()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatImpl.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatImpl.java deleted file mode 100644 index 322b4f5..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.performance; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfStatImpl { - - PerfStatImpl oPerfStatImpl = null; - - PerfStatSuccFail oPerfStatSuccFail = null; - - @Before - public void setUp() throws Exception { - oPerfStatImpl = new PerfStatImpl("testData"); - oPerfStatSuccFail = new PerfStatSuccFail("testMergeFrom"); - } - - @After - public void tearDown() throws Exception { - oPerfStatImpl = null; - } - - @Test - public void testMergeFrom() { - oPerfStatImpl.mergeFrom(oPerfStatSuccFail); - Assert.assertEquals("testMergeFrom", oPerfStatImpl.getName()); - Assert.assertEquals(2, oPerfStatImpl.getPerfStatDataList().size()); - } - - @Test - public void testCalc() { - oPerfStatImpl = new PerfStatImpl("testConstructor", new PerfStatData("test")); - PerfResult oPerfResult = new PerfResult(); - oPerfResult.setName("test"); - List<PerfResult> oPerfResultList = new ArrayList<>(); - oPerfResultList.add(oPerfResult); - oPerfStatImpl.calc(System.currentTimeMillis(), oPerfResultList); - Assert.assertEquals(2, oPerfResultList.size()); - - //Testing Calc with null PerfStat - oPerfStatImpl.calc(null, 20, oPerfResultList); - Assert.assertEquals(2, oPerfResultList.size()); //The list size does not increase - - //Testing Calc with PerfStat - oPerfStatImpl.calc(oPerfStatSuccFail, 20, oPerfResultList); - Assert.assertEquals(3, oPerfResultList.size()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitor.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitor.java deleted file mode 100644 index 8148d99..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitor.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.performance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfStatMonitor { - - PerfStatMonitor oPerfStatMonitor = null; - - PerfStatSuccFail oPerfStatSuccFail = null; - - @Before - public void setUp() throws Exception { - oPerfStatMonitor = new PerfStatMonitor("testMonitor", 0); - oPerfStatSuccFail = new PerfStatSuccFail("testMergeFrom"); - } - - @After - public void tearDown() throws Exception { - oPerfStatMonitor = null; - } - - @Test - public void testCalcCycle() { - Assert.assertEquals("testMonitor", oPerfStatMonitor.getName()); - Assert.assertEquals(0, oPerfStatMonitor.getIndex()); - oPerfStatMonitor.addThreadStat(oPerfStatSuccFail); - oPerfStatMonitor.calcCycle(System.currentTimeMillis(), 20); - Assert.assertEquals("testMergeFrom", oPerfStatMonitor.getPerfStat().getName()); - Assert.assertEquals(2, oPerfStatMonitor.getPerfResultList().size()); - - //Test Format - StringBuilder oBuilder = new StringBuilder(); - oPerfStatMonitor.format(oBuilder, "Test"); - Assert.assertEquals(" all succ :Test all fail :Test", oBuilder.toString()); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitorMgr.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitorMgr.java deleted file mode 100644 index 6692e90..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatMonitorMgr.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.performance; - -import java.util.stream.Collectors; - -import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfStatMonitorMgr { - - PerfStatMonitorMgr oPerfStatMonitorMgr = null; - - PerfStatSuccFail oPerfStatSuccFail = null; - - @Before - public void setUp() throws Exception { - oPerfStatMonitorMgr = new PerfStatMonitorMgr(); - oPerfStatSuccFail = new PerfStatSuccFail("testMergeFrom"); - } - - @After - public void tearDown() throws Exception { - oPerfStatMonitorMgr = null; - oPerfStatSuccFail = null; - } - - @Test - public void testRegisterPerfStat() { - oPerfStatMonitorMgr.registerPerfStat(oPerfStatSuccFail, 0); - Assert.assertEquals(1, oPerfStatMonitorMgr.getMonitorList().size()); - } - - @Test - public void testOnCycle() { - oPerfStatMonitorMgr.registerPerfStat(oPerfStatSuccFail, 0); - oPerfStatMonitorMgr.onCycle(System.currentTimeMillis(), 10); - Assert.assertEquals(1, oPerfStatMonitorMgr.getMonitorPerfStat().size()); - } - - @Test - public void testSort() { - oPerfStatMonitorMgr.registerPerfStat(new PerfStatSuccFail("a"), -1); - oPerfStatMonitorMgr.registerPerfStat(new PerfStatSuccFail("b"), Integer.MAX_VALUE); - - Assert.assertThat( - oPerfStatMonitorMgr.getMonitorList().stream().map(PerfStatMonitor::getName).collect(Collectors.toList()), - Matchers.contains("a", "b")); - } -} diff --git a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatSuccFail.java b/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatSuccFail.java deleted file mode 100644 index 52bd759..0000000 --- a/foundations/foundation-metrics/src/test/java/org/apache/servicecomb/foundation/metrics/performance/TestPerfStatSuccFail.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.performance; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class TestPerfStatSuccFail { - - PerfStatSuccFail oPerfStatSuccFail = null; - - @Before - public void setUp() throws Exception { - oPerfStatSuccFail = new PerfStatSuccFail("testSuccFail"); - } - - @After - public void tearDown() throws Exception { - oPerfStatSuccFail = null; - } - - @Test - public void testAdd() { - oPerfStatSuccFail.add(true, new PerfStatContext()); - Assert.assertEquals(2, oPerfStatSuccFail.getPerfStatDataList().size()); - - //Test org.apache.servicecomb.foundation.metrics.performance.PerfStatSuccFail.add(boolean, int, long) - oPerfStatSuccFail.add(false, 10, 100); - Assert.assertEquals(2, oPerfStatSuccFail.getPerfStatDataList().size()); - } -} -- To stop receiving notification emails like this one, please contact wuji...@apache.org.