1 package org.apache.helix.mock.participant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.helix.alerts.StatsHolder;
26 import org.apache.helix.healthcheck.HealthReportProvider;
27
28
29 public class MockEspressoHealthReportProvider extends HealthReportProvider {
30
31 private final String _reportName = "RestQueryStats";
32 private HashMap<String, Map<String,String>> _statMap;
33 private final String DB_NAME = "DBName";
34
35 public MockEspressoHealthReportProvider()
36 {
37 super();
38 _statMap = new HashMap<String, Map<String,String>>();
39 }
40
41 public String buildMapKey(String dbName)
42 {
43 return _reportName+"@"+DB_NAME+"="+dbName;
44 }
45
46 public void setStat(String dbName, String statName, String statVal)
47 {
48 String currTime = String.valueOf(System.currentTimeMillis());
49 setStat(dbName, statName, statVal, currTime);
50 }
51
52
53
54
55 public void setStat(String dbName, String statName, String statVal, String timestamp)
56 {
57 String key = buildMapKey(dbName);
58 Map<String, String> dbStatMap = _statMap.get(key);
59 if (dbStatMap == null) {
60 dbStatMap = new HashMap<String,String>();
61 _statMap.put(key, dbStatMap);
62 }
63 dbStatMap.put(statName, statVal);
64 dbStatMap.put(StatsHolder.TIMESTAMP_NAME, timestamp);
65 }
66
67 @Override
68 public Map<String, String> getRecentHealthReport() {
69 return null;
70 }
71
72 @Override
73 public Map<String, Map<String, String>> getRecentPartitionHealthReport() {
74 return _statMap;
75 }
76
77 @Override
78 public void resetStats() {
79 _statMap.clear();
80 }
81
82 public String getReportName()
83 {
84 return _reportName;
85 }
86
87 }