Test: Filter out deprecated joda tzs in tests (#34868)

This commit filters out usage of deprecated tzs by tests. These are
tested separately and should not require checking for warnings on any
test using random timezones.

closes #34188
This commit is contained in:
Ryan Ernst 2018-10-30 11:15:34 -07:00 committed by GitHub
parent 2b2e208c4c
commit 512319cef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -28,6 +28,7 @@ import java.time.ZoneOffset;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class DateUtils {
public static DateTimeZone zoneIdToDateTimeZone(ZoneId zoneId) {
@ -44,6 +45,7 @@ public class DateUtils {
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(DateFormatters.class));
// pkg private for tests
static final Map<String, String> DEPRECATED_SHORT_TIMEZONES;
public static final Set<String> DEPRECATED_SHORT_TZ_IDS;
static {
Map<String, String> tzs = new HashMap<>();
tzs.put("EST", "-05:00"); // eastern time without daylight savings
@ -52,6 +54,7 @@ public class DateUtils {
tzs.put("ROC", "Asia/Taipei");
tzs.put("Eire", "Europe/London");
DEPRECATED_SHORT_TIMEZONES = Collections.unmodifiableMap(tzs);
DEPRECATED_SHORT_TZ_IDS = tzs.keySet();
}
public static ZoneId dateTimeZoneToZoneId(DateTimeZone timeZone) {

View File

@ -444,7 +444,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
DateTime queryToValue = new DateTime(2016, 1, 1, 0, 0, 0, ISOChronology.getInstanceUTC());
query.from(queryFromValue);
query.to(queryToValue);
query.timeZone(randomFrom(DateTimeZone.getAvailableIDs()));
query.timeZone(randomDateTimeZone().getID());
query.format("yyyy-MM-dd");
QueryShardContext queryShardContext = createShardContext();
QueryBuilder rewritten = query.rewrite(queryShardContext);

View File

@ -69,6 +69,7 @@ import org.elasticsearch.common.logging.LogConfigurator;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateUtils;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.util.MockBigArrays;
import org.elasticsearch.common.util.MockPageCacheRecycler;
@ -184,9 +185,9 @@ import static org.hamcrest.Matchers.hasItem;
@LuceneTestCase.SuppressReproduceLine
public abstract class ESTestCase extends LuceneTestCase {
private static final List<String> JODA_TIMEZONE_IDS;
private static final List<String> JAVA_TIMEZONE_IDS;
private static final List<String> JAVA_ZONE_IDS;
protected static final List<String> JODA_TIMEZONE_IDS;
protected static final List<String> JAVA_TIMEZONE_IDS;
protected static final List<String> JAVA_ZONE_IDS;
private static final AtomicInteger portGenerator = new AtomicInteger();
@ -227,8 +228,9 @@ public abstract class ESTestCase extends LuceneTestCase {
BootstrapForTesting.ensureInitialized();
List<String> jodaTZIds = new ArrayList<>(DateTimeZone.getAvailableIDs());
Collections.sort(jodaTZIds);
// filter out joda timezones that are deprecated for the java time migration
List<String> jodaTZIds = DateTimeZone.getAvailableIDs().stream()
.filter(DateUtils.DEPRECATED_SHORT_TZ_IDS::contains).sorted().collect(Collectors.toList());
JODA_TIMEZONE_IDS = Collections.unmodifiableList(jodaTZIds);
List<String> javaTZIds = Arrays.asList(TimeZone.getAvailableIDs());

View File

@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xpack.sql.jdbc.jdbc.JdbcConfiguration;
import org.elasticsearch.xpack.sql.jdbc.jdbcx.JdbcDataSource;
import org.joda.time.DateTimeZone;
import org.junit.After;
import java.io.IOException;
@ -23,13 +22,11 @@ import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.TimeZone;
import static org.elasticsearch.xpack.qa.sql.rest.RestSqlTestCase.assertNoSearchContexts;
@ -119,8 +116,8 @@ public abstract class JdbcIntegrationTestCase extends ESRestTestCase {
// from all available JDK timezones. While Joda and JDK are generally in sync, some timezones might not be known
// to the current version of Joda and in this case the test might fail. To avoid that, we specify a timezone
// known for both Joda and JDK
Set<String> timeZones = new HashSet<>(DateTimeZone.getAvailableIDs());
timeZones.retainAll(Arrays.asList(TimeZone.getAvailableIDs()));
Set<String> timeZones = new HashSet<>(JODA_TIMEZONE_IDS);
timeZones.retainAll(JAVA_TIMEZONE_IDS);
List<String> ids = new ArrayList<>(timeZones);
Collections.sort(ids);
return randomFrom(ids);