Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8278434: timeouts in test java/time/test/java/time/format/TestZoneTex…
…tPrinterParser.java

Backport-of: 8dc4437d002db5d025b47f48e7420e3bae55bdec
  • Loading branch information
naotoj committed Jan 13, 2022
1 parent ff85659 commit 064ee6ae135366d59e9485b449a41d2b55811bbe
Showing 3 changed files with 66 additions and 14 deletions.
@@ -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 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea

// 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 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
}
}

// Region Fallback
if (regionFormatFallback(names, index, locale)) {
return;
}

// Type Fallback
if (noDST && typeFallback(names, index)) {
return;
@@ -185,6 +180,11 @@ private void deriveFallbackName(String[] names, int index, Locale locale, boolea
}
}

// 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 @@ private boolean typeFallback(String[] names, int index) {
}

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();
@@ -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 @@

/*
* @test
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049
* @bug 8081022 8151876 8166875 8177819 8189784 8206980 8277049 8278434
* @key randomness
*/

@@ -61,6 +61,11 @@
@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 @@ protected static DateTimeFormatter getFormatter(Locale locale, TextStyle style)
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 void test_printText() {
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 @@ private void printText(Locale locale, ZonedDateTime zdt, TextStyle style, TimeZo
}

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);
@@ -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();
}
}
}

1 comment on commit 064ee6a

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 064ee6a Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.