author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 29117 | 7956b5dc0eac |
permissions | -rw-r--r-- |
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.ZoneId; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
29 |
import java.util.Base64; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
30 |
import java.util.Locale; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
31 |
import java.util.TimeZone; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
32 |
import java.util.logging.Level; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
33 |
import java.util.logging.LogRecord; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
34 |
import java.util.logging.SimpleFormatter; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
35 |
import java.util.regex.Matcher; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
36 |
import java.util.regex.Pattern; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
37 |
import java.util.stream.Stream; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
38 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
39 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
40 |
* @test |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
41 |
* @bug 8072645 |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
42 |
* @summary tests the compatibility of LogRecord serial form between |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
43 |
* JDK 8 and JDK 9. Ideally this test should be run on both platforms. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
44 |
* (It is designed to run on both). |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
45 |
* @run main/othervm SerializeLogRecord |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
46 |
* @author danielfuchs |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
47 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
48 |
public class SerializeLogRecord { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
49 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
50 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
51 |
* Serializes a log record, encode the serialized bytes in base 64, and |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
52 |
* prints pseudo java code that can be cut and pasted into this test. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
53 |
* @param record the log record to serialize, encode in base 64, and for |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
54 |
* which test data will be generated. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
55 |
* @return A string containing the generated pseudo java code. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
56 |
* @throws IOException Unexpected. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
57 |
* @throws ClassNotFoundException Unexpected. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
58 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
59 |
public static String generate(LogRecord record) throws IOException, ClassNotFoundException { |
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 |
// 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
|
62 |
SimpleFormatter formatter = new SimpleFormatter(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
63 |
String str = formatter.format(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
64 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
65 |
// Serialize the given LogRecord |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
66 |
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
67 |
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
|
68 |
oos.writeObject(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
69 |
oos.flush(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
70 |
oos.close(); |
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 |
// Now we're going to perform a number of smoke tests before |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
73 |
// generating the Java pseudo code. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
74 |
// |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
75 |
// 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
|
76 |
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
77 |
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
|
78 |
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
|
79 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
80 |
// 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
|
81 |
// 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
|
82 |
// representation of the original LogRecord |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
83 |
String str2 = formatter.format(record2); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
84 |
if (!str.equals(str2)) 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
|
85 |
+ "\n\tExpected: " + str |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
86 |
+ "\n\tRetrieved: "+str); |
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 |
// Now get a Base64 string representation of the serialized bytes. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
89 |
final String base64 = Base64.getEncoder().encodeToString(baos.toByteArray()); |
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 |
// Check that we can deserialize a log record from the Base64 string |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
92 |
// representation we just computed. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
93 |
final ByteArrayInputStream bais2 = new ByteArrayInputStream(Base64.getDecoder().decode(base64)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
94 |
final ObjectInputStream ois2 = new ObjectInputStream(bais2); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
95 |
final LogRecord record3 = (LogRecord)ois2.readObject(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
96 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
97 |
// Format the new 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
|
98 |
// 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
|
99 |
// representation of the original LogRecord |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
100 |
String str3 = formatter.format(record3); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
101 |
if (!str.equals(str3)) 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
|
102 |
+ "\n\tExpected: " + str |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
103 |
+ "\n\tRetrieved: "+str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
104 |
//System.out.println(base64); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
105 |
//System.out.println(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
106 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
107 |
// Generates the Java Pseudo code that can be cut & pasted into |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
108 |
// this test (see Jdk8SerializedLog and Jdk9SerializedLog below) |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
109 |
final StringBuilder sb = new StringBuilder(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
110 |
sb.append(" /**").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
111 |
sb.append(" * Base64 encoded string for LogRecord object.").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
112 |
sb.append(" * Java version: ").append(System.getProperty("java.version")).append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
113 |
sb.append(" **/").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
114 |
sb.append(" final String base64 = ").append("\n "); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
115 |
final int last = base64.length() - 1; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
116 |
for (int i=0; i<base64.length();i++) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
117 |
if (i%64 == 0) sb.append("\""); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
118 |
sb.append(base64.charAt(i)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
119 |
if (i%64 == 63 || i == last) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
120 |
sb.append("\""); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
121 |
if (i == last) sb.append(";\n"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
122 |
else sb.append("\n + "); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
123 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
124 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
125 |
sb.append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
126 |
sb.append(" /**").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
127 |
sb.append(" * SimpleFormatter output for LogRecord object.").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
128 |
sb.append(" * Java version: ").append(System.getProperty("java.version")).append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
129 |
sb.append(" **/").append('\n'); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
130 |
sb.append(" final String str = ").append("\n "); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
131 |
sb.append("\"").append(str.replace("\n", "\\n")).append("\";\n"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
132 |
return sb.toString(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
133 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
134 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
135 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
136 |
* An abstract class to test that a log record previously serialized on a |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
137 |
* different java version can be deserialized in the current java version. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
138 |
* (see Jdk8SerializedLog and Jdk9SerializedLog below) |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
139 |
*/ |
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
29117
diff
changeset
|
140 |
public abstract static class SerializedLog { |
29117
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
141 |
public abstract String getBase64(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
142 |
public abstract String getString(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
143 |
|
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 |
* Deserializes the Base64 encoded string returned by {@link |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
146 |
* #getBase64()}, format the obtained LogRecord using a |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
147 |
* SimpleFormatter, and checks that the string representation obtained |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
148 |
* matches the original string representation returned by {@link |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
149 |
* #getString()}. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
150 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
151 |
protected void dotest() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
152 |
try { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
153 |
final String base64 = getBase64(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
154 |
final ByteArrayInputStream bais = |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
155 |
new ByteArrayInputStream(Base64.getDecoder().decode(base64)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
156 |
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
|
157 |
final LogRecord record = (LogRecord)ois.readObject(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
158 |
final SimpleFormatter formatter = new SimpleFormatter(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
159 |
String expected = getString(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
160 |
String str2 = formatter.format(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
161 |
check(expected, str2); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
162 |
System.out.println(str2); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
163 |
System.out.println("PASSED: "+this.getClass().getName()+"\n"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
164 |
} catch (IOException | ClassNotFoundException x) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
165 |
throw new RuntimeException(x); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
166 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
167 |
} |
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 |
* Check that the actual String representation obtained matches the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
170 |
* expected String representation. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
171 |
* @param expected Expected String representation, as returned by |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
172 |
* {@link #getString()}. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
173 |
* @param actual Actual String representation obtained by formatting |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
174 |
* the LogRecord obtained by the deserialization of the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
175 |
* bytes encoded in {@link #getBase64()}. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
176 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
177 |
protected void check(String expected, String actual) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
178 |
if (!expected.equals(actual)) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
179 |
throw new RuntimeException(this.getClass().getName() |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
180 |
+ " - Unexpected values in deserialized object:" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
181 |
+ "\n\tExpected: " + expected |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
182 |
+ "\n\tRetrieved: "+ actual); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
183 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
184 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
185 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
186 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
187 |
public static class Jdk8SerializedLog extends SerializedLog { |
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 |
// Generated by generate() on JDK 8. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
190 |
// -------------------------------- |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
191 |
// BEGIN |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
192 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
193 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
194 |
* Base64 encoded string for LogRecord object. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
195 |
* Java version: 1.8.0_11 |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
196 |
**/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
197 |
final String base64 = |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
198 |
"rO0ABXNyABtqYXZhLnV0aWwubG9nZ2luZy5Mb2dSZWNvcmRKjVk982lRlgMACkoA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
199 |
+ "Bm1pbGxpc0oADnNlcXVlbmNlTnVtYmVySQAIdGhyZWFkSURMAAVsZXZlbHQAGUxq" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
200 |
+ "YXZhL3V0aWwvbG9nZ2luZy9MZXZlbDtMAApsb2dnZXJOYW1ldAASTGphdmEvbGFu" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
201 |
+ "Zy9TdHJpbmc7TAAHbWVzc2FnZXEAfgACTAAScmVzb3VyY2VCdW5kbGVOYW1lcQB+" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
202 |
+ "AAJMAA9zb3VyY2VDbGFzc05hbWVxAH4AAkwAEHNvdXJjZU1ldGhvZE5hbWVxAH4A" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
203 |
+ "AkwABnRocm93bnQAFUxqYXZhL2xhbmcvVGhyb3dhYmxlO3hwAAABSjUCgo0AAAAA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
204 |
+ "AAAAAAAAAAFzcgAXamF2YS51dGlsLmxvZ2dpbmcuTGV2ZWyOiHETUXM2kgIAA0kA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
205 |
+ "BXZhbHVlTAAEbmFtZXEAfgACTAAScmVzb3VyY2VCdW5kbGVOYW1lcQB+AAJ4cAAA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
206 |
+ "AyB0AARJTkZPdAAic3VuLnV0aWwubG9nZ2luZy5yZXNvdXJjZXMubG9nZ2luZ3QA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
207 |
+ "BHRlc3R0ABFKYXZhIFZlcnNpb246IHswfXBwcHB3BgEAAAAAAXQACDEuOC4wXzEx" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
208 |
+ "eA=="; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
209 |
|
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 |
* SimpleFormatter output for LogRecord object. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
212 |
* Java version: 1.8.0_11 |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
213 |
**/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
214 |
final String str = |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
215 |
"Dec 10, 2014 4:22:44.621000000 PM test - INFO: Java Version: 1.8.0_11"; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
216 |
// ^^^ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
217 |
// Notice the milli second resolution above... |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
218 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
219 |
// END |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
220 |
// -------------------------------- |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
221 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
222 |
@Override |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
223 |
public String getBase64() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
224 |
return base64; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
225 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
226 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
227 |
@Override |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
228 |
public String getString() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
229 |
return str; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
230 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
231 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
232 |
public static void test() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
233 |
new Jdk8SerializedLog().dotest(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
234 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
235 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
236 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
237 |
public static class Jdk9SerializedLog extends SerializedLog { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
238 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
239 |
// Generated by generate() on JDK 9. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
240 |
// -------------------------------- |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
241 |
// BEGIN |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
242 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
243 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
244 |
* Base64 encoded string for LogRecord object. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
245 |
* Java version: 1.9.0-internal |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
246 |
**/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
247 |
final String base64 = |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
248 |
"rO0ABXNyABtqYXZhLnV0aWwubG9nZ2luZy5Mb2dSZWNvcmRKjVk982lRlgMAC0oA" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
249 |
+ "Bm1pbGxpc0kADm5hbm9BZGp1c3RtZW50SgAOc2VxdWVuY2VOdW1iZXJJAAh0aHJl" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
250 |
+ "YWRJREwABWxldmVsdAAZTGphdmEvdXRpbC9sb2dnaW5nL0xldmVsO0wACmxvZ2dl" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
251 |
+ "ck5hbWV0ABJMamF2YS9sYW5nL1N0cmluZztMAAdtZXNzYWdlcQB+AAJMABJyZXNv" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
252 |
+ "dXJjZUJ1bmRsZU5hbWVxAH4AAkwAD3NvdXJjZUNsYXNzTmFtZXEAfgACTAAQc291" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
253 |
+ "cmNlTWV0aG9kTmFtZXEAfgACTAAGdGhyb3dudAAVTGphdmEvbGFuZy9UaHJvd2Fi" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
254 |
+ "bGU7eHAAAAFLl3u6OAAOU/gAAAAAAAAAAAAAAAFzcgAXamF2YS51dGlsLmxvZ2dp" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
255 |
+ "bmcuTGV2ZWyOiHETUXM2kgIAA0kABXZhbHVlTAAEbmFtZXEAfgACTAAScmVzb3Vy" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
256 |
+ "Y2VCdW5kbGVOYW1lcQB+AAJ4cAAAAyB0AARJTkZPdAAic3VuLnV0aWwubG9nZ2lu" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
257 |
+ "Zy5yZXNvdXJjZXMubG9nZ2luZ3QABHRlc3R0ABFKYXZhIFZlcnNpb246IHswfXBw" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
258 |
+ "cHB3BgEAAAAAAXQADjEuOS4wLWludGVybmFseA=="; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
259 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
260 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
261 |
* SimpleFormatter output for LogRecord object. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
262 |
* Java version: 1.9.0-internal |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
263 |
**/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
264 |
final String str = |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
265 |
"Feb 17, 2015 12:20:43.192939000 PM test - INFO: Java Version: 1.9.0-internal"; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
266 |
// ^^^ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
267 |
// Notice the micro second resolution above... |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
268 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
269 |
// END |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
270 |
// -------------------------------- |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
271 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
272 |
@Override |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
273 |
public String getBase64() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
274 |
return base64; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
275 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
276 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
277 |
@Override |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
278 |
public String getString() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
279 |
return str; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
280 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
281 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
282 |
@Override |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
283 |
protected void check(String expected, String actual) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
284 |
if (System.getProperty("java.version").startsWith("1.8")) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
285 |
// If we are in JDK 8 and print a log record serialized in JDK 9, |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
286 |
// then we won't be able to print anything below the millisecond |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
287 |
// precision, since that hasn't been implemented in JDK 8. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
288 |
// Therefore - we need to replace anything below millseconds by |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
289 |
// zeroes in the expected string (which was generated on JDK 9). |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
290 |
Pattern pattern = Pattern.compile("^" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
291 |
+ "(.*\\.[0-9][0-9][0-9])" // group1: everything up to milliseconds |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
292 |
+ "([0-9][0-9][0-9][0-9][0-9][0-9])" // group 2: micros and nanos |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
293 |
+ "(.* - .*)$"); // group three: all the rest... |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
294 |
Matcher matcher = pattern.matcher(expected); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
295 |
if (matcher.matches()) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
296 |
expected = matcher.group(1) + "000000" + matcher.group(3); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
297 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
298 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
299 |
super.check(expected, actual); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
300 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
301 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
302 |
public static void test() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
303 |
new Jdk9SerializedLog().dotest(); |
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 |
public static void generate() { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
308 |
try { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
309 |
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
|
310 |
record.setLoggerName("test"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
311 |
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
|
312 |
System.out.println(generate(record)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
313 |
} catch (IOException | ClassNotFoundException x) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
314 |
throw new RuntimeException(x); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
315 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
316 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
317 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
318 |
static enum TestCase { GENERATE, TESTJDK8, TESTJDK9 }; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
319 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
320 |
public static void main(String[] args) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
321 |
// Set the locale and time zone to make sure we won't depend on the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
322 |
// test env - in particular we don't want to depend on the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
323 |
// time zone in which the test machine might be located. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
324 |
// So we're gong to use Locale English and Time Zone UTC for this test. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
325 |
// (Maybe that should be Locale.ROOT?) |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
326 |
Locale.setDefault(Locale.ENGLISH); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
327 |
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("UTC"))); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
328 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
329 |
// Set the format property to make sure we always have the nanos, and |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
330 |
// to make sure it's the same format than what we used when |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
331 |
// computing the formatted string for Jdk8SerializedLog and |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
332 |
// Jdk9SerializedLog above. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
333 |
// |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
334 |
// If you change the formatting, then you will need to regenerate |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
335 |
// the data for Jdk8SerializedLog and Jdk9SerializedLog. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
336 |
// |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
337 |
// To do that - just run this test on JDK 8, and cut & paste the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
338 |
// pseudo code printed by generate() into Jdk8SerializedLog. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
339 |
// Then run this test again on JDK 9, and cut & paste the |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
340 |
// pseudo code printed by generate() into Jdk9SerializedLog. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
341 |
// [Note: you can pass GENERATE as single arg to main() to avoid |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
342 |
// running the actual test] |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
343 |
// Finally run the test again to check that it still passes after |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
344 |
// your modifications. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
345 |
// |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
346 |
System.setProperty("java.util.logging.SimpleFormatter.format", |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
347 |
"%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS.%1$tN %1$Tp %2$s - %4$s: %5$s%6$s"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
348 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
349 |
// If no args, then run everything.... |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
350 |
if (args == null || args.length == 0) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
351 |
args = new String[] { "GENERATE", "TESTJDK8", "TESTJDK9" }; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
352 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
353 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
354 |
// Run the specified test case(s) |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
355 |
Stream.of(args).map(x -> TestCase.valueOf(x)).forEach((x) -> { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
356 |
switch(x) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
357 |
case GENERATE: generate(); break; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
358 |
case TESTJDK8: Jdk8SerializedLog.test(); break; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
359 |
case TESTJDK9: Jdk9SerializedLog.test(); break; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
360 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
361 |
}); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
362 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
363 |
} |