Changeset 16768 in josm


Ignore:
Timestamp:
2020-07-14T20:19:40+02:00 (3 weeks ago)
Author:
simon04
Message:

fix #19449 ImageProviderTest.testGetPadded has slow startup, and a race condition (patch by johsin18, modified)

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r16699 r16768  
    229229        File arch = TaggingPresetReader.getZipIcons();
    230230        final Collection<String> s = Config.getPref().getList("taggingpreset.icon.sources", null);
    231         this.iconFuture = new ImageProvider(iconName)
     231        this.iconFuture = new CompletableFuture<>();
     232        new ImageProvider(iconName)
    232233            .setDirs(s)
    233234            .setId("presets")
     
    242243                            Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
    243244                            Logging.warn(e);
     245                        } finally {
     246                            iconFuture.complete(null);
    244247                        }
    245248                    });
    246249                } else {
    247250                    Logging.warn(toString() + ": " + PRESET_ICON_ERROR_MSG_PREFIX + iconName);
     251                    iconFuture.complete(null);
    248252                }
    249253            });
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java

    r15539 r16768  
    1313import java.util.List;
    1414import java.util.Locale;
    15 import java.util.Objects;
    1615import java.util.Set;
    17 import java.util.concurrent.ExecutionException;
    18 import java.util.concurrent.TimeUnit;
    19 import java.util.concurrent.TimeoutException;
    2016
    2117import org.junit.BeforeClass;
     
    2925import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    3026import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
     27import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetsTest;
    3128import org.openstreetmap.josm.gui.tagging.presets.items.Link;
    3229import org.openstreetmap.josm.spi.preferences.Config;
     
    116113        Collection<TaggingPreset> presets = TaggingPresetReader.readAll(source.url, true);
    117114        assertFalse(presets.isEmpty());
    118         // wait for asynchronous icon loading
    119         presets.parallelStream().map(TaggingPreset::getIconLoadingTask).filter(Objects::nonNull).forEach(t -> {
    120             try {
    121                 t.get(30, TimeUnit.SECONDS);
    122             } catch (InterruptedException | ExecutionException | TimeoutException e) {
    123                 Logging.error(e);
    124             }
    125         });
     115        TaggingPresetsTest.waitForIconLoading(presets);
    126116        // check that links are correct and not redirections
    127117        presets.parallelStream().flatMap(x -> x.data.stream().filter(i -> i instanceof Link).map(i -> ((Link) i).getUrl())).forEach(u -> {
  • trunk/test/unit/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetsTest.java

    r16182 r16768  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.tagging.presets;
     3
     4import java.util.Collection;
     5import java.util.Objects;
     6import java.util.concurrent.ExecutionException;
     7import java.util.concurrent.TimeUnit;
     8import java.util.concurrent.TimeoutException;
    39
    410import org.junit.Rule;
    511import org.junit.Test;
    612import org.openstreetmap.josm.testutils.JOSMTestRules;
     13import org.openstreetmap.josm.tools.Logging;
    714
    815import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2936        UtilityClassTestUtil.assertUtilityClassWellDefined(TaggingPresets.class);
    3037    }
     38
     39    /**
     40     * Wait for asynchronous icon loading
     41     * @param presets presets collection
     42     */
     43    public static void waitForIconLoading(Collection<TaggingPreset> presets) {
     44        presets.parallelStream().map(TaggingPreset::getIconLoadingTask).filter(Objects::nonNull).forEach(t -> {
     45            try {
     46                t.get(30, TimeUnit.SECONDS);
     47            } catch (InterruptedException | ExecutionException | TimeoutException e) {
     48                Logging.error(e);
     49            }
     50        });
     51    }
    3152}
  • trunk/test/unit/org/openstreetmap/josm/tools/ImageProviderTest.java

    r16764 r16768  
    66import static org.junit.Assert.assertFalse;
    77import static org.junit.Assert.assertNotNull;
    8 import static org.junit.Assert.assertNull;
    98import static org.junit.Assert.assertTrue;
    109
     
    2322import java.io.File;
    2423import java.io.IOException;
    25 import java.util.EnumSet;
    2624import java.util.List;
    2725import java.util.logging.Handler;
     
    4038import org.openstreetmap.josm.JOSMFixture;
    4139import org.openstreetmap.josm.TestUtils;
    42 import org.openstreetmap.josm.data.osm.Node;
    43 import org.openstreetmap.josm.data.osm.OsmUtils;
    4440import org.openstreetmap.josm.testutils.JOSMTestRules;
    45 import org.openstreetmap.josm.tools.ImageProvider.GetPaddedOptions;
    4641
    4742import com.kitfox.svg.SVGConst;
     
    5954    @Rule
    6055    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    61     public JOSMTestRules test = new JOSMTestRules().mapStyles().presets();
     56    public JOSMTestRules test = new JOSMTestRules();
    6257
    6358    private static final class LogHandler14319 extends Handler {
     
    151146                "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4"+
    152147                "//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="));
    153     }
    154 
    155     /**
    156      * Unit test of {@link ImageProvider#getPadded}.
    157      */
    158     @Test
    159     public void testGetPadded() {
    160         final EnumSet<GetPaddedOptions> noDefault = EnumSet.of(GetPaddedOptions.NO_DEFAULT);
    161         final Dimension iconSize = new Dimension(16, 16);
    162 
    163         assertNull(ImageProvider.getPadded(new Node(), new Dimension(0, 0)));
    164         assertNotNull(ImageProvider.getPadded(new Node(), iconSize));
    165         assertNull(ImageProvider.getPadded(new Node(), iconSize, noDefault));
    166         assertNotNull(ImageProvider.getPadded(OsmUtils.createPrimitive("node amenity=restaurant"), iconSize, noDefault));
    167         assertNull(ImageProvider.getPadded(OsmUtils.createPrimitive("node barrier=hedge"), iconSize,
    168                 EnumSet.of(GetPaddedOptions.NO_DEFAULT, GetPaddedOptions.NO_DEPRECATED)));
    169         assertNotNull(ImageProvider.getPadded(OsmUtils.createPrimitive("way waterway=stream"), iconSize, noDefault));
    170         assertNotNull(ImageProvider.getPadded(OsmUtils.createPrimitive("relation type=route route=railway"), iconSize, noDefault));
    171148    }
    172149
Note: See TracChangeset for help on using the changeset viewer.