github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/sink/dmlsink/mq/manager/pulsar_manager_test.go (about) 1 // Copyright 2023 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package manager 15 16 import ( 17 "context" 18 "net/url" 19 "testing" 20 21 "github.com/pingcap/tiflow/pkg/config" 22 pulsarConfig "github.com/pingcap/tiflow/pkg/sink/pulsar" 23 "github.com/stretchr/testify/require" 24 ) 25 26 func newPulsarConfig(t *testing.T) (*config.PulsarConfig, *url.URL) { 27 sinkURL := "pulsar://127.0.0.1:6650/persistent://public/default/test?" + 28 "protocol=canal-json&pulsar-version=v2.10.0&enable-tidb-extension=true&" + 29 "authentication-token=eyJhbGciOiJSUzIxxxxxxxxxxxxxxxx" 30 31 sinkURI, err := url.Parse(sinkURL) 32 require.NoError(t, err) 33 replicaConfig := config.GetDefaultReplicaConfig() 34 require.NoError(t, replicaConfig.ValidateAndAdjust(sinkURI)) 35 require.NoError(t, err) 36 c, err := pulsarConfig.NewPulsarConfig(sinkURI, replicaConfig.Sink.PulsarConfig) 37 require.NoError(t, err) 38 return c, sinkURI 39 } 40 41 func TestGetPartitionNumMock(t *testing.T) { 42 t.Parallel() 43 44 cfg, _ := newPulsarConfig(t) 45 46 replicaConfig := config.GetDefaultReplicaConfig() 47 replicaConfig.Sink = &config.SinkConfig{ 48 Protocol: str2Pointer("canal-json"), 49 } 50 51 ctx := context.Background() 52 53 ctx = context.WithValue(ctx, "testing.T", t) 54 pm, err := NewMockPulsarTopicManager(cfg, nil) 55 require.NoError(t, err) 56 require.NotNil(t, pm) 57 58 pn, err := pm.GetPartitionNum(ctx, "test") 59 require.NoError(t, err) 60 require.Equal(t, int32(3), pn) 61 }