-
Notifications
You must be signed in to change notification settings - Fork 45
Introduce support for liveness check for MySQL CDC listener #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
b0fe0a3
3a876db
0b66553
25f88ab
5ebaf93
c84cee2
439ed64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,21 +19,21 @@ import ballerinax/cdc; | |
| public isolated class CdcListener { | ||
| *cdc:Listener; | ||
|
|
||
| private final map<string> & readonly config; | ||
| private final map<anydata> & readonly config; | ||
| private boolean isStarted = false; | ||
| private boolean hasAttachedService = false; | ||
|
Comment on lines
+22
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Search for usages of isStarted and hasAttachedService in .bal files
rg -n 'isStarted|hasAttachedService' --type-add 'bal:*.bal' --type balRepository: ballerina-platform/module-ballerinax-mysql Length of output: 232 Remove unused fields These fields are declared at lines 23-24 but never used anywhere in the codebase. No assignments or references to these fields exist outside of their initial declarations, indicating they are dead code and should be removed. 🤖 Prompt for AI Agents |
||
|
|
||
| # Initializes the MySQL listener with the given configuration. | ||
| # | ||
| # + config - The configuration for the MySQL connector | ||
| public isolated function init(*MySqlListenerConfiguration config) { | ||
| map<string> configMap = {}; | ||
| map<string> debeziumConfigs = {}; | ||
| cdc:populateDebeziumProperties({ | ||
| engineName: config.engineName, | ||
| offsetStorage: config.offsetStorage, | ||
| internalSchemaStorage: config.internalSchemaStorage, | ||
| options: config.options | ||
| }, configMap); | ||
| }, debeziumConfigs); | ||
| cdc:populateDatabaseConfigurations({ | ||
| connectorClass: config.database.connectorClass, | ||
| hostname: config.database.hostname, | ||
|
|
@@ -47,9 +47,13 @@ public isolated class CdcListener { | |
| excludedTables: config.database.excludedTables, | ||
| includedColumns: config.database.includedColumns, | ||
| excludedColumns: config.database.excludedColumns | ||
| }, configMap); | ||
| populateMySqlConfigurations(config.database, configMap); | ||
| self.config = configMap.cloneReadOnly(); | ||
| }, debeziumConfigs); | ||
| populateMySqlConfigurations(config.database, debeziumConfigs); | ||
| map<anydata> listenerConfigs = { | ||
| ...debeziumConfigs | ||
| }; | ||
| listenerConfigs["livenessInterval"] = config.livenessInterval; | ||
| self.config = listenerConfigs.cloneReadOnly(); | ||
| } | ||
|
|
||
| # Attaches a CDC service to the MySQL listener. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| // | ||
| // WSO2 LLC. licenses this file to you under the Apache License, | ||
| // Version 2.0 (the "License"); you may not use this file except | ||
| // in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| import ballerina/lang.runtime; | ||
| import ballerina/test; | ||
| import ballerinax/cdc; | ||
|
|
||
| @test:Config { | ||
| groups: ["liveness"] | ||
| } | ||
| function testLivenessBeforeListenerStart() returns error? { | ||
| CdcListener mysqlListener = new ({ | ||
| database: { | ||
| username: cdcUsername, | ||
| password: cdcPassword, | ||
| port | ||
| }, | ||
| options: { | ||
| snapshotMode: cdc:NO_DATA | ||
| } | ||
| }); | ||
| check mysqlListener.attach(testService); | ||
| boolean liveness = check cdc:isLive(mysqlListener); | ||
| test:assertFalse(liveness, "Liveness check passes even before listener starts"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| groups: ["liveness"] | ||
| } | ||
| function testLivenessWithStartedListener() returns error? { | ||
| CdcListener mysqlListener = new ({ | ||
| database: { | ||
| username: cdcUsername, | ||
| password: cdcPassword, | ||
| port | ||
| }, | ||
| options: { | ||
| snapshotMode: cdc:NO_DATA | ||
| } | ||
| }); | ||
| check mysqlListener.attach(testService); | ||
| check mysqlListener.'start(); | ||
| boolean liveness = check cdc:isLive(mysqlListener); | ||
| test:assertTrue(liveness, "Liveness fails for a started listener"); | ||
| check mysqlListener.gracefulStop(); | ||
| } | ||
|
|
||
| @test:Config { | ||
| groups: ["liveness"] | ||
| } | ||
| function testLivenessAfterListenerStop() returns error? { | ||
| CdcListener mysqlListener = new ({ | ||
| database: { | ||
| username: cdcUsername, | ||
| password: cdcPassword, | ||
| port | ||
| }, | ||
| options: { | ||
| snapshotMode: cdc:NO_DATA | ||
| } | ||
| }); | ||
| check mysqlListener.attach(testService); | ||
| check mysqlListener.'start(); | ||
| check mysqlListener.gracefulStop(); | ||
| boolean liveness = check cdc:isLive(mysqlListener); | ||
| test:assertFalse(liveness, "Liveness check passes after the listener has stopped"); | ||
| } | ||
|
|
||
| @test:Config { | ||
| groups: ["liveness"] | ||
| } | ||
| function testLivenessWithoutReceivingEvents() returns error? { | ||
| CdcListener mysqlListener = new ({ | ||
| database: { | ||
| username: cdcUsername, | ||
| password: cdcPassword, | ||
| port | ||
| }, | ||
| options: { | ||
| snapshotMode: cdc:NO_DATA | ||
| }, | ||
| livenessInterval: 5.0 | ||
| }); | ||
| check mysqlListener.attach(testService); | ||
| check mysqlListener.'start(); | ||
| runtime:sleep(10); | ||
| boolean liveness = check cdc:isLive(mysqlListener); | ||
| test:assertFalse(liveness, "Liveness check passes even after not receiving events within the liveness interval"); | ||
| check mysqlListener.gracefulStop(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ballerina-platform/module-ballerinax-mysql
Length of output: 4933
Version misalignments detected between gradle.properties and Dependencies.toml.
All stdlib module versions in Dependencies.toml exceed those specified in gradle.properties:
Additionally, observe (1.5.1) appears in Dependencies.toml but has no corresponding entry in gradle.properties. The mysql module is correctly aligned at 1.16.2 in both files. Update gradle.properties to match Dependencies.toml versions to prevent build conflicts.
🤖 Prompt for AI Agents