1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.core.impl.mocks |
17 | |
|
18 | |
import org.kuali.rice.ksb.api.cache.RiceCacheAdministrator |
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
class RiceCacheAdministratorMock implements RiceCacheAdministrator { |
27 | |
|
28 | 7 | Map<String, Object> cache = new HashMap<String, Object>(); |
29 | 7 | Map<String, Set<String>> keyToGroupMap = new HashMap<String, Set<String>>(); |
30 | 7 | Map<String, Set<String>> groupToKeyMap = new HashMap<String, Set<String>>(); |
31 | |
|
32 | |
@Override |
33 | |
public void start() throws Exception {} |
34 | |
|
35 | |
@Override |
36 | |
public void stop() throws Exception {} |
37 | |
|
38 | |
@Override |
39 | |
public boolean isStarted() { |
40 | 0 | return true; |
41 | |
} |
42 | |
|
43 | |
@Override |
44 | |
public synchronized Object getFromCache(String key) { |
45 | 0 | return cache.get(key); |
46 | |
} |
47 | |
|
48 | |
|
49 | |
@Override |
50 | |
public synchronized Object getFromCache(String key, int refreshPeriod) { |
51 | 0 | return cache.get(key); |
52 | |
} |
53 | |
|
54 | |
|
55 | |
@Override |
56 | |
public synchronized Object getFromCache(String key, int refreshPeriod, String cronExpression) { |
57 | 0 | return cache.get(key); |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public synchronized void putInCache(String key, Object content, String[] groups) { |
62 | 1 | cache.put(key, content); |
63 | 1 | if (groups != null && groups.length > 0) { |
64 | 1 | synchronized (keyToGroupMap) { |
65 | 1 | Set<String> currentGroups = keyToGroupMap.get(key); |
66 | 1 | if (currentGroups == null) { |
67 | 1 | currentGroups = new HashSet<String>(); |
68 | 1 | keyToGroupMap.put(key, currentGroups); |
69 | |
} |
70 | 1 | for (String group : groups) { |
71 | 1 | currentGroups.add(group); |
72 | 1 | Set<String> currentGroupKeys = groupToKeyMap.get(group); |
73 | 1 | if (currentGroupKeys == null) { |
74 | 1 | currentGroupKeys = new HashSet<String>(); |
75 | 1 | groupToKeyMap.put(group, currentGroupKeys); |
76 | |
} |
77 | 1 | currentGroupKeys.add(key); |
78 | |
} |
79 | |
} |
80 | |
} |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public synchronized void putInCache(String key, Object content, String group) { |
85 | 1 | if (group != null) { |
86 | 1 | putInCache(key, content, [ group ] as String[]); |
87 | |
} |
88 | |
} |
89 | |
|
90 | |
@Override |
91 | |
public synchronized void putInCache(String key, Object content) { |
92 | 0 | cache.put(key, content); |
93 | |
} |
94 | |
|
95 | |
@Override |
96 | |
public synchronized void flushEntry(String key) { |
97 | 1 | cache.remove(key); |
98 | 1 | keyToGroupMap.remove(key); |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public synchronized void flushGroup(String group) { |
103 | 2 | Set<String> groupKeys = groupToKeyMap.get(group); |
104 | 2 | if (groupKeys != null) { |
105 | 1 | for (String groupKey : groupKeys) { |
106 | 1 | flushEntry(groupKey); |
107 | |
} |
108 | |
} |
109 | 2 | groupToKeyMap.remove(group); |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public synchronized void flushAll() { |
114 | 0 | cache.clear(); |
115 | 0 | keyToGroupMap.clear(); |
116 | 0 | groupToKeyMap.clear(); |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public void setCacheCapacity(int capacity) {} |
121 | |
|
122 | |
@Override |
123 | |
public void setForceRegistryRefresh(boolean forceRegistryRefresh) {} |
124 | |
|
125 | |
public boolean isEmpty() { |
126 | 3 | return cache.isEmpty(); |
127 | |
} |
128 | |
|
129 | |
public int getSize() { |
130 | 1 | return cache.size(); |
131 | |
} |
132 | |
|
133 | |
} |