github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/model/kv_test.go (about) 1 // Copyright 2020 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 model 15 16 import ( 17 "testing" 18 19 "github.com/pingcap/tiflow/cdc/processor/tablepb" 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestRegionFeedEvent(t *testing.T) { 24 t.Parallel() 25 26 raw := &RawKVEntry{ 27 CRTs: 1, 28 OpType: OpTypePut, 29 } 30 resolved := &ResolvedSpans{ 31 Spans: []RegionComparableSpan{{ 32 Span: tablepb.Span{StartKey: []byte("a"), EndKey: []byte("b")}, 33 }}, ResolvedTs: 111, 34 } 35 36 ev := &RegionFeedEvent{} 37 require.Nil(t, ev.GetValue()) 38 39 ev = &RegionFeedEvent{Val: raw} 40 require.Equal(t, raw, ev.GetValue()) 41 42 ev = &RegionFeedEvent{Resolved: resolved} 43 require.Equal(t, resolved, ev.GetValue().(*ResolvedSpans)) 44 45 require.Equal(t, "span: [{{0 61 62} 0}], resolved-ts: 111", resolved.String()) 46 } 47 48 func TestRawKVEntry(t *testing.T) { 49 t.Parallel() 50 51 raw := &RawKVEntry{ 52 StartTs: 100, 53 CRTs: 101, 54 OpType: OpTypePut, 55 Key: []byte("123"), 56 Value: []byte("345"), 57 } 58 59 require.Equal(t, 60 "OpType: 1, Key: 123, Value: 345, OldValue: , StartTs: 100, CRTs: 101, RegionID: 0", 61 raw.String()) 62 require.Equal(t, int64(6), raw.ApproximateDataSize()) 63 }