Skip to content

Commit 2e01473

Browse files
committed
8278434: timeouts in test java/time/test/java/time/format/TestZoneTextPrinterParser.java
Reviewed-by: phh Backport-of: 064ee6ae135366d59e9485b449a41d2b55811bbe
1 parent 5fa213a commit 2e01473

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, 2018, 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
@@ -49,7 +49,7 @@
4949

5050
/*
5151
* @test
52-
* @bug 8081022 8151876 8166875 8189784 8206980
52+
* @bug 8081022 8151876 8166875 8189784 8206980 8278434
5353
* @key randomness
5454
*/
5555

@@ -59,6 +59,11 @@
5959
@Test
6060
public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
6161

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

@@ -83,7 +87,7 @@ public void test_printText() {
8387
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
8488
TimeZone tz = TimeZone.getTimeZone(zid);
8589
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
86-
for (Locale locale : locales) {
90+
for (Locale locale : SAMPLE_LOCALES) {
8791
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
8892
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
8993
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
@@ -116,9 +120,8 @@ private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, TimeZo
116120
}
117121

118122
public void test_ParseText() {
119-
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
120123
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
121-
for (Locale locale : locales) {
124+
for (Locale locale : SAMPLE_LOCALES) {
122125
parseText(zids, locale, TextStyle.FULL, false);
123126
parseText(zids, locale, TextStyle.FULL, true);
124127
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)