-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
an IDMaker that simply generate a sequence, which is useful for local mode.
- Loading branch information
1 parent
6d5a77e
commit 63c77d2
Showing
9 changed files
with
71 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dingo | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSeqIDMaker(t *testing.T) { | ||
ass := assert.New(t) | ||
|
||
// test overflow | ||
{ | ||
m := &SeqIDMaker{i: ^uint64(0)>>1 - 1} | ||
id, err := m.NewID() | ||
ass.Nil(err) | ||
ass.NotEqual("", id) | ||
|
||
id, err = m.NewID() | ||
ass.NotNil(err) | ||
ass.Equal("", id) | ||
} | ||
|
||
// test normal usaage | ||
{ | ||
m := &SeqIDMaker{} | ||
id1, err := m.NewID() | ||
ass.Nil(err) | ||
|
||
id2, err := m.NewID() | ||
ass.Nil(err) | ||
|
||
num1, err := strconv.Atoi(id1) | ||
ass.Nil(err) | ||
num2, err := strconv.Atoi(id2) | ||
ass.Nil(err) | ||
|
||
ass.Equal(1, num2-num1) | ||
} | ||
} |