Changeset 18027 in josm for trunk/test/unit


Ignore:
Timestamp:
2021-07-15T02:59:58+02:00 (3 years ago)
Author:
Don-vip
Message:

improve speed of ProjectionRefTest from 75s to 45s using parallel stream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java

    r17333 r18027  
    1919import java.util.Arrays;
    2020import java.util.Collection;
     21import java.util.Collections;
    2122import java.util.HashMap;
    2223import java.util.HashSet;
     
    2930import java.util.TreeMap;
    3031import java.util.TreeSet;
     32import java.util.concurrent.ConcurrentHashMap;
    3133import java.util.regex.Matcher;
    3234import java.util.regex.Pattern;
    3335
    34 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    3536import org.junit.Assert;
     37import org.junit.jupiter.api.Test;
    3638import org.junit.jupiter.api.extension.RegisterExtension;
    37 import org.junit.jupiter.api.Test;
    3839import org.openstreetmap.josm.data.Bounds;
    3940import org.openstreetmap.josm.data.coor.EastNorth;
     
    4344import org.openstreetmap.josm.tools.Pair;
    4445import org.openstreetmap.josm.tools.PlatformManager;
     46
     47import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    4548
    4649/**
     
    374377    @Test
    375378    void testProjections() throws IOException {
    376         StringBuilder fail = new StringBuilder();
    377         Map<String, Set<String>> failingProjs = new HashMap<>();
     379        Set<String> failures = Collections.synchronizedSet(new TreeSet<>());
     380        Map<String, Set<String>> failingProjs = new ConcurrentHashMap<>();
    378381        Set<String> allCodes = new HashSet<>(Projections.getAllProjectionCodes());
    379382        Collection<RefEntry> refs = readData();
    380 
    381         for (RefEntry ref : refs) {
     383        refs.stream().map(ref -> ref.code).forEach(allCodes::remove);
     384        if (!allCodes.isEmpty()) {
     385            Assert.fail("no reference data for following projections: "+allCodes);
     386        }
     387
     388        refs.parallelStream().forEach(ref -> {
    382389            String def0 = Projections.getInit(ref.code);
    383390            if (def0 == null) {
     
    385392            }
    386393            if (!ref.def.equals(def0)) {
    387                 fail.append("definitions for ").append(ref.code).append(" do not match\n");
     394                failures.add("definitions for ".concat(ref.code).concat(" do not match\n"));
    388395            } else {
    389396                CustomProjection proj = (CustomProjection) Projections.getProjectionByCode(ref.code);
     
    405412                                "        but got:  eastnorth(%s,%s)!%n",
    406413                                proj.toString(), proj.toCode(), ll.lat(), ll.lon(), enRef.east(), enRef.north(), en.east(), en.north());
    407                         fail.append(errorEN);
     414                        failures.add(errorEN);
    408415                        failingProjs.computeIfAbsent(proj.proj.getProj4Id(), x -> new TreeSet<>()).add(ref.code);
    409416                    }
    410417                }
    411418            }
    412             allCodes.remove(ref.code);
    413         }
    414         if (!allCodes.isEmpty()) {
    415             Assert.fail("no reference data for following projections: "+allCodes);
    416         }
    417         if (fail.length() > 0) {
    418             System.err.println(fail.toString());
     419        });
     420        if (!failures.isEmpty()) {
     421            System.err.println(failures.toString());
    419422            throw new AssertionError("Failing:\n" +
    420423                    failingProjs.keySet().size() + " projections: " + failingProjs.keySet() + "\n" +
Note: See TracChangeset for help on using the changeset viewer.