Skip to content
Permalink
Browse files
8278434: timeouts in test java/time/test/java/time/format/TestZoneTex…
…tPrinterParser.java

Reviewed-by: joehw
  • Loading branch information
naotoj committed Jan 4, 2022
1 parent 6b906bb commit 8dc4437d002db5d025b47f48e7420e3bae55bdec
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();
}
}
}

3 comments on commit 8dc4437

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 8dc4437 Jan 4, 2022

Choose a reason for hiding this comment

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

@naotoj
Copy link
Member Author

@naotoj naotoj commented on 8dc4437 Jan 13, 2022

Choose a reason for hiding this comment

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

/backport jdk18

@openjdk
Copy link

@openjdk openjdk bot commented on 8dc4437 Jan 13, 2022

Choose a reason for hiding this comment

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

@naotoj the backport was successfully created on the branch naotoj-backport-8dc4437d in my personal fork of openjdk/jdk18. To create a pull request with this backport targeting openjdk/jdk18:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 8dc4437d from the openjdk/jdk repository.

The commit being backported was authored by Naoto Sato on 4 Jan 2022 and was reviewed by Joe Wang.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk18:

$ git fetch https://github.com/openjdk-bots/jdk18 naotoj-backport-8dc4437d:naotoj-backport-8dc4437d
$ git checkout naotoj-backport-8dc4437d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk18 naotoj-backport-8dc4437d

Please sign in to comment.