github.com/matrixorigin/matrixone@v1.2.0/pkg/util/status/hakeeper_test.go (about) 1 // Copyright 2021 -2023 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 status 16 17 import ( 18 "context" 19 "testing" 20 21 pb "github.com/matrixorigin/matrixone/pkg/pb/logservice" 22 "github.com/stretchr/testify/assert" 23 ) 24 25 type mockHAKeeperClient struct { 26 details pb.ClusterDetails 27 } 28 29 func (c *mockHAKeeperClient) Close() error { 30 return nil 31 } 32 33 func (c *mockHAKeeperClient) AllocateID(ctx context.Context) (uint64, error) { 34 return 0, nil 35 } 36 37 func (c *mockHAKeeperClient) AllocateIDByKey(ctx context.Context, key string) (uint64, error) { 38 return 0, nil 39 } 40 41 func (c *mockHAKeeperClient) AllocateIDByKeyWithBatch(ctx context.Context, key string, batch uint64) (uint64, error) { 42 return 0, nil 43 } 44 45 func (c *mockHAKeeperClient) GetClusterDetails(ctx context.Context) (pb.ClusterDetails, error) { 46 return c.details, nil 47 } 48 49 func (c *mockHAKeeperClient) GetClusterState(ctx context.Context) (pb.CheckerState, error) { 50 return pb.CheckerState{}, nil 51 } 52 53 func (c *mockHAKeeperClient) addCNStore() { 54 c.details.CNStores = append(c.details.CNStores, pb.CNStore{ 55 SQLAddress: "127.0.0.1:8000", 56 }) 57 } 58 59 func (c *mockHAKeeperClient) addDeletedCNStore() { 60 c.details.DeletedStores = append(c.details.DeletedStores, pb.DeletedStore{}) 61 } 62 63 func TestFillHAKeeper(t *testing.T) { 64 var status Status 65 var client mockHAKeeperClient 66 for i := 0; i < 10; i++ { 67 client.addCNStore() 68 client.addDeletedCNStore() 69 } 70 status.HAKeeperStatus.fill(&client) 71 assert.Equal(t, 10, len(status.HAKeeperStatus.Nodes)) 72 assert.Equal(t, 10, len(status.HAKeeperStatus.DeletedNodes)) 73 }