Update ID generator according to platform.ID

pull/10616/head
Leonardo Di Donato 2018-07-24 12:04:09 +02:00 committed by Leonardo Di Donato
parent 09b7a4138f
commit 26cd66f165
2 changed files with 3 additions and 9 deletions

View File

@ -1,7 +1,6 @@
package snowflake
import (
"encoding/binary"
"math/rand"
"time"
@ -9,8 +8,6 @@ import (
"github.com/influxdata/platform"
)
// TODO: rename to id.go
func init() {
rand.Seed(time.Now().UnixNano())
}
@ -27,8 +24,5 @@ func NewIDGenerator() *IDGenerator {
}
func (g *IDGenerator) ID() platform.ID {
id := make(platform.ID, 8)
i := g.Generator.Next()
binary.BigEndian.PutUint64(id, i)
return id
return platform.ID(g.Generator.Next())
}

View File

@ -10,7 +10,7 @@ import (
func TestIDLength(t *testing.T) {
gen := NewIDGenerator()
id := gen.ID()
if len(id) != 8 {
if len(id.Encode()) != 16 {
t.Fail()
}
}
@ -21,7 +21,7 @@ func TestToFromString(t *testing.T) {
var clone platform.ID
if err := clone.DecodeFromString(id.String()); err != nil {
t.Error(err)
} else if !bytes.Equal(id, clone) {
} else if !bytes.Equal(id.Encode(), clone.Encode()) {
t.Errorf("id started as %x but got back %x", id, clone)
}
}