ppkarwasz commented on code in PR #3338:
URL: https://github.com/apache/logging-log4j2/pull/3338#discussion_r1898969681
##########
log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatterTest.java:
##########
@@ -47,112 +45,81 @@ class InstantPatternDynamicFormatterTest {
@ParameterizedTest
@MethodSource("sequencingTestCases")
void sequencing_should_work(
- final String pattern, final ChronoUnit thresholdPrecision, final
List<PatternSequence> expectedSequences) {
- final List<PatternSequence> actualSequences = sequencePattern(pattern,
thresholdPrecision);
+ final String pattern,
+ final ChronoUnit thresholdPrecision,
+ final List<PatternFormatterFactory> expectedSequences) {
+ final List<PatternFormatterFactory> actualSequences =
sequencePattern(pattern, thresholdPrecision);
assertThat(actualSequences).isEqualTo(expectedSequences);
}
static List<Arguments> sequencingTestCases() {
final List<Arguments> testCases = new ArrayList<>();
// `SSSX` should be treated constant for daily updates
- testCases.add(Arguments.of("SSSX", ChronoUnit.DAYS,
singletonList(pCom(pDyn("SSS"), pDyn("X")))));
+ testCases.add(Arguments.of("SSSX", ChronoUnit.DAYS,
asList(pMilliSec(), pDyn("X"))));
// `yyyyMMddHHmmssSSSX` instant cache updated hourly
testCases.add(Arguments.of(
"yyyyMMddHHmmssSSSX",
ChronoUnit.HOURS,
- asList(
- pCom(pDyn("yyyy"), pDyn("MM"), pDyn("dd"), pDyn("HH")),
- pCom(pDyn("mm"), pDyn("ss"), pDyn("SSS")),
- pDyn("X"))));
+ asList(pDyn("yyyyMMddHH", ChronoUnit.HOURS), pDyn("mm"),
pSec("", 3), pDyn("X"))));
// `yyyyMMddHHmmssSSSX` instant cache updated per minute
testCases.add(Arguments.of(
"yyyyMMddHHmmssSSSX",
ChronoUnit.MINUTES,
- asList(
- pCom(pDyn("yyyy"), pDyn("MM"), pDyn("dd"), pDyn("HH"),
pDyn("mm")),
- pCom(pDyn("ss"), pDyn("SSS")),
- pDyn("X"))));
+ asList(pDyn("yyyyMMddHHmm", ChronoUnit.MINUTES), pSec("", 3),
pDyn("X"))));
// ISO9601 instant cache updated daily
final String iso8601InstantPattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX";
testCases.add(Arguments.of(
iso8601InstantPattern,
ChronoUnit.DAYS,
asList(
- pCom(pDyn("yyyy"), pSta("-"), pDyn("MM"), pSta("-"),
pDyn("dd"), pSta("T")),
- pCom(
- pDyn("HH"),
- pSta(":"),
- pDyn("mm"),
- pSta(":"),
- pDyn("ss"),
- pSta("."),
- pDyn("SSS"),
- pDyn("X")))));
+ pDyn("yyyy'-'MM'-'dd'T'", ChronoUnit.DAYS),
+ pDyn("HH':'mm':'", ChronoUnit.MINUTES),
+ pSec(".", 3),
+ pDyn("X"))));
// ISO9601 instant cache updated per minute
testCases.add(Arguments.of(
iso8601InstantPattern,
ChronoUnit.MINUTES,
- asList(
- pCom(
- pDyn("yyyy"),
- pSta("-"),
- pDyn("MM"),
- pSta("-"),
- pDyn("dd"),
- pSta("T"),
- pDyn("HH"),
- pSta(":"),
- pDyn("mm"),
- pSta(":")),
- pCom(pDyn("ss"), pSta("."), pDyn("SSS")),
- pDyn("X"))));
+ asList(pDyn("yyyy'-'MM'-'dd'T'HH':'mm':'",
ChronoUnit.MINUTES), pSec(".", 3), pDyn("X"))));
// ISO9601 instant cache updated per second
testCases.add(Arguments.of(
iso8601InstantPattern,
ChronoUnit.SECONDS,
- asList(
- pCom(
- pDyn("yyyy"),
- pSta("-"),
- pDyn("MM"),
- pSta("-"),
- pDyn("dd"),
- pSta("T"),
- pDyn("HH"),
- pSta(":"),
- pDyn("mm"),
- pSta(":"),
- pDyn("ss"),
- pSta(".")),
- pDyn("SSS"),
- pDyn("X"))));
+ asList(pDyn("yyyy'-'MM'-'dd'T'HH':'mm':'",
ChronoUnit.MINUTES), pSec(".", 3), pDyn("X"))));
+
+ // Seconds and micros
+ testCases.add(Arguments.of(
+ "HH:mm:ss.SSSSSS", ChronoUnit.MINUTES,
asList(pDyn("HH':'mm':'", ChronoUnit.MINUTES), pSec(".", 6))));
return testCases;
}
- private static CompositePatternSequence pCom(final PatternSequence...
sequences) {
- return new CompositePatternSequence(asList(sequences));
+ private static DateTimeFormatterPatternFormatterFactory pDyn(final String
pattern) {
+ return new DateTimeFormatterPatternFormatterFactory(pattern);
+ }
+
+ private static DateTimeFormatterPatternFormatterFactory pDyn(final String
pattern, final ChronoUnit precision) {
+ return new DateTimeFormatterPatternFormatterFactory(pattern,
precision);
}
- private static DynamicPatternSequence pDyn(final String pattern) {
- return new DynamicPatternSequence(pattern);
+ private static SecondPatternFormatterFactory pSec(String separator, int
fractionalDigits) {
+ return new SecondPatternFormatterFactory(true, separator,
fractionalDigits);
}
- private static StaticPatternSequence pSta(final String literal) {
- return new StaticPatternSequence(literal);
+ private static SecondPatternFormatterFactory pMilliSec() {
+ return new SecondPatternFormatterFactory(false, "", 3);
}
@ParameterizedTest
@ValueSource(
strings = {
// Basics
- "S",
Review Comment:
`S` does not have a nanosecond precision. The Javadoc of
[`DateTimeFormatter`](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)
says:
> **Fraction**: Outputs the nano-of-second field as a fraction-of-second.
The nano-of-second value has nine digits, thus the count of pattern letters is
from 1 to 9. If it is less than 9, then the nano-of-second value is truncated,
with only the most significant digits being output.
So `S` should print the most significant digit of nanoseconds (i.e.
deciseconds)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]