github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/disttae/logtail_consumer_test.go (about) 1 // Copyright 2022 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 disttae 16 17 import ( 18 "github.com/stretchr/testify/require" 19 "testing" 20 ) 21 22 // should ensure that subscribe and unsubscribe methods are effective. 23 func TestSubscribedTable(t *testing.T) { 24 var subscribeRecord subscribedTable 25 26 subscribeRecord.m = make(map[SubTableID]SubTableStatus) 27 require.Equal(t, 0, len(subscribeRecord.m)) 28 29 tbls := []struct { 30 db uint64 31 tb uint64 32 }{ 33 {db: 0, tb: 1}, 34 {db: 0, tb: 2}, 35 {db: 0, tb: 3}, 36 {db: 0, tb: 4}, 37 {db: 0, tb: 1}, 38 } 39 for _, tbl := range tbls { 40 subscribeRecord.setTableSubscribe(tbl.db, tbl.tb) 41 } 42 require.Equal(t, 4, len(subscribeRecord.m)) 43 require.Equal(t, true, subscribeRecord.getTableSubscribe(tbls[0].db, tbls[0].tb)) 44 for _, tbl := range tbls { 45 subscribeRecord.setTableUnsubscribe(tbl.db, tbl.tb) 46 } 47 require.Equal(t, 0, len(subscribeRecord.m)) 48 }