-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changefeed (ticdc): fix mysql sink config contains protocol error (#6896
- Loading branch information
1 parent
834e6c8
commit 8201ed9
Showing
4 changed files
with
211 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -564,13 +564,12 @@ func TestFixState(t *testing.T) { | |
} | ||
} | ||
|
||
func TestFixSinkProtocol(t *testing.T) { | ||
func TestFixMysqlSinkProtocol(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Test fixing the protocol in the configuration. | ||
configTestCases := []struct { | ||
info *ChangeFeedInfo | ||
expectedProtocol config.Protocol | ||
expectedProtocol string | ||
}{ | ||
{ | ||
info: &ChangeFeedInfo{ | ||
|
@@ -579,8 +578,62 @@ func TestFixSinkProtocol(t *testing.T) { | |
Sink: &config.SinkConfig{Protocol: config.ProtocolDefault.String()}, | ||
}, | ||
}, | ||
expectedProtocol: config.ProtocolOpen, | ||
expectedProtocol: "", | ||
}, | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "mysql://root:[email protected]:3306/", | ||
Config: &config.ReplicaConfig{ | ||
Sink: &config.SinkConfig{Protocol: "whatever"}, | ||
}, | ||
}, | ||
expectedProtocol: "", | ||
}, | ||
} | ||
|
||
for _, tc := range configTestCases { | ||
tc.info.fixMySQLSinkProtocol() | ||
require.Equal(t, tc.expectedProtocol, tc.info.Config.Sink.Protocol) | ||
} | ||
|
||
sinkURITestCases := []struct { | ||
info *ChangeFeedInfo | ||
expectedSinkURI string | ||
}{ | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "mysql://root:[email protected]:3306/?protocol=open-protocol", | ||
Config: &config.ReplicaConfig{ | ||
Sink: &config.SinkConfig{Protocol: config.ProtocolDefault.String()}, | ||
}, | ||
}, | ||
expectedSinkURI: "mysql://root:[email protected]:3306/", | ||
}, | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "mysql://root:[email protected]:3306/?protocol=default", | ||
Config: &config.ReplicaConfig{ | ||
Sink: &config.SinkConfig{Protocol: ""}, | ||
}, | ||
}, | ||
expectedSinkURI: "mysql://root:[email protected]:3306/", | ||
}, | ||
} | ||
|
||
for _, tc := range sinkURITestCases { | ||
tc.info.fixMySQLSinkProtocol() | ||
require.Equal(t, tc.expectedSinkURI, tc.info.SinkURI) | ||
} | ||
} | ||
|
||
func TestFixMQSinkProtocol(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Test fixing the protocol in the configuration. | ||
configTestCases := []struct { | ||
info *ChangeFeedInfo | ||
expectedProtocol config.Protocol | ||
}{ | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "kafka://127.0.0.1:9092/ticdc-test2", | ||
|
@@ -611,32 +664,18 @@ func TestFixSinkProtocol(t *testing.T) { | |
} | ||
|
||
for _, tc := range configTestCases { | ||
tc.info.fixSinkProtocol() | ||
tc.info.fixMQSinkProtocol() | ||
var protocol config.Protocol | ||
err := protocol.FromString(tc.info.Config.Sink.Protocol) | ||
if strings.Contains(tc.info.SinkURI, "kafka") { | ||
require.Nil(t, err) | ||
require.Equal(t, tc.expectedProtocol, protocol) | ||
} else { | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "ErrMQSinkUnknownProtocol") | ||
} | ||
require.Nil(t, err) | ||
require.Equal(t, tc.expectedProtocol, protocol) | ||
} | ||
|
||
// Test fixing the protocol in SinkURI. | ||
sinkURITestCases := []struct { | ||
info *ChangeFeedInfo | ||
expectedSinkURI string | ||
}{ | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "mysql://root:[email protected]:3306/", | ||
Config: &config.ReplicaConfig{ | ||
Sink: &config.SinkConfig{Protocol: config.ProtocolDefault.String()}, | ||
}, | ||
}, | ||
expectedSinkURI: "mysql://root:[email protected]:3306/", | ||
}, | ||
{ | ||
info: &ChangeFeedInfo{ | ||
SinkURI: "kafka://127.0.0.1:9092/ticdc-test2", | ||
|
@@ -685,7 +724,7 @@ func TestFixSinkProtocol(t *testing.T) { | |
} | ||
|
||
for _, tc := range sinkURITestCases { | ||
tc.info.fixSinkProtocol() | ||
tc.info.fixMQSinkProtocol() | ||
require.Equal(t, tc.expectedSinkURI, tc.info.SinkURI) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters