mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: move int64Slice into pkg/types/
This commit is contained in:
parent
314d425718
commit
c15c3eab4c
@ -4,6 +4,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/coreos/etcd/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClusterAddSlice(t *testing.T) {
|
func TestClusterAddSlice(t *testing.T) {
|
||||||
@ -201,12 +203,6 @@ func TestClusterSetBad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type int64slice []int64
|
|
||||||
|
|
||||||
func (a int64slice) Len() int { return len(a) }
|
|
||||||
func (a int64slice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
||||||
func (a int64slice) Less(i, j int) bool { return a[i] < a[j] }
|
|
||||||
|
|
||||||
func TestClusterIDs(t *testing.T) {
|
func TestClusterIDs(t *testing.T) {
|
||||||
cs := Cluster{}
|
cs := Cluster{}
|
||||||
cs.AddSlice([]Member{
|
cs.AddSlice([]Member{
|
||||||
@ -214,8 +210,8 @@ func TestClusterIDs(t *testing.T) {
|
|||||||
{ID: 4},
|
{ID: 4},
|
||||||
{ID: 100},
|
{ID: 100},
|
||||||
})
|
})
|
||||||
w := int64slice([]int64{1, 4, 100})
|
w := types.Int64Slice([]int64{1, 4, 100})
|
||||||
g := int64slice(cs.IDs())
|
g := types.Int64Slice(cs.IDs())
|
||||||
sort.Sort(g)
|
sort.Sort(g)
|
||||||
if !reflect.DeepEqual(w, g) {
|
if !reflect.DeepEqual(w, g) {
|
||||||
t.Errorf("IDs=%+v, want %+v", g, w)
|
t.Errorf("IDs=%+v, want %+v", g, w)
|
||||||
|
@ -131,7 +131,7 @@ func NewServer(cfg *ServerConfig) *EtcdServer {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
ids := cfg.Cluster.IDs()
|
ids := cfg.Cluster.IDs()
|
||||||
sort.Sort(int64Slice(ids))
|
sort.Sort(types.Int64Slice(ids))
|
||||||
ccs := make([]raftpb.ConfChange, len(ids))
|
ccs := make([]raftpb.ConfChange, len(ids))
|
||||||
for i, id := range ids {
|
for i, id := range ids {
|
||||||
// TODO: add context for PeerURLs
|
// TODO: add context for PeerURLs
|
||||||
@ -560,10 +560,3 @@ func getBool(v *bool) (vv bool, set bool) {
|
|||||||
}
|
}
|
||||||
return *v, true
|
return *v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// int64Slice implements sort interface
|
|
||||||
type int64Slice []int64
|
|
||||||
|
|
||||||
func (p int64Slice) Len() int { return len(p) }
|
|
||||||
func (p int64Slice) Less(i, j int) bool { return p[i] < p[j] }
|
|
||||||
func (p int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
|
||||||
|
8
pkg/types/slice.go
Normal file
8
pkg/types/slice.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
// Int64Slice implements sort interface
|
||||||
|
type Int64Slice []int64
|
||||||
|
|
||||||
|
func (p Int64Slice) Len() int { return len(p) }
|
||||||
|
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
|
||||||
|
func (p Int64Slice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
|
Loading…
x
Reference in New Issue
Block a user