Ticket #24893: no-tile-304.patch
| File no-tile-304.patch, 5.8 KB (added by , 4 days ago) |
|---|
-
src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
diff --git src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java index 7cc1a98e42..260fb01269 100644
public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 366 366 // If isModifiedSince or If-None-Match has been set 367 367 // and the server answers with a HTTP 304 = "Not Modified" 368 368 Logging.debug("JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl()); 369 // update cache attributes 370 attributes = parseHeaders(urlConn); 371 cache.put(getCacheKey(), cacheData, attributes); 369 updateAttributes(urlConn); 372 370 return true; 373 371 } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 response code 374 372 && ( … … public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements 558 556 boolean ret = (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getHeaderField("ETag"))) || 559 557 (lastModified != 0 && lastModified <= attributes.getLastModification()); 560 558 if (ret) { 561 // update attributes 562 attributes = parseHeaders(urlConn); 563 cache.put(getCacheKey(), cacheData, attributes); 559 updateAttributes(urlConn); 564 560 } 565 561 return ret; 566 562 } 567 563 564 /** 565 * Updates the cache attributes after the server confirmed that the cached object is still valid. 566 * <p> 567 * The "no tile at this zoom level" marker is kept: it was found from the response which delivered the object, 568 * and a confirmation does not repeat that. Without it, an empty no-tile entry would look like a loaded tile 569 * without an image (see #24893). 570 * @param urlConn the response which confirmed the cached object 571 */ 572 private void updateAttributes(HttpClient.Response urlConn) { 573 final boolean noTileAtZoom = attributes.isNoTileAtZoom(); 574 attributes = parseHeaders(urlConn); 575 attributes.setNoTileAtZoom(noTileAtZoom); 576 cache.put(getCacheKey(), cacheData, attributes); 577 } 578 568 579 /** 569 580 * TODO: move to JobFactory 570 581 * cancels all outstanding tasks in the queue. -
test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
diff --git test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java index 791ae6d36a..ff31eca64e 100644
package org.openstreetmap.josm.data.imagery; 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertArrayEquals; 5 5 import static org.junit.jupiter.api.Assertions.assertEquals; 6 import static org.junit.jupiter.api.Assertions.assertNotSame; 6 7 import static org.junit.jupiter.api.Assertions.assertTrue; 7 8 8 9 import java.io.IOException; … … class TMSCachedTileLoaderJobTest { 202 203 Listener listener = new Listener(); 203 204 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(listener, tile, key, minimumExpiry); 204 205 job.submit(force); 206 waitFor(listener); 207 return job; 208 } 209 210 private static void waitFor(Listener listener) { 205 211 synchronized (listener) { 206 212 while (!listener.ready) { 207 213 try { … … class TMSCachedTileLoaderJobTest { 212 218 } 213 219 } 214 220 } 215 return job;216 221 } 217 222 218 223 /** … … class TMSCachedTileLoaderJobTest { 332 337 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/test"))); 333 338 assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent()); 334 339 } 340 341 /** 342 * A cached "no tile at this zoom level" entry which the server confirms with a 304 stays a no-tile. 343 * <p> 344 * Non-regression test for #24893: the 304 replaced the cache attributes and dropped the marker, so the empty 345 * entry finished as a loaded tile without an image, which kept showing the hourglass a tile starts with. 346 * @throws IOException exception 347 */ 348 @Test 349 void testNoTileAtZoomKeptOn304() throws IOException { 350 final String eTag = "\"no-tile\""; 351 long testStart = System.currentTimeMillis(); 352 wireMockRuntimeInfo.getWireMock().register( 353 WireMock.get(WireMock.urlEqualTo("/no-tile")) 354 .willReturn(WireMock.status(304).withHeader("ETag", eTag)) 355 ); 356 MockTile tile = new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/no-tile"); 357 Listener listener = new Listener(); 358 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(listener, tile, "no-tile"); 359 // the entry as cached for a no-tile response, expired since 360 CacheEntryAttributes attributes = new CacheEntryAttributes(); 361 attributes.setNoTileAtZoom(true); 362 attributes.setEtag(eTag); 363 attributes.setLastModification(testStart - TimeUnit.DAYS.toMillis(2)); 364 attributes.setExpirationTime(testStart - TimeUnit.DAYS.toMillis(1)); 365 getCache().put(job.getCacheKey(), new BufferedImageCacheEntry(new byte[0]), attributes); 366 367 job.submit(false); 368 waitFor(listener); 369 370 wireMockRuntimeInfo.getWireMock().verifyThat(1, WireMock.getRequestedFor(WireMock.urlEqualTo("/no-tile"))); 371 assertTrue(job.getAttributes().isNoTileAtZoom(), "the no-tile marker was dropped"); 372 assertEquals("no-tile", tile.getValue("tile-info")); 373 assertNotSame(Tile.LOADING_IMAGE, tile.getImage(), "the tile still shows the hourglass"); 374 } 335 375 }
