jdk/test/java/util/concurrent/tck/TimeUnitTest.java
author dl
Sat, 22 Jul 2017 09:18:50 -0700
changeset 45937 646816090183
parent 36732 7e6686d3f98a
child 46146 b3e220a04d3f
permissions -rw-r--r--
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07 Reviewed-by: martin, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     1
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     3
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     6
 * published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     7
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    12
 * accompanied this code).
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    13
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    17
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    20
 * questions.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    21
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    22
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    23
/*
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    27
 * file:
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    28
 *
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    29
 * Written by Doug Lea with assistance from members of JCP JSR-166
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    31
 * http://creativecommons.org/publicdomain/zero/1.0/
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    32
 * Other contributors include Andrew Wright, Jeffrey Hayes,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    33
 * Pat Fisher, Mike Judd.
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    34
 */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    35
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    36
import static java.util.concurrent.TimeUnit.DAYS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    37
import static java.util.concurrent.TimeUnit.HOURS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    38
import static java.util.concurrent.TimeUnit.MICROSECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    39
import static java.util.concurrent.TimeUnit.MILLISECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    40
import static java.util.concurrent.TimeUnit.MINUTES;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    41
import static java.util.concurrent.TimeUnit.NANOSECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    42
import static java.util.concurrent.TimeUnit.SECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    43
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    44
import java.util.concurrent.CountDownLatch;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    45
import java.util.concurrent.TimeUnit;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    46
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    47
import junit.framework.Test;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    48
import junit.framework.TestSuite;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    49
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    50
public class TimeUnitTest extends JSR166TestCase {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    51
    public static void main(String[] args) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    52
        main(suite(), args);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    53
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    54
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    55
    public static Test suite() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    56
        return new TestSuite(TimeUnitTest.class);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    57
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    58
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    59
    // (loops to 88888 check increments at all time divisions.)
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    60
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    61
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    62
     * convert correctly converts sample values across the units
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    63
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    64
    public void testConvert() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    65
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    66
            assertEquals(t*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    67
                         SECONDS.convert(t, DAYS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    68
            assertEquals(t*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    69
                         SECONDS.convert(t, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    70
            assertEquals(t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    71
                         SECONDS.convert(t, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    72
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    73
                         SECONDS.convert(t, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    74
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    75
                         SECONDS.convert(1000L*t, MILLISECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    76
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    77
                         SECONDS.convert(1000000L*t, MICROSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    78
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    79
                         SECONDS.convert(1000000000L*t, NANOSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    80
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    81
            assertEquals(1000L*t*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    82
                         MILLISECONDS.convert(t, DAYS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    83
            assertEquals(1000L*t*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    84
                         MILLISECONDS.convert(t, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    85
            assertEquals(1000L*t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    86
                         MILLISECONDS.convert(t, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    87
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    88
                         MILLISECONDS.convert(t, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    89
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    90
                         MILLISECONDS.convert(t, MILLISECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    91
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    92
                         MILLISECONDS.convert(1000L*t, MICROSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    93
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    94
                         MILLISECONDS.convert(1000000L*t, NANOSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    95
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    96
            assertEquals(1000000L*t*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    97
                         MICROSECONDS.convert(t, DAYS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    98
            assertEquals(1000000L*t*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
    99
                         MICROSECONDS.convert(t, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   100
            assertEquals(1000000L*t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   101
                         MICROSECONDS.convert(t, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   102
            assertEquals(1000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   103
                         MICROSECONDS.convert(t, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   104
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   105
                         MICROSECONDS.convert(t, MILLISECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   106
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   107
                         MICROSECONDS.convert(t, MICROSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   108
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   109
                         MICROSECONDS.convert(1000L*t, NANOSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   110
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   111
            assertEquals(1000000000L*t*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   112
                         NANOSECONDS.convert(t, DAYS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   113
            assertEquals(1000000000L*t*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   114
                         NANOSECONDS.convert(t, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   115
            assertEquals(1000000000L*t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   116
                         NANOSECONDS.convert(t, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   117
            assertEquals(1000000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   118
                         NANOSECONDS.convert(t, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   119
            assertEquals(1000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   120
                         NANOSECONDS.convert(t, MILLISECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   121
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   122
                         NANOSECONDS.convert(t, MICROSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   123
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   124
                         NANOSECONDS.convert(t, NANOSECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   125
        }
36732
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   126
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   127
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   128
            long[] zs = {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   129
                0, 1, -1,
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   130
                Integer.MAX_VALUE, Integer.MIN_VALUE,
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   131
                Long.MAX_VALUE, Long.MIN_VALUE,
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   132
            };
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   133
            for (long z : zs) assertEquals(z, x.convert(z, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   134
        }
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   135
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   136
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   137
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   138
     * toNanos correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   139
     * nanoseconds
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   140
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   141
    public void testToNanos() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   142
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   143
            assertEquals(t*1000000000L*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   144
                         DAYS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   145
            assertEquals(t*1000000000L*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   146
                         HOURS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   147
            assertEquals(t*1000000000L*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   148
                         MINUTES.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   149
            assertEquals(1000000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   150
                         SECONDS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   151
            assertEquals(1000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   152
                         MILLISECONDS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   153
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   154
                         MICROSECONDS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   155
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   156
                         NANOSECONDS.toNanos(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   157
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   158
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   159
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   160
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   161
     * toMicros correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   162
     * microseconds
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   163
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   164
    public void testToMicros() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   165
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   166
            assertEquals(t*1000000L*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   167
                         DAYS.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   168
            assertEquals(t*1000000L*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   169
                         HOURS.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   170
            assertEquals(t*1000000L*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   171
                         MINUTES.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   172
            assertEquals(1000000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   173
                         SECONDS.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   174
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   175
                         MILLISECONDS.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   176
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   177
                         MICROSECONDS.toMicros(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   178
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   179
                         NANOSECONDS.toMicros(t*1000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   180
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   181
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   182
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   183
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   184
     * toMillis correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   185
     * milliseconds
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   186
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   187
    public void testToMillis() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   188
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   189
            assertEquals(t*1000L*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   190
                         DAYS.toMillis(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   191
            assertEquals(t*1000L*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   192
                         HOURS.toMillis(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   193
            assertEquals(t*1000L*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   194
                         MINUTES.toMillis(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   195
            assertEquals(1000L*t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   196
                         SECONDS.toMillis(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   197
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   198
                         MILLISECONDS.toMillis(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   199
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   200
                         MICROSECONDS.toMillis(t*1000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   201
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   202
                         NANOSECONDS.toMillis(t*1000000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   203
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   204
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   205
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   206
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   207
     * toSeconds correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   208
     * seconds
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   209
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   210
    public void testToSeconds() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   211
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   212
            assertEquals(t*60*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   213
                         DAYS.toSeconds(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   214
            assertEquals(t*60*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   215
                         HOURS.toSeconds(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   216
            assertEquals(t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   217
                         MINUTES.toSeconds(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   218
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   219
                         SECONDS.toSeconds(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   220
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   221
                         MILLISECONDS.toSeconds(t*1000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   222
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   223
                         MICROSECONDS.toSeconds(t*1000000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   224
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   225
                         NANOSECONDS.toSeconds(t*1000000000L));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   226
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   227
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   228
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   229
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   230
     * toMinutes correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   231
     * minutes
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   232
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   233
    public void testToMinutes() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   234
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   235
            assertEquals(t*60*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   236
                         DAYS.toMinutes(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   237
            assertEquals(t*60,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   238
                         HOURS.toMinutes(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   239
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   240
                         MINUTES.toMinutes(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   241
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   242
                         SECONDS.toMinutes(t*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   243
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   244
                         MILLISECONDS.toMinutes(t*1000L*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   245
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   246
                         MICROSECONDS.toMinutes(t*1000000L*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   247
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   248
                         NANOSECONDS.toMinutes(t*1000000000L*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   249
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   250
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   251
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   252
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   253
     * toHours correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   254
     * hours
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   255
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   256
    public void testToHours() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   257
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   258
            assertEquals(t*24,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   259
                         DAYS.toHours(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   260
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   261
                         HOURS.toHours(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   262
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   263
                         MINUTES.toHours(t*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   264
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   265
                         SECONDS.toHours(t*60*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   266
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   267
                         MILLISECONDS.toHours(t*1000L*60*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   268
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   269
                         MICROSECONDS.toHours(t*1000000L*60*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   270
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   271
                         NANOSECONDS.toHours(t*1000000000L*60*60));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   272
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   273
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   274
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   275
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   276
     * toDays correctly converts sample values in different units to
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   277
     * days
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   278
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   279
    public void testToDays() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   280
        for (long t = 0; t < 88888; ++t) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   281
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   282
                         DAYS.toDays(t));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   283
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   284
                         HOURS.toDays(t*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   285
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   286
                         MINUTES.toDays(t*60*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   287
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   288
                         SECONDS.toDays(t*60*60*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   289
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   290
                         MILLISECONDS.toDays(t*1000L*60*60*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   291
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   292
                         MICROSECONDS.toDays(t*1000000L*60*60*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   293
            assertEquals(t,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   294
                         NANOSECONDS.toDays(t*1000000000L*60*60*24));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   295
        }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   296
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   297
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   298
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   299
     * convert saturates positive too-large values to Long.MAX_VALUE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   300
     * and negative to LONG.MIN_VALUE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   301
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   302
    public void testConvertSaturate() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   303
        assertEquals(Long.MAX_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   304
                     NANOSECONDS.convert(Long.MAX_VALUE / 2, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   305
        assertEquals(Long.MIN_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   306
                     NANOSECONDS.convert(-Long.MAX_VALUE / 4, SECONDS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   307
        assertEquals(Long.MAX_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   308
                     NANOSECONDS.convert(Long.MAX_VALUE / 2, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   309
        assertEquals(Long.MIN_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   310
                     NANOSECONDS.convert(-Long.MAX_VALUE / 4, MINUTES));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   311
        assertEquals(Long.MAX_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   312
                     NANOSECONDS.convert(Long.MAX_VALUE / 2, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   313
        assertEquals(Long.MIN_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   314
                     NANOSECONDS.convert(-Long.MAX_VALUE / 4, HOURS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   315
        assertEquals(Long.MAX_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   316
                     NANOSECONDS.convert(Long.MAX_VALUE / 2, DAYS));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   317
        assertEquals(Long.MIN_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   318
                     NANOSECONDS.convert(-Long.MAX_VALUE / 4, DAYS));
36732
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   319
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   320
        for (TimeUnit x : TimeUnit.values())
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   321
            for (TimeUnit y : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   322
                long ratio = x.toNanos(1) / y.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   323
                if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   324
                    assertEquals(ratio, y.convert(1, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   325
                    assertEquals(1, x.convert(ratio, y));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   326
                    long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   327
                    assertEquals(max * ratio, y.convert(max, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   328
                    assertEquals(-max * ratio, y.convert(-max, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   329
                    assertEquals(max, x.convert(max * ratio, y));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   330
                    assertEquals(-max, x.convert(-max * ratio, y));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   331
                    if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   332
                        assertEquals(Long.MAX_VALUE, y.convert(max + 1, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   333
                        assertEquals(Long.MIN_VALUE, y.convert(-max - 1, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   334
                        assertEquals(Long.MIN_VALUE, y.convert(Long.MIN_VALUE + 1, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   335
                    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   336
                    assertEquals(Long.MAX_VALUE, y.convert(Long.MAX_VALUE, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   337
                    assertEquals(Long.MIN_VALUE, y.convert(Long.MIN_VALUE, x));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   338
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   339
            }
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   340
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   341
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   342
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   343
     * toNanos saturates positive too-large values to Long.MAX_VALUE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   344
     * and negative to LONG.MIN_VALUE
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   345
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   346
    public void testToNanosSaturate() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   347
        assertEquals(Long.MAX_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   348
                     MILLISECONDS.toNanos(Long.MAX_VALUE / 2));
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   349
        assertEquals(Long.MIN_VALUE,
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   350
                     MILLISECONDS.toNanos(-Long.MAX_VALUE / 3));
36732
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   351
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   352
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   353
            long ratio = x.toNanos(1) / NANOSECONDS.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   354
            if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   355
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   356
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   357
                    assertEquals(z * ratio, x.toNanos(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   358
                if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   359
                    assertEquals(Long.MAX_VALUE, x.toNanos(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   360
                    assertEquals(Long.MIN_VALUE, x.toNanos(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   361
                    assertEquals(Long.MIN_VALUE, x.toNanos(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   362
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   363
                assertEquals(Long.MAX_VALUE, x.toNanos(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   364
                assertEquals(Long.MIN_VALUE, x.toNanos(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   365
                if (max < Integer.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   366
                    assertEquals(Long.MAX_VALUE, x.toNanos(Integer.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   367
                    assertEquals(Long.MIN_VALUE, x.toNanos(Integer.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   368
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   369
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   370
        }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   371
    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   372
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   373
    /**
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   374
     * toMicros saturates positive too-large values to Long.MAX_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   375
     * and negative to LONG.MIN_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   376
     */
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   377
    public void testToMicrosSaturate() {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   378
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   379
            long ratio = x.toNanos(1) / MICROSECONDS.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   380
            if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   381
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   382
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   383
                    assertEquals(z * ratio, x.toMicros(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   384
                if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   385
                    assertEquals(Long.MAX_VALUE, x.toMicros(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   386
                    assertEquals(Long.MIN_VALUE, x.toMicros(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   387
                    assertEquals(Long.MIN_VALUE, x.toMicros(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   388
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   389
                assertEquals(Long.MAX_VALUE, x.toMicros(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   390
                assertEquals(Long.MIN_VALUE, x.toMicros(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   391
                if (max < Integer.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   392
                    assertEquals(Long.MAX_VALUE, x.toMicros(Integer.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   393
                    assertEquals(Long.MIN_VALUE, x.toMicros(Integer.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   394
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   395
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   396
        }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   397
    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   398
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   399
    /**
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   400
     * toMillis saturates positive too-large values to Long.MAX_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   401
     * and negative to LONG.MIN_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   402
     */
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   403
    public void testToMillisSaturate() {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   404
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   405
            long ratio = x.toNanos(1) / MILLISECONDS.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   406
            if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   407
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   408
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   409
                    assertEquals(z * ratio, x.toMillis(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   410
                if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   411
                    assertEquals(Long.MAX_VALUE, x.toMillis(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   412
                    assertEquals(Long.MIN_VALUE, x.toMillis(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   413
                    assertEquals(Long.MIN_VALUE, x.toMillis(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   414
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   415
                assertEquals(Long.MAX_VALUE, x.toMillis(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   416
                assertEquals(Long.MIN_VALUE, x.toMillis(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   417
                if (max < Integer.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   418
                    assertEquals(Long.MAX_VALUE, x.toMillis(Integer.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   419
                    assertEquals(Long.MIN_VALUE, x.toMillis(Integer.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   420
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   421
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   422
        }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   423
    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   424
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   425
    /**
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   426
     * toSeconds saturates positive too-large values to Long.MAX_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   427
     * and negative to LONG.MIN_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   428
     */
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   429
    public void testToSecondsSaturate() {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   430
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   431
            long ratio = x.toNanos(1) / SECONDS.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   432
            if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   433
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   434
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   435
                    assertEquals(z * ratio, x.toSeconds(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   436
                if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   437
                    assertEquals(Long.MAX_VALUE, x.toSeconds(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   438
                    assertEquals(Long.MIN_VALUE, x.toSeconds(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   439
                    assertEquals(Long.MIN_VALUE, x.toSeconds(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   440
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   441
                assertEquals(Long.MAX_VALUE, x.toSeconds(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   442
                assertEquals(Long.MIN_VALUE, x.toSeconds(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   443
                if (max < Integer.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   444
                    assertEquals(Long.MAX_VALUE, x.toSeconds(Integer.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   445
                    assertEquals(Long.MIN_VALUE, x.toSeconds(Integer.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   446
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   447
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   448
        }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   449
    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   450
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   451
    /**
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   452
     * toMinutes saturates positive too-large values to Long.MAX_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   453
     * and negative to LONG.MIN_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   454
     */
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   455
    public void testToMinutesSaturate() {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   456
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   457
            long ratio = x.toNanos(1) / MINUTES.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   458
            if (ratio > 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   459
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   460
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   461
                    assertEquals(z * ratio, x.toMinutes(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   462
                assertEquals(Long.MAX_VALUE, x.toMinutes(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   463
                assertEquals(Long.MIN_VALUE, x.toMinutes(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   464
                assertEquals(Long.MAX_VALUE, x.toMinutes(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   465
                assertEquals(Long.MIN_VALUE, x.toMinutes(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   466
                assertEquals(Long.MIN_VALUE, x.toMinutes(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   467
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   468
        }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   469
    }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   470
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   471
    /**
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   472
     * toHours saturates positive too-large values to Long.MAX_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   473
     * and negative to LONG.MIN_VALUE
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   474
     */
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   475
    public void testToHoursSaturate() {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   476
        for (TimeUnit x : TimeUnit.values()) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   477
            long ratio = x.toNanos(1) / HOURS.toNanos(1);
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   478
            if (ratio >= 1) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   479
                long max = Long.MAX_VALUE/ratio;
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   480
                for (long z : new long[] {0, 1, -1, max, -max})
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   481
                    assertEquals(z * ratio, x.toHours(z));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   482
                if (max < Long.MAX_VALUE) {
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   483
                    assertEquals(Long.MAX_VALUE, x.toHours(max + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   484
                    assertEquals(Long.MIN_VALUE, x.toHours(-max - 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   485
                    assertEquals(Long.MIN_VALUE, x.toHours(Long.MIN_VALUE + 1));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   486
                }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   487
                assertEquals(Long.MAX_VALUE, x.toHours(Long.MAX_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   488
                assertEquals(Long.MIN_VALUE, x.toHours(Long.MIN_VALUE));
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   489
            }
7e6686d3f98a 8152083: Optimize TimeUnit conversions
dl
parents: 35640
diff changeset
   490
        }
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   491
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   492
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   493
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   494
     * toString returns name of unit
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   495
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   496
    public void testToString() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   497
        assertEquals("SECONDS", SECONDS.toString());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   498
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   499
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   500
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   501
     * name returns name of unit
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   502
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   503
    public void testName() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   504
        assertEquals("SECONDS", SECONDS.name());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   505
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   506
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   507
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   508
     * Timed wait without holding lock throws
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   509
     * IllegalMonitorStateException
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   510
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   511
    public void testTimedWait_IllegalMonitorException() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   512
        Thread t = newStartedThread(new CheckedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   513
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   514
                Object o = new Object();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   515
                TimeUnit tu = MILLISECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   516
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   517
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   518
                    tu.timedWait(o, LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   519
                    threadShouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   520
                } catch (IllegalMonitorStateException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   521
            }});
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   522
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   523
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   524
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   525
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   526
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   527
     * timedWait throws InterruptedException when interrupted
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   528
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   529
    public void testTimedWait_Interruptible() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   530
        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   531
        Thread t = newStartedThread(new CheckedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   532
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   533
                Object o = new Object();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   534
                TimeUnit tu = MILLISECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   535
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   536
                Thread.currentThread().interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   537
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   538
                    synchronized (o) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   539
                        tu.timedWait(o, LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   540
                    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   541
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   542
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   543
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   544
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   545
                pleaseInterrupt.countDown();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   546
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   547
                    synchronized (o) {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   548
                        tu.timedWait(o, LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   549
                    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   550
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   551
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   552
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   553
            }});
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   554
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   555
        await(pleaseInterrupt);
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 36732
diff changeset
   556
        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   557
        t.interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   558
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   559
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   560
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   561
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   562
     * timedJoin throws InterruptedException when interrupted
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   563
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   564
    public void testTimedJoin_Interruptible() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   565
        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   566
        final Thread s = newStartedThread(new CheckedInterruptedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   567
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   568
                Thread.sleep(LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   569
            }});
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   570
        final Thread t = newStartedThread(new CheckedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   571
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   572
                TimeUnit tu = MILLISECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   573
                Thread.currentThread().interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   574
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   575
                    tu.timedJoin(s, LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   576
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   577
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   578
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   579
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   580
                pleaseInterrupt.countDown();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   581
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   582
                    tu.timedJoin(s, LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   583
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   584
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   585
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   586
            }});
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   587
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   588
        await(pleaseInterrupt);
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 36732
diff changeset
   589
        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   590
        t.interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   591
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   592
        s.interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   593
        awaitTermination(s);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   594
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   595
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   596
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   597
     * timedSleep throws InterruptedException when interrupted
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   598
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   599
    public void testTimedSleep_Interruptible() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   600
        final CountDownLatch pleaseInterrupt = new CountDownLatch(1);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   601
        Thread t = newStartedThread(new CheckedRunnable() {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   602
            public void realRun() throws InterruptedException {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   603
                TimeUnit tu = MILLISECONDS;
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   604
                Thread.currentThread().interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   605
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   606
                    tu.sleep(LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   607
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   608
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   609
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   610
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   611
                pleaseInterrupt.countDown();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   612
                try {
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   613
                    tu.sleep(LONG_DELAY_MS);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   614
                    shouldThrow();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   615
                } catch (InterruptedException success) {}
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   616
                assertFalse(Thread.interrupted());
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   617
            }});
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   618
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   619
        await(pleaseInterrupt);
45937
646816090183 8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents: 36732
diff changeset
   620
        assertThreadBlocks(t, Thread.State.TIMED_WAITING);
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   621
        t.interrupt();
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   622
        awaitTermination(t);
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   623
    }
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   624
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   625
    /**
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   626
     * a deserialized serialized unit is the same instance
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   627
     */
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   628
    public void testSerialization() throws Exception {
35640
4adf536f5359 8141452: Convert between TimeUnit and ChronoUnit
dl
parents: 35394
diff changeset
   629
        for (TimeUnit x : TimeUnit.values())
4adf536f5359 8141452: Convert between TimeUnit and ChronoUnit
dl
parents: 35394
diff changeset
   630
            assertSame(x, serialClone(x));
4adf536f5359 8141452: Convert between TimeUnit and ChronoUnit
dl
parents: 35394
diff changeset
   631
    }
4adf536f5359 8141452: Convert between TimeUnit and ChronoUnit
dl
parents: 35394
diff changeset
   632
35394
282c3cb6a0c1 8146467: Integrate JSR 166 jck tests into JDK repo
dl
parents:
diff changeset
   633
}