8278434: timeouts in test java/time/test/java/time/format/TestZoneTextPrinterParser.java

Backport-of: 8dc4437d002db5d025b47f48e7420e3bae55bdec
This commit is contained in:
Naoto Sato 2022-01-13 22:05:52 +00:00
parent ff85659311
commit 064ee6ae13
3 changed files with 66 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -151,8 +151,8 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
// Check parent locales first
if (!exists(names, index)) {
CLDRLocaleProviderAdapter clpa = (CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR);
var cands = clpa.getCandidateLocales("", locale);
var cands = ((CLDRLocaleProviderAdapter)LocaleProviderAdapter.forType(Type.CLDR))
.getCandidateLocales("", locale);
for (int i = 1; i < cands.size() ; i++) {
String[] parentNames = super.getDisplayNameArray(id, cands.get(i));
if (parentNames != null && !parentNames[index].isEmpty()) {
@ -162,11 +162,6 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
}
}
// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
}
// Type Fallback
if (noDST && typeFallback(names, index)) {
return;
@ -185,6 +180,11 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
}
}
// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
}
// last resort
names[index] = toGMTFormat(id,
index == INDEX_DST_LONG || index == INDEX_DST_SHORT,
@ -230,6 +230,11 @@ public class CLDRTimeZoneNameProviderImpl extends TimeZoneNameProviderImpl {
}
private boolean regionFormatFallback(String[] names, int index, Locale l) {
if (index % 2 == 0) {
// ignore short names
return false;
}
String id = names[INDEX_TZID];
LocaleResources lr = LocaleProviderAdapter.forType(Type.CLDR).getLocaleResources(l);
ResourceBundle fd = lr.getJavaTimeFormatData();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -51,7 +51,7 @@ import org.testng.annotations.Test;
/*
* @test
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049 8278434
* @key randomness
*/
@ -61,6 +61,11 @@ import org.testng.annotations.Test;
@Test
public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
private static final Locale[] SAMPLE_LOCALES = {
Locale.US, Locale.UK, Locale.FRANCE, Locale.GERMANY, Locale.ITALY, Locale.forLanguageTag("es"),
Locale.forLanguageTag("pt-BR"), Locale.forLanguageTag("ru"),
Locale.CHINA, Locale.TAIWAN, Locale.JAPAN, Locale.KOREA, Locale.ROOT};
protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style) {
return new DateTimeFormatterBuilder().appendZoneText(style)
.toFormatter(locale)
@ -70,7 +75,6 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
public void test_printText() {
Random r = RandomFactory.getRandom();
int N = 8;
Locale[] locales = Locale.getAvailableLocales();
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
ZonedDateTime zdt = ZonedDateTime.now();
@ -85,7 +89,7 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
TimeZone tz = TimeZone.getTimeZone(zid);
boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
for (Locale locale : locales) {
for (Locale locale : SAMPLE_LOCALES) {
String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
@ -118,9 +122,8 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
}
public void test_ParseText() {
Locale[] locales = new Locale[] { Locale.ENGLISH, Locale.JAPANESE, Locale.FRENCH };
Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
for (Locale locale : locales) {
for (Locale locale : SAMPLE_LOCALES) {
parseText(zids, locale, TextStyle.FULL, false);
parseText(zids, locale, TextStyle.FULL, true);
parseText(zids, locale, TextStyle.SHORT, false);

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package org.openjdk.bench.java.text;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import java.text.DateFormatSymbols;
import java.util.Locale;
@BenchmarkMode(Mode.SingleShotTime)
@State(Scope.Thread)
public class ZoneStrings {
@Benchmark
public void testZoneStrings() {
for (Locale l : Locale.getAvailableLocales()) {
new DateFormatSymbols(l).getZoneStrings();
}
}
}