• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / rocketmq / 7926

pending completion
7926

push

travis-ci-com

GitHub
[ISSUE #5965] Fix lmqTopicQueueTable initialization (#5967)

10 of 10 new or added lines in 2 files covered. (100.0%)

22455 of 43079 relevant lines covered (52.13%)

1.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

41.3
/common/src/main/java/org/apache/rocketmq/common/stats/MomentStatsItemSet.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
package org.apache.rocketmq.common.stats;
19

20
import java.util.Iterator;
21
import java.util.Map.Entry;
22
import java.util.concurrent.ConcurrentHashMap;
23
import java.util.concurrent.ConcurrentMap;
24
import java.util.concurrent.ScheduledExecutorService;
25
import java.util.concurrent.TimeUnit;
26
import org.apache.rocketmq.common.UtilAll;
27
import org.apache.rocketmq.logging.InternalLogger;
28

29
public class MomentStatsItemSet {
30
    private final ConcurrentMap<String/* key */, MomentStatsItem> statsItemTable =
2✔
31
        new ConcurrentHashMap<String, MomentStatsItem>(128);
32
    private final String statsName;
33
    private final ScheduledExecutorService scheduledExecutorService;
34
    private final InternalLogger log;
35

36
    public MomentStatsItemSet(String statsName, ScheduledExecutorService scheduledExecutorService, InternalLogger log) {
2✔
37
        this.statsName = statsName;
2✔
38
        this.scheduledExecutorService = scheduledExecutorService;
2✔
39
        this.log = log;
2✔
40
        this.init();
2✔
41
    }
2✔
42

43
    public ConcurrentMap<String, MomentStatsItem> getStatsItemTable() {
44
        return statsItemTable;
×
45
    }
46

47
    public String getStatsName() {
48
        return statsName;
×
49
    }
50

51
    public void init() {
52

53
        this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
2✔
54
            @Override
55
            public void run() {
56
                try {
57
                    printAtMinutes();
×
58
                } catch (Throwable ignored) {
×
59
                }
×
60
            }
×
61
        }, Math.abs(UtilAll.computeNextMinutesTimeMillis() - System.currentTimeMillis()), 1000 * 60 * 5, TimeUnit.MILLISECONDS);
2✔
62
    }
2✔
63

64
    private void printAtMinutes() {
65
        Iterator<Entry<String, MomentStatsItem>> it = this.statsItemTable.entrySet().iterator();
×
66
        while (it.hasNext()) {
×
67
            Entry<String, MomentStatsItem> next = it.next();
×
68
            next.getValue().printAtMinutes();
×
69
        }
×
70
    }
×
71

72
    public void setValue(final String statsKey, final int value) {
73
        MomentStatsItem statsItem = this.getAndCreateStatsItem(statsKey);
2✔
74
        statsItem.getValue().set(value);
2✔
75
    }
2✔
76

77
    public void delValueByInfixKey(final String statsKey, String separator) {
78
        Iterator<Entry<String, MomentStatsItem>> it = this.statsItemTable.entrySet().iterator();
×
79
        while (it.hasNext()) {
×
80
            Entry<String, MomentStatsItem> next = it.next();
×
81
            if (next.getKey().contains(separator + statsKey + separator)) {
×
82
                it.remove();
×
83
            }
84
        }
×
85
    }
×
86

87
    public void delValueBySuffixKey(final String statsKey, String separator) {
88
        Iterator<Entry<String, MomentStatsItem>> it = this.statsItemTable.entrySet().iterator();
×
89
        while (it.hasNext()) {
×
90
            Entry<String, MomentStatsItem> next = it.next();
×
91
            if (next.getKey().endsWith(separator + statsKey)) {
×
92
                it.remove();
×
93
            }
94
        }
×
95
    }
×
96

97
    public MomentStatsItem getAndCreateStatsItem(final String statsKey) {
98
        MomentStatsItem statsItem = this.statsItemTable.get(statsKey);
2✔
99
        if (null == statsItem) {
2✔
100
            statsItem =
2✔
101
                new MomentStatsItem(this.statsName, statsKey, this.scheduledExecutorService, this.log);
102
            MomentStatsItem prev = this.statsItemTable.putIfAbsent(statsKey, statsItem);
2✔
103

104
            if (null != prev) {
2✔
105
                statsItem = prev;
×
106
                // statsItem.init();
107
            }
108
        }
109

110
        return statsItem;
2✔
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc