private void installMockBroker() throws Exception {
expect(storageBroker.getTransient((TileObject) anyObject())).andAnswer(new IAnswer<Boolean>() {
public Boolean answer() throws Throwable {
TileObject tile = (TileObject) EasyMock.getCurrentArguments()[0];
String key = TransientCache.computeTransientKey(tile);
Resource resource;
synchronized (transientCache) {
resource = transientCache.get(key);
}
if (resource != null) {
cacheHits.incrementAndGet();
} else {
cacheMisses.incrementAndGet();
}
tile.setBlob(resource);
return resource != null;
}
}).anyTimes();
storageBroker.putTransient(capture(new Capture<TileObject>() {
@Override
public void setValue(TileObject tile) {
String key = TransientCache.computeTransientKey(tile);
synchronized (transientCache) {
transientCache.put(key, tile.getBlob());
}
}
}));
expectLastCall().anyTimes();
final HashSet<String> puts = new HashSet<String>();
expect(storageBroker.put(capture(new Capture<TileObject>() {
@Override
public void setValue(TileObject value) {
puts.add(TransientCache.computeTransientKey(value));
storagePutCounter.incrementAndGet();
}
}))).andReturn(true).anyTimes();
expect(storageBroker.get((TileObject) anyObject())).andAnswer(new IAnswer<Boolean>() {
public Boolean answer() throws Throwable {
TileObject tile = (TileObject) EasyMock.getCurrentArguments()[0];
if (puts.contains(TransientCache.computeTransientKey(tile))) {
tile.setBlob(new ByteArrayResource(fakeWMSResponse));
storageGetCounter.incrementAndGet();
return true;
} else {
return false;
}