1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.constructs.nonstop;
18
19 import java.io.IOException;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25
26 import net.sf.ehcache.CacheException;
27 import net.sf.ehcache.Element;
28 import net.sf.ehcache.Status;
29 import net.sf.ehcache.concurrent.CacheLockProvider;
30 import net.sf.ehcache.search.Attribute;
31 import net.sf.ehcache.search.Results;
32 import net.sf.ehcache.search.attribute.AttributeExtractor;
33 import net.sf.ehcache.store.ElementValueComparator;
34 import net.sf.ehcache.store.Policy;
35 import net.sf.ehcache.store.StoreListener;
36 import net.sf.ehcache.store.StoreQuery;
37 import net.sf.ehcache.store.TerracottaStore;
38 import net.sf.ehcache.writer.CacheWriterManager;
39
40 public class MockStoreWithFlag implements TerracottaStore {
41
42 private boolean accessFlag = false;
43 private String lastMethodInvoked;
44 private final CacheLockProvider mockCacheLockProvider = new NullCacheLockProvider();
45
46 public void markAccessFlag() {
47 accessFlag = true;
48 Exception exception = new Exception();
49 exception.fillInStackTrace();
50 StackTraceElement[] stackTrace = exception.getStackTrace();
51 StackTraceElement lastStackTraceElement = stackTrace[1];
52 lastMethodInvoked = lastStackTraceElement.getMethodName();
53 }
54
55 public String getLastMethodInvoked() {
56 return lastMethodInvoked;
57 }
58
59 public boolean isAccessFlagMarked() {
60 return accessFlag;
61 }
62
63 public void clearAccessFlag() {
64 this.accessFlag = false;
65 this.lastMethodInvoked = "";
66 }
67
68 public boolean bufferFull() {
69 markAccessFlag();
70 return false;
71 }
72
73 public boolean containsKey(Object key) {
74 markAccessFlag();
75 return false;
76 }
77
78 public boolean containsKeyInMemory(Object key) {
79 markAccessFlag();
80 return false;
81 }
82
83 public boolean containsKeyOnDisk(Object key) {
84 markAccessFlag();
85 return false;
86 }
87
88 public void dispose() {
89 markAccessFlag();
90
91 }
92
93 public void expireElements() {
94 markAccessFlag();
95
96 }
97
98 public void flush() throws IOException {
99 markAccessFlag();
100
101 }
102
103 public Element get(Object key) {
104 markAccessFlag();
105 return null;
106 }
107
108 public Policy getInMemoryEvictionPolicy() {
109 markAccessFlag();
110 return null;
111 }
112
113 public int getInMemorySize() {
114 markAccessFlag();
115 return 0;
116 }
117
118 public long getInMemorySizeInBytes() {
119 markAccessFlag();
120 return 0;
121 }
122
123 public Object getInternalContext() {
124 markAccessFlag();
125 return mockCacheLockProvider;
126 }
127
128 public List getKeys() {
129 markAccessFlag();
130 return Collections.EMPTY_LIST;
131 }
132
133 public int getOnDiskSize() {
134 markAccessFlag();
135 return 0;
136 }
137
138 public long getOnDiskSizeInBytes() {
139 markAccessFlag();
140 return 0;
141 }
142
143 public Element getQuiet(Object key) {
144 markAccessFlag();
145 return null;
146 }
147
148 public int getSize() {
149 markAccessFlag();
150 return 0;
151 }
152
153 public Status getStatus() {
154 markAccessFlag();
155 return null;
156 }
157
158 public int getTerracottaClusteredSize() {
159 markAccessFlag();
160 return 0;
161 }
162
163 public boolean isCacheCoherent() {
164 markAccessFlag();
165 return false;
166 }
167
168 public boolean isClusterCoherent() {
169 markAccessFlag();
170 return false;
171 }
172
173 public boolean isNodeCoherent() {
174 markAccessFlag();
175 return false;
176 }
177
178 public boolean put(Element element) throws CacheException {
179 markAccessFlag();
180 return false;
181 }
182
183 public void putAll(Collection<Element> elements) throws CacheException {
184 markAccessFlag();
185 }
186
187 public Element putIfAbsent(Element element) throws NullPointerException {
188 markAccessFlag();
189 return null;
190 }
191
192 public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException {
193 markAccessFlag();
194 return false;
195 }
196
197 public Element remove(Object key) {
198 markAccessFlag();
199 return null;
200 }
201
202 public void removeAll(Collection<Object> keys) {
203 markAccessFlag();
204 }
205
206 public void removeAll() throws CacheException {
207 markAccessFlag();
208 }
209
210 public Element removeElement(Element element, ElementValueComparator comparator) throws NullPointerException {
211 markAccessFlag();
212 return null;
213 }
214
215 public Element removeWithWriter(Object key, CacheWriterManager writerManager) throws CacheException {
216 markAccessFlag();
217 return null;
218 }
219
220 public boolean replace(Element old, Element element, ElementValueComparator comparator) throws NullPointerException,
221 IllegalArgumentException {
222 markAccessFlag();
223 return false;
224 }
225
226 public Element replace(Element element) throws NullPointerException {
227 markAccessFlag();
228 return null;
229 }
230
231 public void setInMemoryEvictionPolicy(Policy policy) {
232 markAccessFlag();
233
234 }
235
236 public void setNodeCoherent(boolean coherent) throws UnsupportedOperationException {
237 markAccessFlag();
238
239 }
240
241 public void waitUntilClusterCoherent() throws UnsupportedOperationException {
242 markAccessFlag();
243 }
244
245 public void addStoreListener(StoreListener listener) {
246 markAccessFlag();
247 }
248
249 public void removeStoreListener(StoreListener listener) {
250 markAccessFlag();
251 }
252
253 public int getOffHeapSize() {
254 markAccessFlag();
255 return 0;
256 }
257
258 public long getOffHeapSizeInBytes() {
259 markAccessFlag();
260 return 0;
261 }
262
263 public boolean containsKeyOffHeap(Object key) {
264 markAccessFlag();
265 return false;
266 }
267
268 public Object getMBean() {
269 return null;
270 }
271
272 public void setAttributeExtractors(Map<String, AttributeExtractor> extractors) {
273
274
275 }
276
277 public Results executeQuery(StoreQuery query) {
278 throw new UnsupportedOperationException();
279 }
280
281 public <T> Attribute<T> getSearchAttribute(String attributeName) {
282 return new Attribute(attributeName);
283 }
284
285 public Set getLocalKeys() {
286 markAccessFlag();
287 return null;
288 }
289
290 public Element unlockedGet(Object key) {
291 markAccessFlag();
292 return null;
293 }
294
295 public Element unlockedGetQuiet(Object key) {
296 markAccessFlag();
297 return null;
298 }
299
300 public Element unsafeGet(Object key) {
301 markAccessFlag();
302 return null;
303 }
304
305 public Element unsafeGetQuiet(Object key) {
306 markAccessFlag();
307 return null;
308 }
309
310 }