From 217d7dc37780e72ad78b1885e6fb27f5d01141a1 Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 23 Jun 2022 21:22:05 -0700 Subject: [PATCH] verify seq is always unique --- weed/sequence/snowflake_sequencer_test.go | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 weed/sequence/snowflake_sequencer_test.go diff --git a/weed/sequence/snowflake_sequencer_test.go b/weed/sequence/snowflake_sequencer_test.go new file mode 100644 index 000000000..731e330c5 --- /dev/null +++ b/weed/sequence/snowflake_sequencer_test.go @@ -0,0 +1,25 @@ +package sequence + +import ( + "encoding/hex" + "github.com/chrislusf/seaweedfs/weed/storage/types" + "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 + } + +}