* @throws Exception
*/
@SuppressWarnings("serial")
public void testSeedStoredTiles() throws Exception {
WMSLayer tl = createWMSLayer("image/png");
// create an image to be returned by the mock WMSSourceHelper
// / final byte[] fakeWMSResponse = createFakeSourceImage(tl);
// WMSSourceHelper that on makeRequest() returns always the saqme fake image
WMSSourceHelper mockSourceHelper = new MockWMSSourceHelper();// EasyMock.createMock(WMSSourceHelper.class);
// expect(mockSourceHelper.makeRequest((WMSMetaTile)
// anyObject())).andReturn(fakeWMSResponse)
// .anyTimes();
// replay(mockSourceHelper);
tl.setSourceHelper(mockSourceHelper);
final String gridSetId = tl.getGridSubsets().iterator().next();
final int zoomLevel = 2;
SeedRequest req = createRequest(tl, TYPE.SEED, zoomLevel, zoomLevel);
/*
* Create a mock storage broker that has never an image in its blob store and that captures
* the TileObject the seeder requests it to store for further test validation
*/
final StorageBroker mockStorageBroker = EasyMock.createMock(StorageBroker.class);
Capture<TileObject> storedObjects = new Capture<TileObject>() {
/**
* Override because setValue with anyTimes() resets the list of values
*/
@Override
public void setValue(TileObject o) {
super.getValues().add(o);
}
};
expect(mockStorageBroker.put(capture(storedObjects))).andReturn(true).anyTimes();
expect(mockStorageBroker.get((TileObject) anyObject())).andReturn(false).anyTimes();
replay(mockStorageBroker);
TileRange tr = TileBreeder.createTileRange(req, tl);
TileRangeIterator trIter = new TileRangeIterator(tr, tl.getMetaTilingFactors());
boolean reseed = false;
SeedTask task = new SeedTask(mockStorageBroker, trIter, tl, reseed, false);
task.setTaskId(1L);
task.setThreadInfo(new AtomicInteger(), 0);
/*
* HACK: avoid SeedTask.getCurrentThreadArrayIndex failure.
*/
Thread.currentThread().setName("pool-fake-thread-1");
/*
* Call the seed process
*/
task.doAction();
final GridSubset gridSubset = tl.getGridSubset(gridSetId);
/*
* Make sure the seed process asked for the expected tiles to be stored
*/
final long expectedSavedTileCount;