2022-06-24 04:22:05 +00:00
|
|
|
package sequence
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
2022-06-24 04:22:05 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSequencer(t *testing.T) {
|
|
|
|
seq, err := NewSnowflakeSequencer("for_test", 1)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
last := uint64(0)
|
|
|
|
bytes := make([]byte, types.NeedleIdSize)
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
next := seq.NextFileId(1)
|
|
|
|
types.NeedleIdToBytes(bytes, types.NeedleId(next))
|
|
|
|
println(hex.EncodeToString(bytes))
|
|
|
|
if last == next {
|
|
|
|
t.Errorf("last %d next %d", last, next)
|
|
|
|
}
|
|
|
|
last = next
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|