jdk/test/java/util/logging/HigherResolutionTimeStamps/LogRecordWithNanosAPI.java
author dfuchs
Wed, 25 Feb 2015 18:41:07 +0100
changeset 29117 7956b5dc0eac
child 34439 fbb6e8d9611c
permissions -rw-r--r--
8072645: java.util.logging should use java.time to get more precise time stamps Summary: j.u.logging uses j.t.Instant to store LogRecord time stamps. XMLFormatter format is updated to allow for a new optional <nanos> element containing a nano second adjustment. SimpleFormatter passes a ZonedDateTime object to String.format. LogRecord getMillis/setMillis are deprecated, replaced by getInstant/setInstant. Reviewed-by: scolebourne, plevart, rriggs Contributed-by: daniel.fuchs@oracle.com, peter.levart@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     1
/*
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     4
 *
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     8
 *
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    14
 *
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    18
 *
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    21
 * questions.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    22
 */
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    23
import java.io.ByteArrayInputStream;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    24
import java.io.ByteArrayOutputStream;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    25
import java.io.IOException;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    26
import java.io.ObjectInputStream;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    27
import java.io.ObjectOutputStream;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    28
import java.time.Instant;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    29
import java.util.Objects;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    30
import java.util.logging.Level;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    31
import java.util.logging.LogRecord;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    32
import java.util.logging.SimpleFormatter;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    33
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    34
/**
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    35
 * @test
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    36
 * @bug 8072645
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    37
 * @summary tests the new methods added to LogRecord.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    38
 * @run main LogRecordWithNanosAPI
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    39
 * @author danielfuchs
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    40
 */
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    41
public class LogRecordWithNanosAPI {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    42
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    43
    static final int MILLIS_IN_SECOND = 1000;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    44
    static final int NANOS_IN_MILLI = 1000_000;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    45
    static final int NANOS_IN_SECOND = 1000_000_000;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    46
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    47
    static final boolean verbose = true;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    48
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    49
    static final class TestAssertException extends RuntimeException {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    50
        TestAssertException(String msg) { super(msg); }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    51
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    52
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    53
    private static void assertEquals(long expected, long received, String msg) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    54
        if (expected != received) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    55
            throw new TestAssertException("Unexpected result for " + msg
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    56
                    + ".\n\texpected: " + expected
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    57
                    +  "\n\tactual:   " + received);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    58
        } else if (verbose) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    59
            System.out.println("Got expected " + msg + ": " + received);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    60
        }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    61
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    62
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    63
    private static void assertEquals(Object expected, Object received, String msg) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    64
        if (!Objects.equals(expected, received)) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    65
            throw new TestAssertException("Unexpected result for " + msg
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    66
                    + ".\n\texpected: " + expected
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    67
                    +  "\n\tactual:   " + received);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    68
        } else if (verbose) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    69
            System.out.println("Got expected " + msg + ": " + received);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    70
        }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    71
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    72
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    73
    // The nano second fractional part of a second, contained in a time expressed
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    74
    // as a number of millisecond from the epoch.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    75
    private static long nanoInSecondFromEpochMilli(long millis) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    76
        return (((millis%MILLIS_IN_SECOND) + MILLIS_IN_SECOND)%MILLIS_IN_SECOND)*NANOS_IN_MILLI;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    77
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    78
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    79
    /**
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    80
     * Serializes a log record, then deserializes it and check that both
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    81
     * records match.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    82
     * @param record the log record to serialize & deserialize.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    83
     * @param hasExceedingNanos whether the record has a nano adjustment whose
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    84
     *            value exceeds 1ms.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    85
     * @throws IOException Unexpected.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    86
     * @throws ClassNotFoundException  Unexpected.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    87
     */
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    88
    public static void test(LogRecord record, boolean hasExceedingNanos)
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    89
            throws IOException, ClassNotFoundException {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    90
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    91
        // Format the given logRecord using the SimpleFormatter
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    92
        SimpleFormatter formatter = new SimpleFormatter();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    93
        String str = formatter.format(record);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    94
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    95
        // Serialize the given LogRecord
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    96
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    97
        final ObjectOutputStream oos = new ObjectOutputStream(baos);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    98
        oos.writeObject(record);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
    99
        oos.flush();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   100
        oos.close();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   101
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   102
        // First checks that the log record can be deserialized
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   103
        final ByteArrayInputStream bais =
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   104
                new ByteArrayInputStream(baos.toByteArray());
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   105
        final ObjectInputStream ois = new ObjectInputStream(bais);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   106
        final LogRecord record2 = (LogRecord)ois.readObject();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   107
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   108
        assertEquals(record.getMillis(), record2.getMillis(), "getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   109
        assertEquals(record.getInstant().getEpochSecond(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   110
                record2.getInstant().getEpochSecond(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   111
                "getInstant().getEpochSecond()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   112
        assertEquals(record.getInstant().getNano(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   113
                record2.getInstant().getNano(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   114
                "getInstant().getNano()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   115
        assertEquals(record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   116
                record2.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   117
                "getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   118
        long millis = record.getMillis();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   119
        millis = hasExceedingNanos
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   120
                ? Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   121
                        (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   122
                        + record.getInstant().getNano() % NANOS_IN_MILLI).toEpochMilli()
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   123
                : millis;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   124
        assertEquals(millis, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   125
                "getMillis()/getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   126
        millis = record2.getMillis();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   127
        millis = hasExceedingNanos
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   128
                ? Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   129
                        (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   130
                        + record2.getInstant().getNano() % NANOS_IN_MILLI).toEpochMilli()
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   131
                : millis;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   132
        assertEquals(millis, record2.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   133
                "getMillis()/getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   134
        long nanos = nanoInSecondFromEpochMilli(record.getMillis())
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   135
                + record.getInstant().getNano() % NANOS_IN_MILLI;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   136
        assertEquals(nanos, record.getInstant().getNano(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   137
                "nanoInSecondFromEpochMilli(record.getMillis())"
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   138
                + " + record.getInstant().getNano() % NANOS_IN_MILLI /getInstant().getNano()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   139
        nanos = nanoInSecondFromEpochMilli(record2.getMillis())
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   140
                + record2.getInstant().getNano() % NANOS_IN_MILLI;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   141
        assertEquals(nanos, record2.getInstant().getNano(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   142
                "nanoInSecondFromEpochMilli(record2.getMillis())"
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   143
                + " + record2.getInstant().getNano() % NANOS_IN_MILLI /getInstant().getNano()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   144
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   145
        // Format the deserialized LogRecord using the SimpleFormatter, and
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   146
        // check that the string representation obtained matches the string
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   147
        // representation of the original LogRecord
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   148
        String str2 = formatter.format(record2);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   149
        if (!str.equals(str2))
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   150
            throw new RuntimeException("Unexpected values in deserialized object:"
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   151
                + "\n\tExpected:  " + str
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   152
                + "\n\tRetrieved: "+str);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   153
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   154
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   155
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   156
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   157
    public static void main(String[] args) throws Exception {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   158
        int count=0;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   159
        LogRecord record = new LogRecord(Level.INFO, "Java Version: {0}");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   160
        record.setLoggerName("test");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   161
        record.setParameters(new Object[] {System.getProperty("java.version")});
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   162
        final int nanos = record.getInstant().getNano() % NANOS_IN_MILLI;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   163
        final long millis = record.getMillis();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   164
        final Instant instant = record.getInstant();
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   165
        if (millis != instant.toEpochMilli()) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   166
            throw new RuntimeException("Unexpected millis: "
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   167
                    + record.getMillis());
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   168
        }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   169
        test(record, false);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   170
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   171
        // nano adjustment < 1ms (canonical case)
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   172
        int newNanos = (nanos + 111111) % NANOS_IN_MILLI;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   173
        record.setInstant(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   174
                (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + newNanos));
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   175
        assertEquals(newNanos, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   176
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   177
        assertEquals(millis, record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   178
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   179
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   180
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   181
        test(record, false);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   182
        assertEquals(newNanos, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   183
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   184
        assertEquals(millis, record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   185
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   186
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   187
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   188
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   189
        // nano adjustment > 1ms - non canonical - should still work
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   190
        int newExceedingNanos = 2111_111;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   191
        record.setInstant(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   192
                (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + newExceedingNanos));
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   193
        assertEquals(newExceedingNanos % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   194
                record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   195
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   196
        assertEquals(millis + newExceedingNanos / NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   197
                record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   198
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   199
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   200
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   201
        test(record, true);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   202
        assertEquals(newExceedingNanos % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   203
                record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   204
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   205
        assertEquals(millis  + newExceedingNanos / NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   206
                record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   207
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   208
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   209
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   210
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   211
        // nano adjustement > 1s - non canonical - should still work
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   212
        newExceedingNanos = 1111_111_111;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   213
        record.setInstant(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   214
                (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + newExceedingNanos));
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   215
        assertEquals(newExceedingNanos % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   216
                record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   217
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   218
        assertEquals(millis  + newExceedingNanos / NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   219
                record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   220
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   221
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   222
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   223
        test(record, true);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   224
        assertEquals(newExceedingNanos % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   225
                record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   226
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   227
        assertEquals(millis  + newExceedingNanos / NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   228
                record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   229
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   230
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   231
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   232
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   233
        // nano adjustement < 0 - non canonical - should still work
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   234
        newExceedingNanos = -1;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   235
        record.setInstant(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   236
                (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + newExceedingNanos));
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   237
        assertEquals(newExceedingNanos + NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   238
                record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   239
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   240
        assertEquals(millis -1, record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   241
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   242
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   243
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   244
        test(record, true);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   245
        record.setInstant(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   246
                (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + newExceedingNanos));
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   247
        assertEquals(millis -1, record.getMillis(), "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   248
        assertEquals(Instant.ofEpochSecond(millis/MILLIS_IN_SECOND,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   249
                (millis%MILLIS_IN_SECOND)*NANOS_IN_MILLI + newExceedingNanos),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   250
                record.getInstant(), "record.getInstant()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   251
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   252
        // setMillis
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   253
        record.setMillis(millis-1);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   254
        assertEquals(millis-1, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   255
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   256
        assertEquals(millis-1, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   257
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   258
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   259
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   260
        test(record, false);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   261
        assertEquals(millis-1, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   262
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   263
        assertEquals(millis-1, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   264
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   265
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   266
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   267
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   268
        // setMillis to 0
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   269
        record.setMillis(0);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   270
        assertEquals(0, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   271
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   272
        assertEquals(0, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   273
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   274
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   275
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   276
        test(record, false);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   277
        assertEquals(0, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   278
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   279
        assertEquals(0, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   280
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   281
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   282
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   283
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   284
        // setMillis to -1
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   285
        record.setMillis(-1);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   286
        assertEquals(-1, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   287
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   288
        assertEquals(-1, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   289
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   290
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   291
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   292
        test(record, false);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   293
        assertEquals(-1, record.getInstant().toEpochMilli(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   294
                "record.getInstant().toEpochMilli()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   295
        assertEquals(-1, record.getMillis(),
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   296
                "record.getMillis()");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   297
        assertEquals(0, record.getInstant().getNano() % NANOS_IN_MILLI,
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   298
                "record.getInstant().getNano() % NANOS_IN_MILLI");
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   299
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   300
        try {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   301
            record.setInstant(null);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   302
        } catch (NullPointerException x) {
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   303
            System.out.println("Got expected NPE when trying to call record.setInstant(null): " + x);
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   304
        }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   305
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   306
    }
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   307
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff changeset
   308
}