Changeset 19709 in josm


Ignore:
Timestamp:
2026-11-27T15:43:57+01:00 (less than one hour ago)
Author:
GerdP
Message:

fix #24893: Cache for background layer Esri World Imagery needs manual flush
patch no-tile-304-v2.patch by wangi

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r19693 r19709  
    367367                // and the server answers with a HTTP 304 = "Not Modified"
    368368                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);
    372370                return true;
    373371            } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 response code
    … …  
    559557                (lastModified != 0 && lastModified <= attributes.getLastModification());
    560558        if (ret) {
    561             // update attributes
    562             attributes = parseHeaders(urlConn);
    563             cache.put(getCacheKey(), cacheData, attributes);
     559            updateAttributes(urlConn);
    564560        }
    565561        return ret;
     562    }
     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);
    566577    }
    567578
  • trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java

    r19693 r19709  
    608608    }
    609609
     610    /**
     611     * A 304 keeps the "no tile at this zoom level" marker of the cache entry: it was found from the response which
     612     * delivered the object, and the confirmation does not repeat it. Non-regression test for #24893.
     613     * @throws IOException exception
     614     */
     615    @Test
     616    void testNoTileAtZoomKeptOn304() throws IOException {
     617        final String eTag = "\"no-tile\"";
     618        ICacheAccess<String, CacheEntry> cache = getCache();
     619        long expires = TimeUnit.DAYS.toMillis(1);
     620        long testStart = System.currentTimeMillis();
     621        CacheEntryAttributes attributes = createEntryAttributes(-1 * expires, 200, testStart, eTag);
     622        attributes.setNoTileAtZoom(true);
     623        cache.put("no-tile", new CacheEntry("cached dummy".getBytes(StandardCharsets.UTF_8)), attributes);
     624        tileServer.getWireMock().register(get(urlEqualTo("/no-tile"))
     625                .willReturn(status(304).withHeader("ETag", eTag)
     626                        .withHeader("Expires", TestUtils.getHTTPDate(testStart + expires))));
     627
     628        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(
     629                "http://127.0.0.1:" + tileServer.getHttpPort() + "/no-tile", "no-tile");
     630        Listener listener = submitJob(job, false);
     631        tileServer.getWireMock().verifyThat(1, getRequestedFor(urlEqualTo("/no-tile")));
     632        assertTrue(listener.attributes.isNoTileAtZoom(), "the no-tile marker was dropped");
     633        assertTrue(((CacheEntryAttributes) cache.getCacheElement("no-tile").getElementAttributes()).isNoTileAtZoom(),
     634                "the no-tile marker was dropped from the cache");
     635        assertTrue(listener.attributes.getExpirationTime() >= testStart + expires, "the expiry wasn't updated");
     636    }
     637
    610638    private void createHeadGetStub(UrlPattern url, long expires, long lastModified, String eTag, String body) {
    611639        tileServer.getWireMock().register(get(url)
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java

    r19515 r19709  
    44import static org.junit.jupiter.api.Assertions.assertArrayEquals;
    55import static org.junit.jupiter.api.Assertions.assertEquals;
     6import static org.junit.jupiter.api.Assertions.assertNotSame;
    67import static org.junit.jupiter.api.Assertions.assertTrue;
    78
    … …  
    203204        TestCachedTileLoaderJob job = new TestCachedTileLoaderJob(listener, tile, key, minimumExpiry);
    204205        job.submit(force);
     206        waitFor(listener);
     207        return job;
     208    }
     209
     210    private static void waitFor(Listener listener) {
    205211        synchronized (listener) {
    206212            while (!listener.ready) {
    … …  
    213219            }
    214220        }
    215         return job;
    216221    }
    217222
    … …  
    333338        assertArrayEquals("mock entry".getBytes(StandardCharsets.UTF_8), job.get().getContent());
    334339    }
     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    }
    335375}
Note: See TracChangeset for help on using the changeset viewer.