Skip to content

Commit

Permalink
config (ticdc): Fix sink protocol can no specify by config file. (#6361
Browse files Browse the repository at this point in the history
…) (#7508)

close #6360, ref #7501
  • Loading branch information
ti-chi-bot authored Nov 4, 2022
1 parent 1572212 commit 9f3c1c8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/config/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,18 @@ func (s *SinkConfig) applyParameter(sinkURI *url.URL) error {
return cerror.ErrSinkURIInvalid.GenWithStackByArgs(errMsg)
}

s.Protocol = params.Get(ProtocolKey)
protocolFromURI := params.Get(ProtocolKey)
if protocolFromURI != "" {
if s.Protocol != "" {
log.Warn(
fmt.Sprintf("protocol is specified in both sink URI and config file"+
"the value in sink URI will be used"+
"protocol in sink URI:%s, protocol in config file:%s",
protocolFromURI, s.Protocol))
}
s.Protocol = protocolFromURI
}

// validate that protocol is compatible with the scheme
if IsMqScheme(sinkURI.Scheme) {
var protocol Protocol
Expand Down
35 changes: 35 additions & 0 deletions pkg/config/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,38 @@ func TestValidateApplyParameter(t *testing.T) {
}
}
}

func TestApplyParameter(t *testing.T) {
t.Parallel()
testCases := []struct {
sinkConfig *SinkConfig
sinkURI string
result string
}{
{
sinkConfig: &SinkConfig{
Protocol: "default",
},
sinkURI: "kafka://127.0.0.1:9092?protocol=whatever",
result: "whatever",
},
{
sinkConfig: &SinkConfig{},
sinkURI: "kafka://127.0.0.1:9092?protocol=default",
result: "default",
},
{
sinkConfig: &SinkConfig{
Protocol: "default",
},
sinkURI: "kafka://127.0.0.1:9092",
result: "default",
},
}
for _, c := range testCases {
parsedSinkURI, err := url.Parse(c.sinkURI)
require.Nil(t, err)
c.sinkConfig.applyParameter(parsedSinkURI)
require.Equal(t, c.result, c.sinkConfig.Protocol)
}
}

0 comments on commit 9f3c1c8

Please sign in to comment.