-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
stream-loader-core/src/test/scala/com/adform/streamloader/util/UuidExtensionsTest.scala
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,32 @@ | ||
/* | ||
* Copyright (c) 2020 Adform | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.adform.streamloader.util | ||
|
||
import com.adform.streamloader.util.UuidExtensions.randomUUIDv7 | ||
import org.scalatest.funspec.AnyFunSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class UuidExtensionsTest extends AnyFunSpec with Matchers { | ||
|
||
it("should generate unique UUIDv7 values") { | ||
val uuids = (0 until 100).map(_ => randomUUIDv7()) | ||
uuids should contain theSameElementsInOrderAs uuids.distinct | ||
} | ||
|
||
it("should generate alphabetically sorted UUIDv7 values") { | ||
val uuids = (0 until 10) | ||
.map(_ => { | ||
randomUUIDv7() | ||
Thread.sleep(5) // the v7 spec guarantees ordering in a 1ms scope | ||
}) | ||
.map(_.toString) | ||
|
||
uuids should contain theSameElementsInOrderAs uuids.sorted | ||
} | ||
} |
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