steveloughran commented on code in PR #5508:
URL: https://github.com/apache/hadoop/pull/5508#discussion_r1146691034
##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java:
##########
@@ -78,6 +78,31 @@ public void testUpdateAndGet() throws IOException {
Assert.assertTrue(token3 == cachedToken);
}
+ @Test
+ public void testValidExpirationParsing() {
+ CachedSASToken cachedSasToken = new CachedSASToken();
+ String[] values = {
+ "2123-03-24T00:06:46Z", // sample timestamp from azure portal
+ "2124-03-30", // sample YYYY-MM-DD date format generated from az cli
+ "2125-03-30Z", // sample YYYY-MM-DD[offset] date format
+ };
+
+ for (String se : values) {
+ cachedSasToken.setForTesting(null, null);
+ String token = "se=" + se;
+
+ // set first time and ensure reference equality
+ cachedSasToken.update(token);
+ String cachedToken = cachedSasToken.get();
+ Assert.assertTrue(token == cachedToken);
Review Comment:
assertEquals(expected, actual) or AssertJ.asserThat(). thanks
##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/CachedSASToken.java:
##########
@@ -114,8 +125,20 @@ private static OffsetDateTime getExpiry(String token) {
OffsetDateTime seDate = OffsetDateTime.MIN;
try {
seDate = OffsetDateTime.parse(seValue, DateTimeFormatter.ISO_DATE_TIME);
- } catch (DateTimeParseException ex) {
- LOG.error("Error parsing se query parameter ({}) from SAS.", seValue,
ex);
+ } catch (DateTimeParseException dateTimeException) {
+ try {
+ TemporalAccessor dt = isoDateMidnight.parseBest(seValue,
OffsetDateTime::from, LocalDateTime::from);
+ if (dt instanceof OffsetDateTime) {
+ seDate = (OffsetDateTime) dt;
+ } else if (dt instanceof LocalDateTime) {
+ seDate = ((LocalDateTime) dt).atOffset(ZoneOffset.UTC);
+ } else {
+ throw dateTimeException;
+ }
+ } catch (DateTimeParseException dateOnlyException) {
+ // log original exception
+ LOG.error("Error parsing se query parameter ({}) from SAS as
ISO_DATE_TIME or ISO_DATE.", seValue, dateTimeException);
Review Comment:
now, if there's a problem here it is still going to log a lot, isn't it?
might be best to use a LogExactlyOnce log here for the error line, and log
at debug the rest of the time
##########
hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/utils/TestCachedSASToken.java:
##########
@@ -78,6 +78,31 @@ public void testUpdateAndGet() throws IOException {
Assert.assertTrue(token3 == cachedToken);
}
+ @Test
+ public void testValidExpirationParsing() {
Review Comment:
is there a test for an invalid date time parsing now?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]