github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/service/server_test.go (about)

     1  // Copyright 2021 Matrix Origin
     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  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package service
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/pb/api"
    21  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestTableID(t *testing.T) {
    26  	type testCase struct {
    27  		ta       api.TableID
    28  		tb       api.TableID
    29  		evaluate func(t require.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{})
    30  	}
    31  
    32  	cases := []testCase{
    33  		{
    34  			ta:       mockTable(1, 1, 1),
    35  			tb:       mockTable(1, 1, 1),
    36  			evaluate: require.Equal,
    37  		},
    38  		{
    39  			ta:       mockTable(1, 1, 1),
    40  			tb:       mockTable(2, 1, 1),
    41  			evaluate: require.NotEqual,
    42  		},
    43  		{
    44  			ta:       mockTable(1, 1, 1),
    45  			tb:       mockTable(1, 2, 1),
    46  			evaluate: require.NotEqual,
    47  		},
    48  		{
    49  			ta:       mockTable(1, 1, 1),
    50  			tb:       mockTable(1, 1, 2),
    51  			evaluate: require.NotEqual,
    52  		},
    53  	}
    54  
    55  	for _, c := range cases {
    56  		taID := TableID(c.ta.String())
    57  		tbID := TableID(c.tb.String())
    58  		c.evaluate(t, taID, tbID)
    59  	}
    60  }
    61  
    62  func mockTable(dbID, tbID, ptID uint64) api.TableID {
    63  	return api.TableID{
    64  		DbId:        dbID,
    65  		TbId:        tbID,
    66  		PartitionId: ptID,
    67  	}
    68  }
    69  
    70  func mockTimestamp(physical int64, logical uint32) timestamp.Timestamp {
    71  	return timestamp.Timestamp{
    72  		PhysicalTime: physical,
    73  		LogicalTime:  logical,
    74  	}
    75  }