Skip to content

Commit 09af958

Browse files
authored
Fix BeamRowWrapperTest microsecond precision flake (#39287)
Use a deterministic microsecond-aligned Instant and assert the exact conversion so Java 21 clock precision cannot break test class initialization.
1 parent cccb649 commit 09af958

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

sdks/java/io/iceberg/src/test/java/org/apache/beam/sdk/io/iceberg/BeamRowWrapperTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public class BeamRowWrapperTest {
8585
Types.NestedField.required(1, "nested_int", Types.IntegerType.get()))),
8686
Types.NestedField.required(14, "pass_through_field", Types.IntegerType.get()));
8787
private static final UUID TEST_UUID = UUID.randomUUID();
88+
private static final Instant TEST_MICROS_INSTANT =
89+
Instant.ofEpochSecond(1_609_459_200L, 123_456_000);
8890
private static final Row NESTED_ROW = Row.withSchema(NESTED_BEAM_SCHEMA).addValue(999).build();
8991
private static final Row ROW =
9092
Row.withSchema(BEAM_SCHEMA)
@@ -99,7 +101,7 @@ public class BeamRowWrapperTest {
99101
.array(),
100102
new BigDecimal("123.45"),
101103
org.joda.time.Instant.now(),
102-
Instant.now(),
104+
TEST_MICROS_INSTANT,
103105
LocalDateTime.now(ZoneId.systemDefault()),
104106
LocalDate.now(ZoneId.systemDefault()),
105107
LocalTime.now(ZoneId.systemDefault()),
@@ -180,10 +182,7 @@ public void testDateTimeConversion() {
180182

181183
@Test
182184
public void testMicrosInstantLogicalTypeConversion() {
183-
Instant javaInstant = ROW.getLogicalTypeValue(7, Instant.class);
184-
long expectedMicrosInstant =
185-
TimeUnit.SECONDS.toMicros(javaInstant.getEpochSecond()) + javaInstant.getNano() / 1000;
186-
assertEquals(expectedMicrosInstant, (long) WRAPPER.get(7, Long.class));
185+
assertEquals(1_609_459_200_123_456L, (long) WRAPPER.get(7, Long.class));
187186
}
188187

189188
@Test

0 commit comments

Comments
 (0)