Skip to content

Commit 57de302

Browse files
authored
Merge branch 'prb-its' into my-test
2 parents 715d5e6 + ce5bc30 commit 57de302

File tree

6 files changed

+206
-87
lines changed

6 files changed

+206
-87
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ jobs:
4747
run: which docker && docker ps
4848

4949
- name: Build with Maven
50-
run: mvn clean verify -fae -T 2 -B -V -DcloudBuild -Dmaven.wagon.http.retryHandler.count=3 -Dmaven.wagon
51-
.httpconnectionManager.ttlSeconds=25
50+
run: mvn clean verify -fae -T 2 -B -V -DcloudBuild -Dmaven.wagon.http.retryHandler.count=3
51+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=25
5252

5353
- name: Archive build artifacts
5454
uses: actions/upload-artifact@v3

mysql-delta-plugins/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<dependency>
5454
<groupId>mysql</groupId>
5555
<artifactId>mysql-connector-java</artifactId>
56-
<version>8.0.19</version>
56+
<version>8.0.28</version>
5757
<scope>test</scope>
5858
</dependency>
5959
</dependencies>

mysql-delta-plugins/src/test/java/io/cdap/delta/mysql/MySqlEventReaderIntegrationTest.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.cdap.delta.plugin.mock.BlockingEventEmitter;
3131
import io.cdap.delta.plugin.mock.MockContext;
3232
import io.cdap.delta.plugin.mock.MockEventEmitter;
33+
import org.junit.AfterClass;
3334
import org.junit.Assert;
3435
import org.junit.BeforeClass;
3536
import org.junit.Test;
@@ -41,6 +42,7 @@
4142
import java.sql.Date;
4243
import java.sql.DriverManager;
4344
import java.sql.PreparedStatement;
45+
import java.sql.SQLException;
4446
import java.sql.Statement;
4547
import java.time.LocalDate;
4648
import java.util.Collections;
@@ -57,7 +59,7 @@
5759
* are some classloading issues due to copied debezium classes.
5860
*/
5961
public class MySqlEventReaderIntegrationTest {
60-
private static final String DB = "test";
62+
private static final int CONSUMER_ID = 13;
6163
private static final String CUSTOMERS_TABLE = "customers";
6264
private static final Schema CUSTOMERS_SCHEMA = Schema.recordOf(
6365
"customers",
@@ -69,9 +71,14 @@ public class MySqlEventReaderIntegrationTest {
6971
BINARYCOL_TABLE,
7072
Schema.Field.of("id", Schema.of(Schema.Type.INT)),
7173
Schema.Field.of("bincol", Schema.of(Schema.Type.STRING)));
74+
private static final String HOST = "localhost";
75+
private static final String DB = "test";
76+
private static final String USER = "root";
7277

7378
private static String password;
7479
private static int port;
80+
private static Properties connProperties;
81+
private static String connectionUrl;
7582

7683

7784
@BeforeClass
@@ -84,10 +91,10 @@ public static void setupClass() throws Exception {
8491
}
8592
port = Integer.parseInt(properties.getProperty("mysql.port"));
8693

87-
Properties connProperties = new Properties();
88-
connProperties.put("user", "root");
94+
connProperties = new Properties();
95+
connProperties.put("user", USER);
8996
connProperties.put("password", password);
90-
String connectionUrl = String.format("jdbc:mysql://localhost:%d", port);
97+
connectionUrl = String.format("jdbc:mysql://localhost:%d", port);
9198
DriverManager.getDriver(connectionUrl);
9299

93100
// wait until a connection can be established
@@ -146,14 +153,24 @@ public static void setupClass() throws Exception {
146153
}
147154
}
148155

156+
@AfterClass
157+
public static void tearDown() throws SQLException {
158+
// drop database
159+
try (Connection connection = DriverManager.getConnection(connectionUrl, connProperties)) {
160+
try (Statement statement = connection.createStatement()) {
161+
statement.execute("DROP DATABASE " + DB);
162+
}
163+
}
164+
}
165+
149166
@Test
150167
public void test() throws InterruptedException {
151168
SourceTable sourceTable = new SourceTable(DB, CUSTOMERS_TABLE, null,
152169
Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
153170

154171
DeltaSourceContext context = new MockContext(Driver.class);
155-
MockEventEmitter eventEmitter = new MockEventEmitter(6);
156-
MySqlConfig config = new MySqlConfig("localhost", port, "root", password, 13, DB,
172+
MockEventEmitter eventEmitter = new MockEventEmitter(7);
173+
MySqlConfig config = new MySqlConfig(HOST, port, USER, password, CONSUMER_ID, DB,
157174
TimeZone.getDefault().getID());
158175

159176
MySqlEventReader eventReader = new MySqlEventReader(Collections.singleton(sourceTable), config,
@@ -164,7 +181,7 @@ public void test() throws InterruptedException {
164181
eventEmitter.waitForExpectedEvents(30, TimeUnit.SECONDS);
165182

166183
Assert.assertEquals(4, eventEmitter.getDdlEvents().size());
167-
Assert.assertEquals(2, eventEmitter.getDmlEvents().size());
184+
Assert.assertEquals(3, eventEmitter.getDmlEvents().size());
168185

169186
DDLEvent ddlEvent = eventEmitter.getDdlEvents().get(0);
170187
Assert.assertEquals(DDLOperation.Type.DROP_TABLE, ddlEvent.getOperation().getType());
@@ -184,14 +201,20 @@ public void test() throws InterruptedException {
184201
Assert.assertEquals(DB, ddlEvent.getOperation().getDatabaseName());
185202
Assert.assertEquals(CUSTOMERS_TABLE, ddlEvent.getOperation().getTableName());
186203
Assert.assertEquals(Collections.singletonList("id"), ddlEvent.getPrimaryKey());
204+
187205
Assert.assertEquals(CUSTOMERS_SCHEMA, ddlEvent.getSchema());
188206

189207
DMLEvent dmlEvent = eventEmitter.getDmlEvents().get(0);
190208
Assert.assertEquals(DMLOperation.Type.INSERT, dmlEvent.getOperation().getType());
191209
Assert.assertEquals(DB, dmlEvent.getOperation().getDatabaseName());
192210
Assert.assertEquals(CUSTOMERS_TABLE, dmlEvent.getOperation().getTableName());
193211
StructuredRecord row = dmlEvent.getRow();
194-
StructuredRecord expected = StructuredRecord.builder(CUSTOMERS_SCHEMA)
212+
213+
// Take schema name from the row as it is generated by debezium
214+
// so it can be different from the one in our schema but does not impact data
215+
Schema expectedSchema = Schema.recordOf(row.getSchema().getRecordName(), CUSTOMERS_SCHEMA.getFields());
216+
217+
StructuredRecord expected = StructuredRecord.builder(expectedSchema)
195218
.set("id", 0)
196219
.set("name", "alice")
197220
.setDate("bday", LocalDate.ofEpochDay(0))
@@ -203,7 +226,7 @@ public void test() throws InterruptedException {
203226
Assert.assertEquals(DB, dmlEvent.getOperation().getDatabaseName());
204227
Assert.assertEquals(CUSTOMERS_TABLE, dmlEvent.getOperation().getTableName());
205228
row = dmlEvent.getRow();
206-
expected = StructuredRecord.builder(CUSTOMERS_SCHEMA)
229+
expected = StructuredRecord.builder(expectedSchema)
207230
.set("id", 1)
208231
.set("name", "bob")
209232
.setDate("bday", LocalDate.ofEpochDay(365))
@@ -215,7 +238,7 @@ public void test() throws InterruptedException {
215238
Assert.assertEquals(DB, dmlEvent.getOperation().getDatabaseName());
216239
Assert.assertEquals(CUSTOMERS_TABLE, dmlEvent.getOperation().getTableName());
217240
row = dmlEvent.getRow();
218-
expected = StructuredRecord.builder(CUSTOMERS_SCHEMA)
241+
expected = StructuredRecord.builder(expectedSchema)
219242
.set("id", 2)
220243
.set("name", "tim")
221244
.setDate("bday", null)
@@ -232,7 +255,7 @@ public void stopReaderTest() throws Exception {
232255
BlockingQueue<DDLEvent> ddlEvents = new ArrayBlockingQueue<>(1);
233256
BlockingQueue<DMLEvent> dmlEvents = new ArrayBlockingQueue<>(1);
234257
EventEmitter eventEmitter = new BlockingEventEmitter(ddlEvents, dmlEvents);
235-
MySqlConfig config = new MySqlConfig("localhost", port, "root", password, 13, DB,
258+
MySqlConfig config = new MySqlConfig(HOST, port, USER, password, CONSUMER_ID, DB,
236259
TimeZone.getDefault().getID());
237260

238261
MySqlEventReader eventReader = new MySqlEventReader(Collections.singleton(sourceTable), config,
@@ -264,7 +287,7 @@ public void testBinaryHandlingModebyDebezium() throws InterruptedException {
264287
context.addRuntimeArgument(MySqlEventReader.SOURCE_CONNECTOR_PREFIX + "binary.handling.mode" , "HEX");
265288

266289
MockEventEmitter eventEmitter = new MockEventEmitter(4);
267-
MySqlConfig config = new MySqlConfig("localhost", port, "root", password, 13, DB,
290+
MySqlConfig config = new MySqlConfig(HOST, port, USER, password, CONSUMER_ID, DB,
268291
TimeZone.getDefault().getID());
269292

270293
MySqlEventReader eventReader = new MySqlEventReader(Collections.singleton(sourceTable), config,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
~ Copyright © 2022 Cask Data, Inc.
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License"); you may not
7+
~ use this file except in compliance with the License. You may obtain a copy of
8+
~ the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15+
~ License for the specific language governing permissions and limitations under
16+
~ the License.
17+
-->
18+
19+
<configuration>
20+
21+
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
22+
<encoder>
23+
<pattern>%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n</pattern>
24+
</encoder>
25+
</appender>
26+
27+
<logger name="io.debezium.connector" level="WARN">
28+
<appender-ref ref="Console"/>
29+
</logger>
30+
31+
<root level="INFO">
32+
<appender-ref ref="Console"/>
33+
</root>
34+
35+
</configuration>

0 commit comments

Comments
 (0)