Changeset 19718 in josm for trunk/test
- Timestamp:
- 2026-11-29T09:59:39+01:00 (21 hours ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 3 edited
-
data/cache/JCSCachedTileLoaderJobTest.java (modified) (1 diff)
-
data/imagery/TMSCachedTileLoaderJobTest.java (modified) (4 diffs)
-
gui/layer/AbstractTileSourceLayerTest.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r19709 r19718 132 132 doTestStatusCode(501); 133 133 doTestStatusCode(502); 134 doTestStatusCode(503); 135 doTestStatusCode(504); 134 136 } 135 137 -
trunk/test/unit/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJobTest.java
r19709 r19718 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.assertFalse; 6 7 import static org.junit.jupiter.api.Assertions.assertNotSame; 7 8 import static org.junit.jupiter.api.Assertions.assertTrue; … … 107 108 private CacheEntryAttributes attributes; 108 109 private boolean ready; 110 private int notifications; 109 111 private byte[] data; 110 112 … … 112 114 public synchronized void tileLoadingFinished(Tile tile, boolean success) { 113 115 ready = true; 116 notifications++; 114 117 this.notifyAll(); 118 } 119 120 synchronized boolean waitForNotifications(int count, long timeoutMillis) throws InterruptedException { 121 long end = System.currentTimeMillis() + timeoutMillis; 122 while (notifications < count) { 123 long remaining = end - System.currentTimeMillis(); 124 if (remaining <= 0) { 125 return false; 126 } 127 wait(remaining); 128 } 129 return true; 115 130 } 116 131 } … … 373 388 assertNotSame(Tile.LOADING_IMAGE, tile.getImage(), "the tile still shows the hourglass"); 374 389 } 390 391 /** 392 * A 5xx response is a transient error: the tile is downloaded again, but only after a delay and a limited number of times. 393 * Until then, the tile stays loaded with its error, so the layer neither shows nothing nor downloads it again at once. 394 * Non-regression test for #25133. 395 * @throws Exception exception 396 */ 397 @Test 398 void testTransientErrorRetriedWithDelay() throws Exception { 399 TMSCachedTileLoaderJob.TRANSIENT_ERROR_RETRY_DELAY.put(50L); 400 final int retries = TMSCachedTileLoaderJob.TRANSIENT_ERROR_RETRIES.get(); 401 wireMockRuntimeInfo.getWireMock().register( 402 WireMock.get(WireMock.urlEqualTo("/error")) 403 .willReturn(WireMock.serverError()) 404 ); 405 MockTile tile = new MockTile(wireMockRuntimeInfo.getHttpBaseUrl() + "/error"); 406 407 for (int attempt = 0; attempt <= retries; attempt++) { 408 // as the layer does at a repaint, download the tile when it is not loaded 409 assertFalse(tile.isLoaded() || tile.isLoading(), "the tile isn't due for a download"); 410 Listener listener = new Listener(); 411 new TestCachedTileLoaderJob(listener, tile, "error").submit(false); 412 assertTrue(listener.waitForNotifications(1, 10_000), "the download didn't finish"); 413 414 wireMockRuntimeInfo.getWireMock().verifyThat(attempt + 1, WireMock.getRequestedFor(WireMock.urlEqualTo("/error"))); 415 assertTrue(tile.hasError(), "the tile doesn't show the error"); 416 assertTrue(tile.isLoaded(), "the tile would be downloaded again at once"); 417 418 if (attempt < retries) { 419 // after the delay, the tile is due for a download again 420 assertTrue(listener.waitForNotifications(2, 10_000), "the tile wasn't retried"); 421 assertFalse(tile.isLoaded(), "the tile wasn't retried"); 422 } else { 423 // no more retries 424 assertFalse(listener.waitForNotifications(2, 50L << retries), "the tile was retried too often"); 425 assertTrue(tile.isLoaded(), "the tile was retried too often"); 426 } 427 } 428 } 375 429 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayerTest.java
r18870 r19718 6 6 import static org.junit.jupiter.api.Assertions.assertFalse; 7 7 import static org.junit.jupiter.api.Assertions.assertNotNull; 8 import static org.junit.jupiter.api.Assertions.assertNull; 9 import static org.junit.jupiter.api.Assertions.assertSame; 8 10 import static org.junit.jupiter.api.Assertions.assertTrue; 9 11 … … 198 200 assertDoesNotThrow(() -> testLayer.new TileSourceLayerPopup(100, 100)); 199 201 } 202 203 /** 204 * Test {@link AbstractTileSourceLayer#getTileStatusImage}: a tile shows the error image or the hourglass only once 205 * it has failed, until it is loaded successfully. Non-regression test for #25133. 206 */ 207 @Test 208 void testTileStatusImage() { 209 Tile tile = new Tile(testLayer.tileSource, 1, 1, 1); 210 tile.initLoading(); 211 assertNull(testLayer.getTileStatusImage(tile), "a tile which never failed shows its normal loading"); 212 213 tile.finishLoading(); 214 tile.setError("HTTP error 503 when loading tiles"); 215 testLayer.tileLoadingFinished(tile, false); 216 assertSame(Tile.ERROR_IMAGE, testLayer.getTileStatusImage(tile)); 217 218 // the retry after a transient error 219 tile.setLoaded(false); 220 assertSame(Tile.ERROR_IMAGE, testLayer.getTileStatusImage(tile)); 221 tile.initLoading(); 222 assertSame(Tile.LOADING_IMAGE, testLayer.getTileStatusImage(tile)); 223 224 testLayer.getDisplaySettings().setShowErrors(false); 225 assertNull(testLayer.getTileStatusImage(tile), "errors are not shown"); 226 testLayer.getDisplaySettings().setShowErrors(true); 227 228 tile.finishLoading(); 229 testLayer.tileLoadingFinished(tile, true); 230 assertNull(testLayer.getTileStatusImage(tile), "a tile loaded successfully shows its image"); 231 232 // after a success, normal loading is shown again 233 tile.initLoading(); 234 assertNull(testLayer.getTileStatusImage(tile)); 235 } 200 236 }
Note:
See TracChangeset
for help on using the changeset viewer.
