Changeset 14536 in josm


Ignore:
Timestamp:
2018-12-09T20:45:03+01:00 (10 months ago)
Author:
Don-vip
Message:

see #16073 - check response contents with correct cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r14535 r14536  
    1010import java.util.ArrayList;
    1111import java.util.Collections;
    12 import java.util.HashSet;
    1312import java.util.List;
    1413import java.util.Map;
    15 import java.util.Set;
    1614import java.util.TreeMap;
    1715import java.util.concurrent.TimeUnit;
     
    6967
    7068    private final Map<String, Map<ImageryInfo, List<String>>> errors = Collections.synchronizedMap(new TreeMap<>());
    71     private final Set<String> workingURLs = Collections.synchronizedSet(new HashSet<>());
     69    private final Map<String, byte[]> workingURLs = Collections.synchronizedMap(new TreeMap<>());
    7270
    7371    private TMSCachedTileLoaderJob helper;
     
    9290
    9391    private byte[] checkUrl(ImageryInfo info, String url) {
    94         if (url != null && !url.isEmpty() && !workingURLs.contains(url)) {
     92        if (url != null && !url.isEmpty()) {
     93            if (workingURLs.containsKey(url)) {
     94                return workingURLs.get(url);
     95            }
    9596            try {
    9697                Response response = HttpClient.create(new URL(url))
     
    103104                } else if (response.getResponseCode() >= 300) {
    104105                    Logging.warn(url + " -> HTTP " + response.getResponseCode());
    105                 } else {
    106                     workingURLs.add(url);
    107106                }
    108107                try {
    109                     return Utils.readBytesFromStream(response.getContent());
     108                    byte[] data = Utils.readBytesFromStream(response.getContent());
     109                    if (response.getResponseCode() < 300) {
     110                        workingURLs.put(url, data);
     111                    }
     112                    return data;
    110113                } finally {
    111114                    response.disconnect();
Note: See TracChangeset for help on using the changeset viewer.