Skip to content

Commit 2d0a6f6

Browse files
committed
MSSQL Datetime2 and Time tests fixes
Make sure the number of significant digits matches the column precision. So that the tests work with any Java version. Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
1 parent ebb3eb1 commit 2d0a6f6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

vertx-mssql-client/src/test/java/io/vertx/mssqlclient/data/MSSQLPreparedQueryNotNullableDataTypeTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public void testEncodeDate(TestContext ctx) {
121121
@Test
122122
@Repeat(100)
123123
public void testEncodeTime(TestContext ctx) {
124-
LocalTime now = LocalTime.now();
124+
// Make sure the number of significant digits matches the column precision
125+
int nanoOfSecond = 1_000 * ThreadLocalRandom.current().nextInt(1_000_000);
126+
LocalTime now = LocalTime.now().withNano(nanoOfSecond);
125127
testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_time", now, row -> {
126128
ColumnChecker.checkColumn(0, "test_time")
127129
.returns(Tuple::getValue, Row::getValue, now)
@@ -180,7 +182,9 @@ public void testEncodeDateTime(TestContext ctx) {
180182
@Test
181183
@Repeat(100)
182184
public void testEncodeDateTime2(TestContext ctx) {
183-
LocalDateTime now = LocalDateTime.now();
185+
// Make sure the number of significant digits matches the column precision
186+
int nanoOfSecond = 100 * ThreadLocalRandom.current().nextInt(10_000_000);
187+
LocalDateTime now = LocalDateTime.now().withNano(nanoOfSecond);
184188
testPreparedQueryEncodeGeneric(ctx, "not_nullable_datatype", "test_datetime2", now, row -> {
185189
ColumnChecker.checkColumn(0, "test_datetime2")
186190
.returns(Tuple::getValue, Row::getValue, now)
@@ -195,14 +199,7 @@ public void testEncodeDateTime2(TestContext ctx) {
195199
@Test
196200
@Repeat(100)
197201
public void testEncodeOffsetDateTime(TestContext ctx) {
198-
/*
199-
Starting from Java 11, LocalDateTime.now() can have microseconds precision.
200-
But the test database defines the test_datetimeoffset column with scale of 5.
201-
202-
Therefore, in order to get consistent behavior between Java 8 and Java 11,
203-
we erase the nanoOfSecond value obtained from the clock with a random number
204-
which has at most tens of microseconds precision.
205-
*/
202+
// Make sure the number of significant digits matches the column precision
206203
int nanoOfSecond = ThreadLocalRandom.current().nextInt(100_000) * 10_000;
207204
OffsetDateTime now = LocalDateTime.now().withNano(nanoOfSecond)
208205
.atOffset(ZoneOffset.ofHoursMinutes(-3, -15));

0 commit comments

Comments
 (0)