Changes to support the removal of the now callable in core (elastic/elasticsearch#3685)
Fixes to x-plugins code now that DateMathParser accepts a LongSupplier rather than a Callable to get the value of now Relates to elastic/elasticsearchelastic/elasticsearch#20796 Original commit: elastic/x-pack-elasticsearch@99fc47a8a7
This commit is contained in:
parent
31ed371ed0
commit
f9aba3944e
|
@ -22,7 +22,6 @@ import org.joda.time.DateTimeZone;
|
|||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
/**
|
||||
*
|
||||
|
@ -91,7 +90,7 @@ public class WatcherDateTimeUtils {
|
|||
}
|
||||
|
||||
public static DateTime parseDateMath(String valueString, DateTimeZone timeZone, final Clock clock) {
|
||||
return new DateTime(dateMathParser.parse(valueString, new ClockNowCallable(clock)), timeZone);
|
||||
return new DateTime(dateMathParser.parse(valueString, clock::millis), timeZone);
|
||||
}
|
||||
|
||||
public static DateTime parseDate(String fieldName, XContentParser parser, DateTimeZone timeZone) throws IOException {
|
||||
|
@ -199,18 +198,4 @@ public class WatcherDateTimeUtils {
|
|||
throw new ElasticsearchParseException("Failed to parse [{}]", e, sValue);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ClockNowCallable implements Callable<Long> {
|
||||
|
||||
private final Clock clock;
|
||||
|
||||
ClockNowCallable(Clock clock){
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return clock.millis();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.nio.file.Path;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
@ -46,21 +45,11 @@ public class TestUtils {
|
|||
private static final DateTimeFormatter dateTimeFormatter = formatDateTimeFormatter.printer();
|
||||
|
||||
public static String dateMathString(String time, final long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
}));
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, () -> now));
|
||||
}
|
||||
|
||||
public static long dateMath(String time, final long now) {
|
||||
return dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
});
|
||||
return dateMathParser.parse(time, () -> now);
|
||||
}
|
||||
|
||||
public static LicenseSpec generateRandomLicenseSpec(int version) {
|
||||
|
|
|
@ -22,8 +22,6 @@ import org.joda.time.format.DateTimeFormatter;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomInt;
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween;
|
||||
|
@ -51,21 +49,11 @@ public class TestUtils {
|
|||
}
|
||||
|
||||
public static String dateMathString(String time, final long now) {
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
}));
|
||||
return dateTimeFormatter.print(dateMathParser.parse(time, () -> now));
|
||||
}
|
||||
|
||||
public static long dateMath(String time, final long now) {
|
||||
return dateMathParser.parse(time, new Callable<Long>() {
|
||||
@Override
|
||||
public Long call() throws Exception {
|
||||
return now;
|
||||
}
|
||||
});
|
||||
return dateMathParser.parse(time, () -> now);
|
||||
}
|
||||
|
||||
public static LicenseSpec generateRandomLicenseSpec(int version) {
|
||||
|
|
Loading…
Reference in New Issue