kgeisz commented on code in PR #7683:
URL: https://github.com/apache/hbase/pull/7683#discussion_r2737874570


##########
hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupUtils.java:
##########
@@ -110,9 +129,99 @@ public void testFilesystemWalHostNameParsing() throws 
IOException {
       Path testOldWalWithRegionGroupingPath = new Path(oldLogDir,
         serverName + BackupUtils.LOGNAME_SEPARATOR + serverName + 
BackupUtils.LOGNAME_SEPARATOR
           + "regiongroup-0" + BackupUtils.LOGNAME_SEPARATOR + 
EnvironmentEdgeManager.currentTime());
-      Assert.assertEquals(host + Addressing.HOSTNAME_PORT_SEPARATOR + port,
+      assertEquals(host + Addressing.HOSTNAME_PORT_SEPARATOR + port,
         BackupUtils.parseHostFromOldLog(testOldWalWithRegionGroupingPath));
     }
+  }
+
+  // Ensure getValidWalDirs() uses UTC timestamps regardless of what time zone 
the test is run in.
+  @Test
+  public void testGetValidWalDirForAllTimeZonesSingleDay() throws IOException {
+    // This UTC test time is a time when it is still "yesterday" in other time 
zones (such as PST)
+    List<String> walDateDirs = List.of("2026-01-23");
+    Path walDir = new Path(backupRootDir, "WALs");
+
+    // 10-minute window in UTC between start and end time
+    long startTime = Instant.parse("2026-01-23T01:00:00Z").toEpochMilli();
+    long endTime = startTime + (10 * 60 * 1000);
+
+    testGetValidWalDirs(startTime, endTime, walDir, walDateDirs, 1, 
walDateDirs);
+  }
+
+  // Ensure getValidWalDirs() works as expected for time ranges across 
multiple days for all time
+  // zones
+  @Test
+  public void testGetValidWalDirsForAllTimeZonesMultiDay() throws IOException {
+    List<String> walDateDirs = List.of("2025-12-30", "2025-12-31", 
"2026-01-01", "2026-01-02");
+    List<String> expectedValidWalDirs = List.of("2025-12-31", "2026-01-01");
+    Path walDir = new Path(backupRootDir, "WALs");
+
+    // 10-minute window in UTC between start and end time that spans over two 
days
+    long startTime = Instant.parse("2025-12-31T23:55:00Z").toEpochMilli();
+    long endTime = Instant.parse("2026-01-01T00:05:00Z").toEpochMilli();
+
+    testGetValidWalDirs(startTime, endTime, walDir, walDateDirs, 2, 
expectedValidWalDirs);
+  }
+
+  @Test
+  public void testGetValidWalDirExactlyMidnightUTC() throws IOException {
+    List<String> walDateDirs = List.of("2026-01-23");
+    Path walDir = new Path(backupRootDir, "WALs");
+    // This instant is UTC
+    long startAndEndTime = 
Instant.parse("2026-01-23T00:00:00.000Z").toEpochMilli();
 
+    testGetValidWalDirs(startAndEndTime, startAndEndTime, walDir, walDateDirs, 
1, walDateDirs);
+  }
+
+  @Test
+  public void testGetValidWalDirOneMsBeforeMidnightUTC() throws IOException {
+    List<String> walDateDirs = List.of("2026-01-23");
+    Path walDir = new Path(backupRootDir, "WALs");
+    // This instant is UTC
+    long startAndEndTime = 
Instant.parse("2026-01-23T23:59:59.999Z").toEpochMilli();
+
+    testGetValidWalDirs(startAndEndTime, startAndEndTime, walDir, walDateDirs, 
1, walDateDirs);
+  }
+
+  protected void testGetValidWalDirs(long startTime, long endTime, Path walDir,
+    List<String> walDateDirs, int numExpectedValidWalDirs, List<String> 
expectedValidWalDirs)
+    throws IOException {
+    TimeZone defaultTimeZone = TimeZone.getDefault();
+    try {
+      // This UTC test time is a time when it is still "yesterday" in other 
time zones (such as PST)
+      for (String dirName : walDateDirs) {
+        dummyFs.mkdirs(new Path(walDir, dirName));
+      }
+
+      // Ensure we can get valid WAL dirs regardless of the test environment's 
time zone
+      for (String timeZone : ZoneId.getAvailableZoneIds()) {

Review Comment:
   It's pretty fast. The `testGetValidWalDirsForAllTimeZonesMultiDay()` method 
finishes in about 250ms.  The entire test class takes about 450ms.



-- 
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]

Reply via email to