github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/api/v1/validator_test.go (about)

     1  // Copyright 2021 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 v1
    15  
    16  import (
    17  	"context"
    18  	"testing"
    19  
    20  	"github.com/pingcap/tiflow/cdc/model"
    21  	"github.com/pingcap/tiflow/pkg/config"
    22  	"github.com/pingcap/tiflow/pkg/util"
    23  	"github.com/stretchr/testify/require"
    24  )
    25  
    26  func TestVerifyUpdateChangefeedConfig(t *testing.T) {
    27  	t.Parallel()
    28  	ctx := context.Background()
    29  	ctx, cancel := context.WithCancel(ctx)
    30  	defer cancel()
    31  	oldInfo := &model.ChangeFeedInfo{Config: config.GetDefaultReplicaConfig()}
    32  	// test startTs > targetTs
    33  	changefeedConfig := model.ChangefeedConfig{TargetTS: 20}
    34  	oldInfo.StartTs = 40
    35  	newInfo, err := VerifyUpdateChangefeedConfig(ctx, changefeedConfig, oldInfo)
    36  	require.NotNil(t, err)
    37  	require.Regexp(t, ".*can not update target-ts.*less than start-ts.*", err)
    38  	require.Nil(t, newInfo)
    39  
    40  	// test no change error
    41  	changefeedConfig = model.ChangefeedConfig{SinkURI: "blackhole://"}
    42  	oldInfo.SinkURI = "blackhole://"
    43  	oldInfo.Config.Sink.TxnAtomicity = util.AddressOf(config.AtomicityLevel("none"))
    44  	newInfo, err = VerifyUpdateChangefeedConfig(ctx, changefeedConfig, oldInfo)
    45  	require.NotNil(t, err)
    46  	require.Regexp(t, ".*changefeed config is the same with the old one.*", err)
    47  	require.Nil(t, newInfo)
    48  
    49  	// test verify success
    50  	changefeedConfig = model.ChangefeedConfig{MounterWorkerNum: 32}
    51  	newInfo, err = VerifyUpdateChangefeedConfig(ctx, changefeedConfig, oldInfo)
    52  	require.Nil(t, err)
    53  	require.NotNil(t, newInfo)
    54  	require.NotEqual(t, 0, newInfo.Epoch)
    55  }