Ignore:
Timestamp:
2017-01-10T00:07:50+01:00 (8 years ago)
Author:
Don-vip
Message:

see #14166 - checkstyle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/cache/HostLimitQueueTest.java

    r11444 r11448  
    1414import org.junit.Rule;
    1515import org.junit.Test;
     16import org.openstreetmap.josm.Main;
    1617import org.openstreetmap.josm.testutils.JOSMTestRules;
    1718import org.openstreetmap.josm.tools.Utils;
     
    2223 * Simple tests for ThreadPoolExecutor / HostLimitQueue veryfing, that this pair works OK
    2324 * @author Wiktor Niesiobedzki
    24  *
    2525 */
    2626public class HostLimitQueueTest {
     
    3131    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3232    public JOSMTestRules test = new JOSMTestRules().preferences().timeout(20 * 1000);
    33 
    3433
    3534    private static ThreadPoolExecutor getNewThreadPoolExecutor(String nameFormat, int workers, int queueLimit) {
     
    5352        private URL url;
    5453        private AtomicInteger counter;
    55         private int id;
    5654
    57         public Task(ICacheAccess<String, CacheEntry> cache, URL url, AtomicInteger counter, int id) {
     55        Task(ICacheAccess<String, CacheEntry> cache, URL url, AtomicInteger counter) {
    5856            super(cache, 1, 1, null);
    5957            this.url = url;
    6058            this.counter = counter;
    61             this.id = id;
    6259        }
    6360
     
    6764                Thread.sleep(1000);
    6865            } catch (InterruptedException e) {
     66                Main.trace(e);
    6967            } finally {
    7068                this.counter.incrementAndGet();
     
    9189    /**
    9290     * Check if single threaded execution works properly
    93      * @throws InterruptedException
    94      * @throws IOException
     91     * @throws Exception in case of error
    9592     */
    9693    @Test
    97     public void test_single_thread_per_host() throws InterruptedException, IOException {
     94    public void test_single_thread_per_host() throws Exception {
    9895        ThreadPoolExecutor tpe = getNewThreadPoolExecutor("test-%d", 3, 1);
    9996        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test", 3, 0, "");
     
    10198        long start = System.currentTimeMillis();
    10299        for (int i = 0; i < 10; i++) {
    103             tpe.execute(new Task(cache, new URL("http://localhost/"+i), counter, i));
     100            tpe.execute(new Task(cache, new URL("http://localhost/"+i), counter));
    104101        }
    105102        tpe.shutdown();
     
    111108        // so it should take ~10 seconds to finish
    112109        // if it's shorter, it means that host limit does not work
    113         assertTrue("Expected duration between 9 and 11 seconds not met. Actual duration: " + (duration /1000), duration < 11*1000 & duration > 9*1000 );
     110        assertTrue("Expected duration between 9 and 11 seconds not met. Actual duration: " + (duration /1000),
     111                duration < 11*1000 & duration > 9*1000);
    114112    }
    115113
    116114    /**
    117115     * Check if two threaded execution work properly
    118      * @throws InterruptedException
    119      * @throws IOException
     116     * @throws Exception in case of error
    120117     */
    121118    @Test
    122     public void test_multiple_thread_per_host() throws InterruptedException, IOException {
     119    public void test_multiple_thread_per_host() throws Exception {
    123120        ThreadPoolExecutor tpe = getNewThreadPoolExecutor("test-%d", 3, 2);
    124121        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test", 3, 0, "");
     
    126123        long start = System.currentTimeMillis();
    127124        for (int i = 0; i < 10; i++) {
    128             tpe.execute(new Task(cache, new URL("http://hostlocal/"+i), counter, i));
     125            tpe.execute(new Task(cache, new URL("http://hostlocal/"+i), counter));
    129126        }
    130127        tpe.shutdown();
     
    136133        // so it should take ~5 seconds to finish
    137134        // if it's shorter, it means that host limit does not work
    138         assertTrue("Expected duration between 4 and 6 seconds not met. Actual duration: " + (duration /1000), duration < 6*1000 & duration > 4*1000 );
     135        assertTrue("Expected duration between 4 and 6 seconds not met. Actual duration: " + (duration /1000),
     136                duration < 6*1000 & duration > 4*1000);
    139137    }
    140138
    141139    /**
    142140     * Check two hosts
    143      * @throws InterruptedException
    144      * @throws IOException
     141     * @throws Exception in case of error
    145142     */
    146143    @Test
    147     public void test_two_hosts() throws InterruptedException, IOException {
     144    public void test_two_hosts() throws Exception {
    148145        ThreadPoolExecutor tpe = getNewThreadPoolExecutor("test-%d", 3, 1);
    149146        ICacheAccess<String, CacheEntry> cache = JCSCacheManager.getCache("test", 3, 0, "");
     
    152149        for (int i = 0; i < 10; i++) {
    153150            String url = (i % 2 == 0) ? "http://localhost" : "http://hostlocal";
    154             tpe.execute(new Task(cache, new URL(url+i), counter, i));
     151            tpe.execute(new Task(cache, new URL(url+i), counter));
    155152        }
    156153        tpe.shutdown();
     
    162159        // so it should take ~5 seconds to finish
    163160        // if it's shorter, it means that host limit does not work
    164         assertTrue("Expected duration between 4 and 6 seconds not met. Actual duration: " + (duration /1000), duration < 6*1000 & duration > 4*1000 );
     161        assertTrue("Expected duration between 4 and 6 seconds not met. Actual duration: " + (duration /1000),
     162                duration < 6*1000 & duration > 4*1000);
    165163    }
    166 
    167164}
Note: See TracChangeset for help on using the changeset viewer.