github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/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  	"github.com/pingcap/check"
    18  	"github.com/pingcap/ticdc/pkg/regionspan"
    19  	"github.com/pingcap/ticdc/pkg/util/testleak"
    20  )
    21  
    22  type kvSuite struct{}
    23  
    24  var _ = check.Suite(&kvSuite{})
    25  
    26  func (s *kvSuite) TestRegionFeedEvent(c *check.C) {
    27  	defer testleak.AfterTest(c)()
    28  	raw := &RawKVEntry{
    29  		CRTs:   1,
    30  		OpType: OpTypePut,
    31  	}
    32  	resolved := &ResolvedSpan{
    33  		Span:       regionspan.ComparableSpan{Start: []byte("a"), End: []byte("b")},
    34  		ResolvedTs: 111,
    35  	}
    36  
    37  	ev := &RegionFeedEvent{}
    38  	c.Assert(ev.GetValue(), check.IsNil)
    39  
    40  	ev = &RegionFeedEvent{Val: raw}
    41  	c.Assert(ev.GetValue(), check.DeepEquals, raw)
    42  
    43  	ev = &RegionFeedEvent{Resolved: resolved}
    44  	c.Assert(ev.GetValue(), check.DeepEquals, resolved)
    45  
    46  	c.Assert(resolved.String(), check.Equals, "span: [61, 62), resolved-ts: 111")
    47  }
    48  
    49  func (s *kvSuite) TestRawKVEntry(c *check.C) {
    50  	defer testleak.AfterTest(c)()
    51  	raw := &RawKVEntry{
    52  		StartTs: 100,
    53  		CRTs:    101,
    54  		OpType:  OpTypePut,
    55  		Key:     []byte("123"),
    56  		Value:   []byte("345"),
    57  	}
    58  
    59  	c.Assert(raw.String(), check.Equals,
    60  		"OpType: 1, Key: 123, Value: 345, OldValue: , StartTs: 100, CRTs: 101, RegionID: 0")
    61  	c.Assert(raw.ApproximateSize(), check.Equals, int64(6))
    62  }