Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r10545 r10558 391 391 } else { 392 392 attributes.setError(e); 393 attributes.setResponseCode(499); // set dummy error code 394 boolean doCache = isResponseLoadable(null, 499, null) || cacheAsEmpty(); //generic 499 error code returned 395 if (doCache) { 396 cacheData = createCacheEntry(new byte[]{}); 397 cache.put(getCacheKey(), createCacheEntry(new byte[]{}), attributes); 398 } 399 return doCache; 393 attributes.setResponseCode(599); // set dummy error code, greater than 500 so it will be not cached 394 return false; 400 395 } 401 396 -
trunk/test/unit/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJobTest.java
r10557 r10558 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 5 6 6 7 import java.io.IOException; … … 13 14 import org.junit.Test; 14 15 import org.openstreetmap.josm.JOSMFixture; 16 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult; 15 17 16 18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 23 25 private static class TestCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, CacheEntry> { 24 26 private String url; 27 private String key; 25 28 26 TestCachedTileLoaderJob(String url ) throws IOException {29 TestCachedTileLoaderJob(String url, String key) throws IOException { 27 30 super(getCache(), 30000, 30000, null); 31 28 32 this.url = url; 29 } 30 31 private static ICacheAccess<String, CacheEntry> getCache() throws IOException { 32 return JCSCacheManager.getCache("test"); 33 this.key = key; 33 34 } 34 35 35 36 @Override 36 37 public String getCacheKey() { 37 return "cachekey" + url;38 return key; 38 39 } 39 40 … … 56 57 private CacheEntryAttributes attributes; 57 58 private boolean ready; 59 private LoadResult result; 58 60 59 61 @Override … … 61 63 this.attributes = attributes; 62 64 this.ready = true; 65 this.result = result; 63 66 this.notifyAll(); 64 67 } … … 100 103 @SuppressFBWarnings(value = "WA_NOT_IN_LOOP") 101 104 public void testUnknownHost() throws IOException, InterruptedException { 102 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown"); 105 String key = "key_unknown_host"; 106 TestCachedTileLoaderJob job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key); 103 107 Listener listener = new Listener(); 104 108 job.submit(listener, true); … … 109 113 } 110 114 assertEquals("java.net.UnknownHostException: unkownhost.unkownhost", listener.attributes.getErrorMessage()); 115 assertEquals(LoadResult.FAILURE, listener.result); // because response will be cached, and that is checked below 116 117 ICacheAccess<String, CacheEntry> cache = getCache(); 118 CacheEntry e = new CacheEntry(new byte[]{0,1,2,3}); 119 CacheEntryAttributes attributes = new CacheEntryAttributes(); 120 attributes.setExpirationTime(2); 121 cache.put(key, e, attributes); 122 123 job = new TestCachedTileLoaderJob("http://unkownhost.unkownhost/unkown", key); 124 listener = new Listener(); 125 job.submit(listener, true); 126 synchronized (listener) { 127 if (!listener.ready) { 128 listener.wait(); 129 } 130 } 131 assertEquals(LoadResult.SUCCESS, listener.result); 132 assertFalse(job.isCacheElementValid()); 111 133 } 112 134 … … 125 147 126 148 private static TestCachedTileLoaderJob getStatusLoaderJob(int responseCode) throws IOException { 127 return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode); 149 return new TestCachedTileLoaderJob("http://httpstat.us/" + responseCode, "key_" + responseCode); 150 } 151 152 private static ICacheAccess<String, CacheEntry> getCache() throws IOException { 153 return JCSCacheManager.getCache("test"); 128 154 } 129 155 }
Note:
See TracChangeset
for help on using the changeset viewer.