Skip to content

Commit cca54fd

Browse files
Using Ids utility classes (#67)
1 parent 85d12de commit cca54fd

File tree

44 files changed

+374
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+374
-176
lines changed

.github/workflows/PR.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2929
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3030
run: |
31-
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
31+
mvn -B -Pjacoco verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
3232
-Dsonar.host.url="https://sonarcloud.io" \
3333
-Dsonar.organization=memoria-io \
3434
-Dsonar.projectKey=memoria-io_atom

.github/workflows/Release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3131
run: |
32-
mvn --batch-mode deploy org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
32+
mvn -B -Pjacoco deploy org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
3333
-Dsonar.host.url="https://sonarcloud.io" \
3434
-Dsonar.organization=memoria-io \
3535
-Dsonar.projectKey=memoria-io_atom

core/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.memoria</groupId>
88
<artifactId>atom</artifactId>
9-
<version>24.4.0</version>
9+
<version>24.5.0</version>
1010
</parent>
1111

1212
<groupId>io.memoria.atom</groupId>
1313
<artifactId>core</artifactId>
14-
<version>24.4.0</version>
14+
<version>24.5.0</version>
1515
<packaging>jar</packaging>
1616
<name>${project.groupId}.${project.artifactId}</name>
1717
<description>Core Module</description>

core/src/main/java/io/memoria/atom/core/id/Id.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ public Id(Id id) {
2929
this.value = id.value;
3030
}
3131

32-
public static Id of(String value) {
33-
return new Id(value);
34-
}
35-
36-
public static Id of(long value) {
37-
return new Id(value);
38-
}
39-
40-
public static Id of(UUID uuid) {
41-
return new Id(uuid);
42-
}
43-
4432
public String value() {
4533
return value;
4634
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.memoria.atom.core.id;
2+
3+
import java.util.UUID;
4+
5+
public class Ids {
6+
private Ids() {}
7+
8+
public static Id of(String value) {
9+
return new Id(value);
10+
}
11+
12+
public static Id of(long value) {
13+
return new Id(value);
14+
}
15+
16+
public static Id of(UUID uuid) {
17+
return new Id(uuid);
18+
}
19+
}

core/src/test/java/io/memoria/atom/core/domain/PartitionedTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.memoria.atom.core.domain;
22

33
import io.memoria.atom.core.id.Id;
4+
import io.memoria.atom.core.id.Ids;
45
import io.memoria.atom.core.math.MathOps;
56
import org.assertj.core.api.Assertions;
67
import org.junit.jupiter.params.ParameterizedTest;
@@ -28,7 +29,7 @@ public class PartitionedTest {
2829
@MethodSource("totalPartitions")
2930
void uuidShardsShouldBeNormal(int totalPartitions) {
3031
// Given
31-
var shards = createShards(_ -> Id.of(UUID.randomUUID()));
32+
var shards = createShards(_ -> Ids.of(UUID.randomUUID()));
3233
var partitionSizeList = partitionSizeList(shards, totalPartitions).stream().map(Long::doubleValue).toList();
3334
int maxOutliers = getMaxOutliers(totalPartitions);
3435

@@ -43,7 +44,7 @@ void uuidShardsShouldBeNormal(int totalPartitions) {
4344
@MethodSource("totalPartitions")
4445
void longShardsShouldBeNormal(int totalPartitions) {
4546
// Given
46-
var shards = createShards(Id::of);
47+
var shards = createShards(Ids::of);
4748
var partitionSizeList = partitionSizeList(shards, totalPartitions).stream().map(Long::doubleValue).toList();
4849

4950
// When

core/src/test/java/io/memoria/atom/core/id/IdTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ void idEquality() {
2222
var uuidStr = uuid.toString();
2323

2424
// When
25-
var id1 = Id.of(uuid);
26-
var id2 = Id.of(uuidStr);
25+
var id1 = Ids.of(uuid);
26+
var id2 = Ids.of(uuidStr);
2727

2828
// Then
2929
Assertions.assertThat(id1).isEqualTo(id2).hasToString(uuidStr);
@@ -32,31 +32,31 @@ void idEquality() {
3232

3333
@Test
3434
void happyPath() {
35-
var id = Id.of(UuidCreator.getTimeOrderedEpoch());
35+
var id = Ids.of(UuidCreator.getTimeOrderedEpoch());
3636
Assertions.assertThat(id.value()).isNotEmpty();
3737
}
3838

3939
@Test
4040
void validation() {
4141
String str = null;
4242
//noinspection ConstantValue
43-
Assertions.assertThatNullPointerException().isThrownBy(() -> Id.of(str));
44-
Assertions.assertThatIllegalArgumentException().isThrownBy(() -> Id.of(-1L));
45-
Assertions.assertThatIllegalArgumentException().isThrownBy(() -> Id.of(""));
43+
Assertions.assertThatNullPointerException().isThrownBy(() -> Ids.of(str));
44+
Assertions.assertThatIllegalArgumentException().isThrownBy(() -> Ids.of(-1L));
45+
Assertions.assertThatIllegalArgumentException().isThrownBy(() -> Ids.of(""));
4646
}
4747

4848
@Test
4949
void uuidOrdering() {
5050
TreeMap<Id, Integer> map = new TreeMap<>();
51-
IntStream.range(0, 1000).forEach(i -> map.put(Id.of(UuidCreator.getTimeOrderedEpoch()), i));
51+
IntStream.range(0, 1000).forEach(i -> map.put(Ids.of(UuidCreator.getTimeOrderedEpoch()), i));
5252
var atomic = new AtomicInteger(0);
5353
map.forEach((k, v) -> Assertions.assertThat(v).isEqualTo(atomic.getAndIncrement()));
5454
}
5555

5656
@Test
5757
void seqIdOrdering() {
5858
TreeMap<Id, Integer> map = new TreeMap<>();
59-
IntStream.range(0, 1000).forEach(i -> map.put(Id.of(i), i));
59+
IntStream.range(0, 1000).forEach(i -> map.put(Ids.of(i), i));
6060
var atomic = new AtomicInteger(0);
6161
map.forEach((k, v) -> Assertions.assertThat(v).isEqualTo(atomic.getAndIncrement()));
6262
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.memoria.atom.core.id;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.UUID;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
class IdsTest {
10+
@Test
11+
void testOfString() {
12+
Id id = Ids.of("123");
13+
assertEquals("123", id.value());
14+
}
15+
16+
@Test
17+
void testOfLong() {
18+
Id id = Ids.of(123L);
19+
assertEquals("123", id.value());
20+
}
21+
22+
@Test
23+
void testOfUUID() {
24+
UUID uuid = UUID.randomUUID();
25+
Id id = Ids.of(uuid);
26+
assertEquals(uuid.toString(), id.value());
27+
}
28+
}

docker-compose.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: '3.8'
2+
3+
services:
4+
sonarqube:
5+
image: sonarqube:latest
6+
container_name: sonarqube
7+
ports:
8+
- "127.0.0.1:9000:9000"
9+
environment:
10+
- SONAR_JDBC_URL=jdbc:postgresql://db:5432/sonar
11+
- SONAR_JDBC_USERNAME=sonar
12+
- SONAR_JDBC_PASSWORD=sonar
13+
depends_on:
14+
- db
15+
16+
db:
17+
image: postgres:latest
18+
container_name: sonarqube_db
19+
environment:
20+
- POSTGRES_USER=sonar
21+
- POSTGRES_PASSWORD=sonar
22+
- POSTGRES_DB=sonar
23+
volumes:
24+
- sonarqube_db_data:/var/lib/postgresql/data
25+
26+
volumes:
27+
sonarqube_db_data:

eventsourcing/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>io.memoria</groupId>
88
<artifactId>atom</artifactId>
9-
<version>24.4.0</version>
9+
<version>24.5.0</version>
1010
</parent>
1111

1212
<groupId>io.memoria.atom</groupId>
1313
<artifactId>eventsourcing</artifactId>
14-
<version>24.4.0</version>
14+
<version>24.5.0</version>
1515
<packaging>jar</packaging>
1616
<name>${project.groupId}.${project.artifactId}</name>
1717
<description>eventsourcing Module</description>

0 commit comments

Comments
 (0)