Add local id gen (#72)

This commit is contained in:
struga 2023-10-30 14:15:31 +03:00 committed by GitHub
parent 94418ab4ea
commit 21442408e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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);
}
}