-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize: improve UUIDGenerator using "history time" version of snowflake algorithm #3175
Merged
l81893521
merged 15 commits into
apache:develop
from
selfishlover:feature-optimized-snowfake
Dec 15, 2020
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0d796cb
optimize: improve UUIDGenerator using "history time" version of snowf…
2a77d19
optimize: fix style
7495451
Merge branch 'develop' into feature-optimized-snowfake
jsbxyyx c093777
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes d4d29b1
optimize: adjust line
selfishlover 4947d78
Merge remote-tracking branch 'origin/feature-optimized-snowfake' into…
selfishlover 4e4229b
optimize: fix style
selfishlover 8a0156d
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes f077b7c
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes bdedd88
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes 782f2a9
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes 2f9ff34
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes c642166
Merge branch 'develop' into feature-optimized-snowfake
funky-eyes c2d3c1a
Merge branch 'develop' into feature-optimized-snowfake
l81893521 456a442
append author
selfishlover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
46 changes: 46 additions & 0 deletions
46
common/src/test/java/io/seata/common/util/IdWorkerTest.java
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,46 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.seata.common.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class IdWorkerTest { | ||
|
||
@Test | ||
void testNegativeWorkerId() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new IdWorker(-1L); | ||
}, "should throw IllegalArgumentException when workerId is negative"); | ||
} | ||
|
||
@Test | ||
void testTooLargeWorkerId() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
new IdWorker(1024L); | ||
}, "should throw IllegalArgumentException when workerId is bigger than 1023"); | ||
} | ||
|
||
@Test | ||
void testNextId() { | ||
IdWorker worker = new IdWorker(null); | ||
long id1 = worker.nextId(); | ||
long id2 = worker.nextId(); | ||
assertEquals(1L, id2 - id1, "increment step should be 1"); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if currentWithSequence will never be negative number, I think use
is enought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentWithSequence could be a negative number(though it would be a long long time to reach this~). What ever, >>> and >> have the same speed for cpu.