|
62 | 62 | import org.junit.jupiter.api.AfterAll;
|
63 | 63 | import org.junit.jupiter.api.BeforeAll;
|
64 | 64 | import org.junit.jupiter.api.BeforeEach;
|
| 65 | +import org.junit.jupiter.api.DisplayName; |
65 | 66 | import org.junit.jupiter.api.Test;
|
66 | 67 | import org.junit.jupiter.api.extension.ExtendWith;
|
67 | 68 | import org.testcontainers.containers.PostgreSQLContainer;
|
@@ -852,4 +853,46 @@ public void testJdbcOptionsParameter() throws Exception {
|
852 | 853 | }
|
853 | 854 | }
|
854 | 855 |
|
| 856 | + @Test |
| 857 | + @DisplayName("Make sure initial incremental load is reading records in a certain order") |
| 858 | + void testReadIncrementalRecordOrder() throws Exception { |
| 859 | + final JsonNode config = getConfig(PSQL_DB, dbName); |
| 860 | + // We want to test ordering, so we can delete the NaN entry |
| 861 | + try (final DSLContext dslContext = getDslContext(config)) { |
| 862 | + final Database database = getDatabase(dslContext); |
| 863 | + database.query(ctx -> { |
| 864 | + ctx.fetch("DELETE FROM id_and_name WHERE id = 'NaN';"); |
| 865 | + for (int i = 3; i < 1000; i++) { |
| 866 | + ctx.fetch("INSERT INTO id_and_name (id, name, power) VALUES (%d, 'gohan%d', 222.1);".formatted(i, i)); |
| 867 | + } |
| 868 | + return null; |
| 869 | + }); |
| 870 | + |
| 871 | + final ConfiguredAirbyteCatalog configuredCatalog = |
| 872 | + CONFIGURED_INCR_CATALOG |
| 873 | + .withStreams(CONFIGURED_INCR_CATALOG.getStreams().stream().filter(s -> s.getStream().getName().equals(STREAM_NAME)).collect( |
| 874 | + Collectors.toList())); |
| 875 | + final PostgresSource source = new PostgresSource(); |
| 876 | + source.setStateEmissionFrequencyForDebug(1); |
| 877 | + final List<AirbyteMessage> actualMessages = MoreIterators.toList(source.read(getConfig(PSQL_DB, dbName), configuredCatalog, null)); |
| 878 | + setEmittedAtToNull(actualMessages); |
| 879 | + |
| 880 | + // final List<AirbyteStateMessage> stateAfterFirstBatch = extractStateMessage(actualMessages); |
| 881 | + |
| 882 | + setEmittedAtToNull(actualMessages); |
| 883 | + |
| 884 | + final Set<AirbyteMessage> expectedOutput = Sets.newHashSet( |
| 885 | + createRecord(STREAM_NAME, SCHEMA_NAME, map("id", new BigDecimal("1.0"), "name", "goku", "power", null)), |
| 886 | + createRecord(STREAM_NAME, SCHEMA_NAME, map("id", new BigDecimal("2.0"), "name", "vegeta", "power", 9000.1))); |
| 887 | + for (int i = 3; i < 1000; i++) { |
| 888 | + expectedOutput.add( |
| 889 | + createRecord(STREAM_NAME, SCHEMA_NAME, map("id", new BigDecimal("%d.0".formatted(i)), "name", "gohan%d".formatted(i), "power", 222.1))); |
| 890 | + } |
| 891 | + assertThat(actualMessages.contains(expectedOutput)); |
| 892 | + // Assert that the Postgres source is emitting records & state messages in the correct order. |
| 893 | + assertCorrectRecordOrderForIncrementalSync(actualMessages, "id", JsonSchemaPrimitive.NUMBER, configuredCatalog, |
| 894 | + new AirbyteStreamNameNamespacePair("id_and_name", "public")); |
| 895 | + } |
| 896 | + } |
| 897 | + |
855 | 898 | }
|
0 commit comments