Skip to content

Commit 9942309

Browse files
committed
more realistic debezium test
also: switch to JDK11
1 parent ad3425f commit 9942309

File tree

3 files changed

+70
-6
lines changed

3 files changed

+70
-6
lines changed

connector/src/main/java/io/questdb/kafka/BufferingSender.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ final class BufferingSender implements Sender {
3131
private final List<CharSequence> stringValues = new ArrayList<>(DEFAULT_CAPACITY);
3232
private final List<CharSequence> symbolColumnNames = new ArrayList<>(DEFAULT_CAPACITY);
3333
private final List<CharSequence> symbolColumnValues = new ArrayList<>(DEFAULT_CAPACITY);
34-
35-
36-
private Set<CharSequence> symbolColumns = new HashSet<>();
34+
private final Set<CharSequence> symbolColumns = new HashSet<>();
3735

3836
BufferingSender(Sender sender, String symbolColumns) {
3937
this.sender = sender;

integration-tests/debezium/src/test/java/kafka/DebeziumIT.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.questdb.kafka.JarResolverExtension;
1111
import org.apache.kafka.connect.json.JsonConverter;
1212
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.Assertions;
1314
import org.junit.jupiter.api.BeforeAll;
1415
import org.junit.jupiter.api.Test;
1516
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -27,12 +28,15 @@
2728

2829
import java.sql.Connection;
2930
import java.sql.DriverManager;
31+
import java.sql.PreparedStatement;
3032
import java.sql.ResultSet;
3133
import java.sql.SQLException;
3234
import java.sql.Statement;
35+
import java.util.concurrent.ThreadLocalRandom;
3336
import java.util.stream.Stream;
3437

3538
import static org.hamcrest.MatcherAssert.assertThat;
39+
import static org.junit.Assert.assertEquals;
3640

3741
@Testcontainers
3842
public class DebeziumIT {
@@ -132,6 +136,68 @@ public void testSmoke() throws Exception {
132136
}
133137
}
134138

139+
@Test
140+
public void testManyUpdates() throws Exception {
141+
String questTableName = "test_many_updates";
142+
try (Connection connection = getConnection(postgresContainer);
143+
Statement statement = connection.createStatement()) {
144+
startDebeziumConnector();
145+
ConnectorConfiguration questSink = newQuestSinkBaseConfig(questTableName);
146+
questSink = questSink.with("transforms.unwrap.add.fields", "source.ts_ms")
147+
.with(QuestDBSinkConnectorConfig.DESIGNATED_TIMESTAMP_COLUMN_NAME_CONFIG, "__source_ts_ms");
148+
questSink.with(QuestDBSinkConnectorConfig.SYMBOL_COLUMNS_CONFIG, "symbol");
149+
debeziumContainer.registerConnector(QUESTDB_CONNECTOR_NAME, questSink);
150+
151+
statement.execute("create schema " + PG_SCHEMA_NAME);
152+
statement.execute("create table " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " (id int8 not null, symbol varchar(255), price double precision, primary key (id))");
153+
statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (0, 'TDB', 1.0)");
154+
statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (1, 'QDB', 1.0)");
155+
statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (2, 'IDB', 1.0)");
156+
statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (3, 'PDB', 1.0)");
157+
statement.execute("insert into " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " values (4, 'KDB', 1.0)");
158+
159+
QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"symbol\",\"price\"\r\n"
160+
+ "0,\"TDB\",1.0\r\n"
161+
+ "1,\"QDB\",1.0\r\n"
162+
+ "2,\"IDB\",1.0\r\n"
163+
+ "3,\"PDB\",1.0\r\n"
164+
+ "4,\"KDB\",1.0\r\n",
165+
"select id, symbol, price from " + questTableName);
166+
167+
try (PreparedStatement preparedStatement = connection.prepareStatement("update " + PG_SCHEMA_NAME + "." + PG_TABLE_NAME + " set price = ? where id = ?")) {
168+
//a bunch of updates
169+
for (int i = 0; i < 200_000; i++) {
170+
int id = ThreadLocalRandom.current().nextInt(5);
171+
double newPrice = ThreadLocalRandom.current().nextDouble(100);
172+
preparedStatement.setDouble(1, newPrice);
173+
preparedStatement.setInt(2, id);
174+
preparedStatement.addBatch();
175+
}
176+
preparedStatement.executeBatch();
177+
// set all prices to a known value, this will be useful in asserting the final state
178+
for (int i = 0; i < 5; i++) {
179+
preparedStatement.setDouble(1, 42.0);
180+
preparedStatement.setInt(2, i);
181+
Assertions.assertEquals(1, preparedStatement.executeUpdate());
182+
}
183+
}
184+
185+
// all symbols have the last well-known price
186+
QuestDBUtils.assertSqlEventually(questDBContainer, "\"id\",\"symbol\",\"last_price\"\r\n"
187+
+ "0,\"TDB\",42.0\r\n"
188+
+ "1,\"QDB\",42.0\r\n"
189+
+ "2,\"IDB\",42.0\r\n"
190+
+ "3,\"PDB\",42.0\r\n"
191+
+ "4,\"KDB\",42.0\r\n",
192+
"select id, symbol, last(price) as last_price from " + questTableName);
193+
194+
// total number of rows is equal to the number of updates / inserts
195+
QuestDBUtils.assertSqlEventually(questDBContainer, "\"count\"\r\n"
196+
+ "200010\r\n",
197+
"select count() from " + questTableName);
198+
}
199+
}
200+
135201
@Test
136202
public void testSchemaChange() throws Exception {
137203
String questTableName = "test_schema_change";

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
<properties>
1818
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19-
<maven.compiler.source>8</maven.compiler.source>
20-
<maven.compiler.target>8</maven.compiler.target>
19+
<maven.compiler.source>11</maven.compiler.source>
20+
<maven.compiler.target>11</maven.compiler.target>
2121
<kafka.scala.version>2.13</kafka.scala.version>
2222
<kafka.version>3.3.1</kafka.version>
2323
<junit.version>5.9.0</junit.version>
@@ -85,7 +85,7 @@
8585
<dependency>
8686
<groupId>org.questdb</groupId>
8787
<artifactId>questdb</artifactId>
88-
<version>6.5.2-jdk8</version>
88+
<version>6.5.3</version>
8989
</dependency>
9090
<dependency>
9191
<groupId>org.junit.jupiter</groupId>

0 commit comments

Comments
 (0)