|
27 | 27 |
|
28 | 28 | import java.sql.Connection; |
29 | 29 | import java.sql.DriverManager; |
| 30 | +import java.sql.ResultSet; |
30 | 31 | import java.sql.SQLException; |
31 | 32 | import java.sql.Statement; |
32 | 33 | import java.util.stream.Stream; |
@@ -65,14 +66,15 @@ public class DebeziumIT { |
65 | 66 | .withCopyFileToContainer(MountableFile.forHostPath(connectorJarResolver.getJarPath()), "/kafka/connect/questdb-connector/questdb-connector.jar") |
66 | 67 | .withCopyFileToContainer(MountableFile.forHostPath(questdbJarResolver.getJarPath()), "/kafka/connect/questdb-connector/questdb.jar") |
67 | 68 | .dependsOn(kafkaContainer) |
| 69 | +// .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("debezium"))) |
68 | 70 | .withEnv("CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE", "true") |
69 | 71 | .withEnv("CONNECT_VALUE_CONVERTER_SCHEMAS_ENABLE", "true"); |
70 | 72 |
|
71 | 73 | @Container |
72 | 74 | private static final GenericContainer<?> questDBContainer = new GenericContainer<>("questdb/questdb:6.5.3") |
73 | 75 | .withNetwork(network) |
74 | 76 | .withExposedPorts(QuestDBUtils.QUESTDB_HTTP_PORT) |
75 | | - .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("questdb"))) |
| 77 | +// .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger("questdb"))) |
76 | 78 | .withEnv("QDB_CAIRO_COMMIT_LAG", "100") |
77 | 79 | .withEnv("JAVA_OPTS", "-Djava.locale.providers=JRE,SPI"); |
78 | 80 |
|
@@ -160,6 +162,104 @@ public void testSchemaChange() throws Exception { |
160 | 162 | } |
161 | 163 | } |
162 | 164 |
|
| 165 | + @Test |
| 166 | + public void testUpdatesChange() throws Exception { |
| 167 | + String questTableName = "test_updates_change"; |
| 168 | + try (Connection connection = getConnection(postgresContainer); |
| 169 | + Statement statement = connection.createStatement()) { |
| 170 | + |
| 171 | + statement.execute("create schema " + PG_SCHEMA_NAME); |
| 172 | + statement.execute("create table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " (id int8 not null, title varchar(255), primary key (id))"); |
| 173 | + statement.execute("alter table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " replica identity full"); |
| 174 | + statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'Learn CDC')"); |
| 175 | + |
| 176 | + startDebeziumConnector(); |
| 177 | + ConnectorConfiguration questSink = newQuestSinkBaseConfig(questTableName); |
| 178 | + debeziumContainer.registerConnector(QUESTDB_CONNECTOR_NAME, questSink); |
| 179 | + |
| 180 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\"\r\n" |
| 181 | + + "1,\"Learn CDC\"\r\n", |
| 182 | + "select id, title from " + questTableName); |
| 183 | + |
| 184 | + statement.executeUpdate("update " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " set title = 'Learn Debezium' where id = 1"); |
| 185 | + |
| 186 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\"\r\n" |
| 187 | + + "1,\"Learn CDC\"\r\n" |
| 188 | + + "1,\"Learn Debezium\"\r\n", |
| 189 | + "select id, title from " + questTableName); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + public void testInsertThenDeleteThenInsertAgain() throws Exception { |
| 195 | + String questTableName = "test_insert_then_delete_then_insert_again"; |
| 196 | + try (Connection connection = getConnection(postgresContainer); |
| 197 | + Statement statement = connection.createStatement()) { |
| 198 | + |
| 199 | + statement.execute("create schema " + PG_SCHEMA_NAME); |
| 200 | + statement.execute("create table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " (id int8 not null, title varchar(255), primary key (id))"); |
| 201 | + statement.execute("alter table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " replica identity full"); |
| 202 | + statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'Learn CDC')"); |
| 203 | + |
| 204 | + startDebeziumConnector(); |
| 205 | + ConnectorConfiguration questSink = newQuestSinkBaseConfig(questTableName); |
| 206 | + debeziumContainer.registerConnector(QUESTDB_CONNECTOR_NAME, questSink); |
| 207 | + |
| 208 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\"\r\n" |
| 209 | + + "1,\"Learn CDC\"\r\n", |
| 210 | + "select id, title from " + questTableName); |
| 211 | + |
| 212 | + statement.execute("delete from " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " where id = 1"); |
| 213 | + statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'Learn Debezium')"); |
| 214 | + |
| 215 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\"\r\n" |
| 216 | + + "1,\"Learn CDC\"\r\n" |
| 217 | + + "1,\"Learn Debezium\"\r\n", |
| 218 | + "select id, title from " + questTableName); |
| 219 | + } |
| 220 | + } |
| 221 | + |
| 222 | + @Test |
| 223 | + public void testEventTime() throws SQLException { |
| 224 | + String questTableName = "test_event_time"; |
| 225 | + try (Connection connection = getConnection(postgresContainer); |
| 226 | + Statement statement = connection.createStatement()) { |
| 227 | + |
| 228 | + statement.execute("create schema " + PG_SCHEMA_NAME); |
| 229 | + statement.execute("create table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " (id int8 not null, title varchar(255), created_at timestamp, primary key (id))"); |
| 230 | + statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'Learn CDC', '2021-01-02T01:02:03.456Z')"); |
| 231 | + |
| 232 | + startDebeziumConnector(); |
| 233 | + ConnectorConfiguration questSink = newQuestSinkBaseConfig(questTableName); |
| 234 | + questSink.with(QuestDBSinkConnectorConfig.DESIGNATED_TIMESTAMP_COLUMN_NAME_CONFIG, "created_at"); |
| 235 | + debeziumContainer.registerConnector(QUESTDB_CONNECTOR_NAME, questSink); |
| 236 | + |
| 237 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\",\"timestamp\"\r\n" |
| 238 | + + "1,\"Learn CDC\",\"2021-01-02T01:02:03.456000Z\"\r\n", |
| 239 | + "select id, title, timestamp from " + questTableName); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + @Test |
| 244 | + public void testNonDesignatedTimestamp() throws SQLException { |
| 245 | + String questTableName = "test_non_designated_timestamp"; |
| 246 | + try (Connection connection = getConnection(postgresContainer); |
| 247 | + Statement statement = connection.createStatement()) { |
| 248 | + |
| 249 | + statement.execute("create schema " + PG_SCHEMA_NAME); |
| 250 | + statement.execute("create table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " (id int8 not null, title varchar(255), created_at timestamp, primary key (id))"); |
| 251 | + statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'Learn CDC', '2021-01-02T01:02:03.456Z')"); |
| 252 | + |
| 253 | + startDebeziumConnector(); |
| 254 | + ConnectorConfiguration questSink = newQuestSinkBaseConfig(questTableName); |
| 255 | + debeziumContainer.registerConnector(QUESTDB_CONNECTOR_NAME, questSink); |
| 256 | + |
| 257 | + QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"title\",\"created_at\"\r\n" |
| 258 | + + "1,\"Learn CDC\",\"2021-01-02T01:02:03.456000Z\"\r\n", |
| 259 | + "select id, title, created_at from " + questTableName); |
| 260 | + } |
| 261 | + } |
| 262 | + |
163 | 263 | private static void startDebeziumConnector() { |
164 | 264 | ConnectorConfiguration connector = ConnectorConfiguration |
165 | 265 | .forJdbcContainer(postgresContainer) |
|
0 commit comments