-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added UUID generator selection through SPI for #2698
- Loading branch information
Julien Kronegg
committed
Mar 17, 2023
1 parent
291b8f8
commit 39e815d
Showing
80 changed files
with
1,320 additions
and
106 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
40 changes: 40 additions & 0 deletions
40
cucumber-core/src/main/java/io/cucumber/core/eventbus/IncrementingUuidGenerator.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,40 @@ | ||
package io.cucumber.core.eventbus; | ||
|
||
import io.cucumber.core.exception.CucumberException; | ||
|
||
import java.util.UUID; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Thread-safe and collision-free UUID generator for single JVM. This is a | ||
* sequence generator and each instance has its own counter. This generator is | ||
* about 100 times faster than #RandomUuidGenerator. If you use Cucumber in | ||
* multi-JVM setup, you should use #RandomUuidGenerator instead. Note that the | ||
* UUID version and variant is not guaranteed to be stable. | ||
*/ | ||
public class IncrementingUuidGenerator implements UuidGenerator { | ||
private static final AtomicLong sessionCounter = new AtomicLong(Long.MIN_VALUE); | ||
|
||
private final long sessionId; | ||
private final AtomicLong counter = new AtomicLong(Long.MIN_VALUE); | ||
|
||
public IncrementingUuidGenerator() { | ||
sessionId = sessionCounter.incrementAndGet(); | ||
} | ||
|
||
/** | ||
* Generate a new UUID. Will throw an exception when out of capacity. | ||
* | ||
* @return a non-null UUID | ||
* @throws CucumberException when out of capacity | ||
*/ | ||
@Override | ||
public UUID get() { | ||
long leastSigBits = counter.incrementAndGet(); | ||
if (leastSigBits == Long.MAX_VALUE) { | ||
throw new CucumberException( | ||
"Out of IncrementingUuidGenerator capacity. Please use the RandomUuidGenerator instead."); | ||
} | ||
return new UUID(sessionId, leastSigBits); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
cucumber-core/src/main/java/io/cucumber/core/eventbus/Options.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,7 @@ | ||
package io.cucumber.core.eventbus; | ||
|
||
public interface Options { | ||
|
||
Class<? extends UuidGenerator> getUuidGeneratorClass(); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
cucumber-core/src/main/java/io/cucumber/core/eventbus/RandomUuidGenerator.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,14 @@ | ||
package io.cucumber.core.eventbus; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* UUID generator based on random numbers. The generator is thread-safe and | ||
* supports multi-jvm usage of Cucumber. | ||
*/ | ||
public class RandomUuidGenerator implements UuidGenerator { | ||
@Override | ||
public UUID get() { | ||
return UUID.randomUUID(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
cucumber-core/src/main/java/io/cucumber/core/eventbus/UuidGenerator.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,13 @@ | ||
package io.cucumber.core.eventbus; | ||
|
||
import org.apiguardian.api.API; | ||
|
||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* SPI (Service Provider Interface) to generate UUIDs. | ||
*/ | ||
@API(status = API.Status.STABLE) | ||
public interface UuidGenerator extends Supplier<UUID> { | ||
} |
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
Oops, something went wrong.