github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/mock/mockid/mockid.go (about) 1 // Copyright 2019 TiKV Project Authors. 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 mockid 15 16 import "sync/atomic" 17 18 // IDAllocator mocks IDAllocator and it is only used for test. 19 type IDAllocator struct { 20 base uint64 21 } 22 23 // NewIDAllocator creates a new IDAllocator. 24 func NewIDAllocator() *IDAllocator { 25 return &IDAllocator{base: 0} 26 } 27 28 // Alloc returns a new id. 29 func (alloc *IDAllocator) Alloc() (uint64, error) { 30 return atomic.AddUint64(&alloc.base, 1), nil 31 } 32 33 // Rebase implements the IDAllocator interface. 34 func (alloc *IDAllocator) Rebase() error { 35 return nil 36 }