|
98 | 98 | import java.util.regex.Pattern; |
99 | 99 |
|
100 | 100 | import static org.junit.Assert.assertEquals; |
| 101 | +import static org.junit.Assert.assertFalse; |
101 | 102 | import static org.junit.Assert.assertThrows; |
102 | 103 | import static org.junit.Assert.assertTrue; |
103 | 104 |
|
@@ -2460,5 +2461,37 @@ public void testProcedureIdentifierQuoting() |
2460 | 2461 | // A dotted name is rejected: schema and procedure are separate parameters, so a '.' in a single component is an ambiguous schema-qualified reference |
2461 | 2462 | assertThrows(IllegalArgumentException.class, () -> dialect.buildProcedureCall(core.getName(), "a.b", 0, false, false, scope)); |
2462 | 2463 | } |
| 2464 | + |
| 2465 | + // GH Issue #1223: Verify the server/database clock-skew arithmetic and warning threshold |
| 2466 | + @Test |
| 2467 | + public void testServerDatabaseTimeDifference() |
| 2468 | + { |
| 2469 | + LocalDateTime base = LocalDateTime.of(2026, 7, 6, 12, 0, 0); |
| 2470 | + |
| 2471 | + // Identical times: zero difference, no warning |
| 2472 | + ServerDatabaseTimeDifference equal = new ServerDatabaseTimeDifference(base, base); |
| 2473 | + assertEquals(0, equal.getSeconds()); |
| 2474 | + assertFalse(equal.exceedsWarningThreshold()); |
| 2475 | + |
| 2476 | + // Comfortably below the threshold: no warning |
| 2477 | + ServerDatabaseTimeDifference below = new ServerDatabaseTimeDifference(base, base.plusSeconds(5)); |
| 2478 | + assertEquals(5, below.getSeconds()); |
| 2479 | + assertFalse(below.exceedsWarningThreshold()); |
| 2480 | + |
| 2481 | + // Exactly at the threshold: no warning (comparison is strictly greater-than) |
| 2482 | + ServerDatabaseTimeDifference atThreshold = new ServerDatabaseTimeDifference(base, base.plusSeconds(TIME_DIFFERENCE_WARNING_SECONDS)); |
| 2483 | + assertEquals(TIME_DIFFERENCE_WARNING_SECONDS, atThreshold.getSeconds()); |
| 2484 | + assertFalse(atThreshold.exceedsWarningThreshold()); |
| 2485 | + |
| 2486 | + // Just past the threshold: warning |
| 2487 | + ServerDatabaseTimeDifference over = new ServerDatabaseTimeDifference(base, base.plusSeconds(TIME_DIFFERENCE_WARNING_SECONDS + 1)); |
| 2488 | + assertEquals(TIME_DIFFERENCE_WARNING_SECONDS + 1, over.getSeconds()); |
| 2489 | + assertTrue(over.exceedsWarningThreshold()); |
| 2490 | + |
| 2491 | + // Difference is absolute: database clock behind the web server is treated the same as ahead |
| 2492 | + ServerDatabaseTimeDifference behind = new ServerDatabaseTimeDifference(base, base.minusSeconds(TIME_DIFFERENCE_WARNING_SECONDS + 1)); |
| 2493 | + assertEquals(TIME_DIFFERENCE_WARNING_SECONDS + 1, behind.getSeconds()); |
| 2494 | + assertTrue(behind.exceedsWarningThreshold()); |
| 2495 | + } |
2463 | 2496 | } |
2464 | 2497 | } |
0 commit comments