1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.cache.tests; |
21 |
|
|
22 |
|
import org.xwiki.cache.event.CacheEntryEvent; |
23 |
|
import org.xwiki.cache.event.CacheEntryListener; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
@version |
29 |
|
|
|
|
| 69% |
Uncovered Elements: 9 (29) |
Complexity: 11 |
Complexity Density: 0.65 |
|
30 |
|
public class CacheEntryListenerTest implements CacheEntryListener<Object> |
31 |
|
{ |
32 |
|
|
33 |
|
|
34 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
35 |
|
public enum EventType |
36 |
|
{ |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
ADD, |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
MODIFY, |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
REMOVE |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
private CacheEntryEvent<Object> addedEvent; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
private CacheEntryEvent<Object> modifiedEvent; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private CacheEntryEvent<Object> removedEvent; |
67 |
|
|
68 |
|
|
69 |
|
@return |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
4 |
public CacheEntryEvent<Object> getAddedEvent()... |
72 |
|
{ |
73 |
4 |
return this.addedEvent; |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0 |
public void reinitAddEvent()... |
80 |
|
{ |
81 |
0 |
this.addedEvent = null; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
4 |
public CacheEntryEvent<Object> getModifiedEvent()... |
88 |
|
{ |
89 |
4 |
return this.modifiedEvent; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
0 |
public void reinitModifiedEvent()... |
96 |
|
{ |
97 |
0 |
this.modifiedEvent = null; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@return |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
7 |
public CacheEntryEvent<Object> getRemovedEvent()... |
104 |
|
{ |
105 |
7 |
return this.removedEvent; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public void reinitRemovedEvent()... |
112 |
|
{ |
113 |
0 |
this.removedEvent = null; |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
7 |
@Override... |
117 |
|
public void cacheEntryAdded(CacheEntryEvent<Object> event) |
118 |
|
{ |
119 |
7 |
this.addedEvent = event; |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
1 |
@Override... |
123 |
|
public void cacheEntryModified(CacheEntryEvent<Object> event) |
124 |
|
{ |
125 |
1 |
this.modifiedEvent = event; |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
6 |
@Override... |
129 |
|
public void cacheEntryRemoved(CacheEntryEvent<Object> event) |
130 |
|
{ |
131 |
6 |
this.removedEvent = event; |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
|
@param |
136 |
|
@return |
137 |
|
@throws |
138 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
139 |
3 |
public boolean waitForEntryEvent(EventType eventType) throws InterruptedException... |
140 |
|
{ |
141 |
3 |
EventWaiter eventWaiter = new EventWaiter(eventType); |
142 |
|
|
143 |
3 |
Thread thread = new Thread(eventWaiter); |
144 |
3 |
thread.start(); |
145 |
3 |
thread.join(100000); |
146 |
|
|
147 |
3 |
if (thread.isAlive()) { |
148 |
0 |
eventWaiter.stop(); |
149 |
|
|
150 |
0 |
return false; |
151 |
|
} |
152 |
|
|
153 |
3 |
return true; |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
|
|
| 70.8% |
Uncovered Elements: 7 (24) |
Complexity: 8 |
Complexity Density: 0.62 |
|
159 |
|
class EventWaiter implements Runnable |
160 |
|
{ |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
private boolean run = true; |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
private EventType eventType; |
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
3 |
EventWaiter(EventType eventType)... |
175 |
|
{ |
176 |
3 |
this.eventType = eventType; |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
182 |
0 |
void stop()... |
183 |
|
{ |
184 |
0 |
this.run = false; |
185 |
|
} |
186 |
|
|
|
|
| 73.7% |
Uncovered Elements: 5 (19) |
Complexity: 6 |
Complexity Density: 0.55 |
|
187 |
3 |
@Override... |
188 |
|
public void run() |
189 |
|
{ |
190 |
3 |
CacheEntryEvent<Object> event; |
191 |
|
|
192 |
9 |
while (this.run) { |
193 |
9 |
if (this.eventType == EventType.ADD) { |
194 |
0 |
event = addedEvent; |
195 |
9 |
} else if (this.eventType == EventType.MODIFY) { |
196 |
0 |
event = modifiedEvent; |
197 |
|
} else { |
198 |
9 |
event = removedEvent; |
199 |
|
} |
200 |
|
|
201 |
9 |
if (event != null) { |
202 |
3 |
break; |
203 |
|
} |
204 |
|
|
205 |
6 |
try { |
206 |
6 |
Thread.sleep(500); |
207 |
|
} catch (InterruptedException e) { |
208 |
|
|
209 |
|
} |
210 |
|
} |
211 |
|
} |
212 |
|
} |
213 |
|
} |