Skip to content

Commit

Permalink
SOLR-17278: Skip broken timezones in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Chattopadhyaya committed May 6, 2024
1 parent f823e9b commit d5b8241
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion solr/core/src/test/org/apache/solr/util/TimeZoneUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
*/
package org.apache.solr.util;

import java.lang.invoke.MethodHandles;
import java.util.HashSet;
import java.util.Locale;
import java.util.Random;
import java.util.Set;
import java.util.TimeZone;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.SolrTestCase;
import org.apache.solr.common.util.SuppressForbidden;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TimeZoneUtilsTest extends SolrTestCase {

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static void assertSameRules(
final String label, final TimeZone expected, final TimeZone actual) {

Expand All @@ -39,10 +45,12 @@ private static void assertSameRules(
assertTrue(label + ": " + expected + " [[NOT SAME RULES]] " + actual, same);
}

@SuppressForbidden(reason = "Using TimeZone.getDisplayName() just for warning purpose in a test")
public void testValidIds() {

final Set<String> idsTested = new HashSet<>();

int skipped = 0;
// brain dead: anything the JVM supports, should work
for (String validId : TimeZone.getAvailableIDs()) {
assertTrue(
Expand All @@ -51,14 +59,28 @@ public void testValidIds() {

final TimeZone expected = TimeZone.getTimeZone(validId);
final TimeZone actual = TimeZoneUtils.getTimeZone(validId);

// Hack: Why do some timezones have useDaylightTime() as true, but DST as 0?
// It causes an exception during String.valueOf(actual/expected)
if (expected.useDaylightTime() && expected.getDSTSavings() == 0
|| actual.useDaylightTime() && actual.getDSTSavings() == 0) {
if (log.isWarnEnabled()) {
log.warn(
"Not expecting DST to be 0 for {} " + " (actual: {})",
expected.getDisplayName(),
actual.getDisplayName());
}
skipped++;
continue;
}
assertSameRules(validId, expected, actual);

idsTested.add(validId);
}

assertEquals(
"TimeZone.getAvailableIDs vs TimeZoneUtils.KNOWN_TIMEZONE_IDS",
TimeZoneUtils.KNOWN_TIMEZONE_IDS.size(),
TimeZoneUtils.KNOWN_TIMEZONE_IDS.size() - skipped,
idsTested.size());
}

Expand Down

0 comments on commit d5b8241

Please sign in to comment.