Skip to content

Commit 8dc4437

Browse files
committed
8278434: timeouts in test java/time/test/java/time/format/TestZoneTextPrinterParser.java
Reviewed-by: joehw
1 parent 6b906bb commit 8dc4437

File tree

3 files changed

+66
-14
lines changed

3 files changed

+66
-14
lines changed

src/java.base/share/classes/sun/util/cldr/CLDRTimeZoneNameProviderImpl.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -151,8 +151,8 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
151151

152152
// Check parent locales first
153153
if (!exists(names, index)) {
154-
CLDRLocaleProviderAdapter clpa = (CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR);
155-
var cands = clpa.getCandidateLocales("", locale);
154+
var cands = ((CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR))
155+
.getCandidateLocales("", locale);
156156
for (int i = 1; i < cands.size() ; i++) {
157157
String[] parentNames = super.getDisplayNameArray(id, cands.get(i));
158158
if (parentNames != null && !parentNames[index].isEmpty()) {
@@ -162,11 +162,6 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
162162
}
163163
}
164164

165-
// Region Fallback
166-
if (regionFormatFallback(names, index, locale)) {
167-
return;
168-
}
169-
170165
// Type Fallback
171166
if (noDST && typeFallback(names, index)) {
172167
return;
@@ -185,6 +180,11 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
185180
}
186181
}
187182

183+
// Region Fallback
184+
if (regionFormatFallback(names, index, locale)) {
185+
return;
186+
}
187+
188188
// last resort
189189
names[index] = toGMTFormat(id,
190190
index == INDEX_DST_LONG || index == INDEX_DST_SHORT,
@@ -230,6 +230,11 @@ private boolean typeFallback(String[] names, int index) {
230230
}
231231

232232
private boolean regionFormatFallback(String[] names, int index, Locale l) {
233+
if (index % 2 == 0) {
234+
// ignore short names
235+
return false;
236+
}
237+
233238
String id = names[INDEX_TZID];
234239
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
235240
ResourceBundle fd = lr.getJavaTimeFormatData();

test/jdk/java/time/test/java/time/format/TestZoneTextPrinterParser.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -51,7 +51,7 @@
5151

5252
/*
5353
* @test
54-
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049
54+
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049 8278434
5555
* @key randomness
5656
*/
5757

@@ -61,6 +61,11 @@
6161
@Test
6262
public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
6363

64+
private static final Locale[] SAMPLE_LOCALES = {
65+
Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY, Locale.ITALY, Locale.forLanguageTag("es"),
66+
Locale.forLanguageTag("pt-BR"), Locale.forLanguageTag("ru"),
67+
Locale.CHINA, Locale.TAIWAN, Locale.JAPAN, Locale.KOREA, Locale.ROOT};
68+
6469
protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
6570
return new DateTimeFormatterBuilder().appendZoneText(style)
6671
.toFormatter(locale)
@@ -70,7 +75,6 @@ protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style)
7075
public void test_printText() {
7176
Random r = RandomFactory.getRandom();
7277
int N = 8;
73-
Locale[] locales = Locale.getAvailableLocales();
7478
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
7579
ZonedDateTime zdt = ZonedDateTime.now();
7680

@@ -85,7 +89,7 @@ public void test_printText() {
8589
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
8690
TimeZone tz = TimeZone.getTimeZone(zid);
8791
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
88-
for (Locale locale : locales) {
92+
for (Locale locale : SAMPLE_LOCALES) {
8993
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
9094
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
9195
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
@@ -118,9 +122,8 @@ private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, TimeZo
118122
}
119123

120124
public void test_ParseText() {
121-
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
122125
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
123-
for (Locale locale : locales) {
126+
for (Locale locale : SAMPLE_LOCALES) {
124127
parseText(zids, locale, TextStyle.FULL, false);
125128
parseText(zids, locale, TextStyle.FULL, true);
126129
parseText(zids, locale, TextStyle.SHORT, false);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package org.openjdk.bench.java.text;
24+
25+
import org.openjdk.jmh.annotations.Benchmark;
26+
import org.openjdk.jmh.annotations.BenchmarkMode;
27+
import org.openjdk.jmh.annotations.Mode;
28+
import org.openjdk.jmh.annotations.Scope;
29+
import org.openjdk.jmh.annotations.State;
30+
31+
import java.text.DateFormatSymbols;
32+
import java.util.Locale;
33+
34+
@BenchmarkMode(Mode.SingleShotTime)
35+
@State(Scope.Thread)
36+
public class ZoneStrings {
37+
38+
@Benchmark
39+
public void testZoneStrings() {
40+
for (Locale l : Locale.getAvailableLocales()) {
41+
new DateFormatSymbols(l).getZoneStrings();
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)