@@ -409,40 +409,62 @@ public void setIncludeBeforeEpochNullEpochTest() {
409409 }
410410
411411 /**
412- * Testing timezone handling of epoch_hour and logtime near midnight.
412+ * Testing timezone handling of epoch_hour and logtime near midnight using 2 different session timezones .
413413 */
414414 @ Test
415415 public void epochHourTimezoneTest () {
416416 // Add test data to logfile table in journaldb.
417417 final DSLContext ctx = DSL .using (connection , SQLDialect .MYSQL );
418- // Set epoch_hour to 2023-10-05 01:00 UTC, which will cause issues if session timezone (America/New_York, UTC-4) is affecting logtime and logdate result .
418+ // Create a LogfileRecord object with epoch_hour of 2023-10-05 01:00 UTC.
419419 LogfileRecord logfileRecord = logfileRecordForEpoch (1696467600L , false );
420+ // Insert the logfileRecord to the database using JOOQ.
420421 ctx .insertInto (JOURNALDB .LOGFILE ).set (logfileRecord ).execute ();
421422
422- // Assert StreamDBClient methods work as expected with the test data .
423+ // Create an instance of StreamDBClient using the default server timezone (UTC-4) .
423424 final Map <String , String > opts = this .opts ;
424425 opts .put ("DBurl" , mariadb .getJdbcUrl ());
425426 final Config config = new Config (opts );
426427 final StreamDBClient sdc = Assertions .assertDoesNotThrow (() -> new StreamDBClient (config ));
427- Long earliestEpoch = 1696377600L ; // 2023-10-04
428+ // Create another instance of StreamDBClient using explicitly set UTC session timezone.
429+ final Map <String , String > optsUTC = this .opts ;
430+ optsUTC .put ("DBurl" , mariadb .getJdbcUrl () + "?forceConnectionTimeZoneToSession=true&connectionTimeZone=UTC" );
431+ final Config configUTC = new Config (optsUTC );
432+ final StreamDBClient sdcUTC = Assertions .assertDoesNotThrow (() -> new StreamDBClient (configUTC ));
433+
434+ final Long earliestEpoch = 1696377600L ; // 2023-10-04
428435 Long latestOffset = earliestEpoch ;
429436
430437 // Pull the records from a specific logdate to the slicetable for further processing.
431438 int rows = sdc .pullToSliceTable (Date .valueOf ("2023-10-5" ));
432439 Assertions .assertEquals (1 , rows );
440+ // Do the same for sdcUTC
441+ Assertions .assertEquals (rows , sdcUTC .pullToSliceTable (Date .valueOf ("2023-10-5" )));
433442
434443 // Get the offset for the first non-empty hour of records from the slicetable.
435444 WeightedOffset nextHourAndSizeFromSliceTable = sdc .getNextHourAndSizeFromSliceTable (latestOffset );
436445 Assertions .assertFalse (nextHourAndSizeFromSliceTable .isStub );
446+ // Do the same for sdcUTC
447+ WeightedOffset nextHourAndSizeFromSliceTableUTC = sdcUTC .getNextHourAndSizeFromSliceTable (latestOffset );
448+ Assertions .assertFalse (nextHourAndSizeFromSliceTableUTC .isStub );
449+
437450 latestOffset = nextHourAndSizeFromSliceTable .offset ();
451+ Assertions .assertEquals (latestOffset , nextHourAndSizeFromSliceTableUTC .offset ());
452+
453+ // Get the logfile results from the known hour range.
438454 Assertions .assertEquals (1696467600L , latestOffset );
439455 Result <Record11 <ULong , String , String , String , String , Date , String , String , Long , ULong , ULong >> hourRange = sdc
440456 .getHourRange (earliestEpoch , latestOffset );
441457 Assertions .assertEquals (1 , hourRange .size ());
458+ // Do the same for sdcUTC
459+ Result <Record11 <ULong , String , String , String , String , Date , String , String , Long , ULong , ULong >> hourRangeUTC = sdcUTC
460+ .getHourRange (earliestEpoch , latestOffset );
461+ Assertions .assertEquals (1 , hourRangeUTC .size ());
442462 // Assert that the resulting logfile metadata is as expected for logdate and logtime, they should not be affected by session timezone.
443463 ZonedDateTime zonedDateTimeUTC = ZonedDateTime .of (2023 , 10 , 5 , 1 , 0 , 0 , 0 , ZoneId .of ("UTC" ));
444464 Assertions .assertEquals (zonedDateTimeUTC .toEpochSecond (), hourRange .get (0 ).get (8 , Long .class ));
465+ Assertions .assertEquals (zonedDateTimeUTC .toEpochSecond (), hourRangeUTC .get (0 ).get (8 , Long .class ));
445466 Assertions .assertEquals (Date .valueOf ("2023-10-5" ), hourRange .get (0 ).get (5 , Date .class ));
467+ Assertions .assertEquals (Date .valueOf ("2023-10-5" ), hourRangeUTC .get (0 ).get (5 , Date .class ));
446468 }
447469
448470 @ Test
0 commit comments