mirror of
https://github.com/valitydev/adapter-flow-lib.git
synced 2024-11-06 00:05:22 +00:00
Add local id gen (#72)
This commit is contained in:
parent
94418ab4ea
commit
21442408e5
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>adapter-flow-lib</artifactId>
|
<artifactId>adapter-flow-lib</artifactId>
|
||||||
<version>0.2.1</version>
|
<version>0.2.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>adapter-flow-lib</name>
|
<name>adapter-flow-lib</name>
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package dev.vality.adapter.flow.lib.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LocalIdGenerator implements IdGenerator {
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
@Override
|
||||||
|
public Long get(String invoiceId) {
|
||||||
|
return UUID.nameUUIDFromBytes(invoiceId.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits() &
|
||||||
|
Long.MAX_VALUE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package dev.vality.adapter.flow.lib.service;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class LocalIdGeneratorTest {
|
||||||
|
|
||||||
|
public static final String TEST = "test";
|
||||||
|
public static final String TEST_2 = "test_2";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void get() {
|
||||||
|
LocalIdGenerator localIdGenerator = new LocalIdGenerator();
|
||||||
|
|
||||||
|
Long idTest1 = localIdGenerator.get(TEST);
|
||||||
|
Long idTest2 = localIdGenerator.get(TEST);
|
||||||
|
|
||||||
|
Assertions.assertEquals(idTest1, idTest2);
|
||||||
|
|
||||||
|
Long idTest3 = localIdGenerator.get(TEST_2);
|
||||||
|
|
||||||
|
Assertions.assertNotEquals(idTest1, idTest3);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user