Skip to content

Commit 3ab53af

Browse files
committedSep 25, 2024
Update project to JDK 23.
1 parent c9b0efd commit 3ab53af

File tree

8 files changed

+23
-39
lines changed

8 files changed

+23
-39
lines changed
 

‎Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define your base image
2-
FROM container-registry.oracle.com/java/openjdk:22-oraclelinux8 as jre-build
2+
FROM container-registry.oracle.com/java/openjdk:23-oraclelinux9 as jre-build
33

44
RUN $JAVA_HOME/bin/jlink \
55
--add-modules java.base,java.compiler,java.desktop,java.instrument,java.management,java.net.http,java.prefs,java.rmi,java.scripting,java.security.jgss,java.sql.rowset,jdk.jfr,jdk.net,jdk.unsupported,jdk.management.agent,jdk.crypto.ec,jdk.management.jfr \
@@ -11,7 +11,7 @@ RUN $JAVA_HOME/bin/jlink \
1111
# Define your base image
1212
FROM oraclelinux:9-slim
1313

14-
ENV JAVA_HOME /usr/java/openjdk-22
14+
ENV JAVA_HOME /usr/java/openjdk-23
1515
ENV PATH $JAVA_HOME/bin:$PATH
1616
COPY --from=jre-build /javaruntime $JAVA_HOME
1717

‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ spring.ssl.bundle.jks.mybundle.keystore.location=stores/keystore.p12
8181
spring.ssl.bundle.jks.mybundle.truststore.location=stores/truststore.p12
8282
```
8383

84-
**IMPORTANT** For demo purposes, `application.properties` file contains the passwords in clear. For production environments you must consider encrypting your passwords.
84+
**IMPORTANT** For demo purposes, `application.properties` contains the passwords in clear.
85+
For production environments you must consider encrypting your passwords.
8586

8687
## How to play
8788

‎pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.springframework.boot</groupId>
77
<artifactId>spring-boot-starter-parent</artifactId>
8-
<version>3.2.4</version>
8+
<version>3.3.2</version>
99
<relativePath/>
1010
</parent>
1111

@@ -15,7 +15,7 @@
1515
<name>tictactoe</name>
1616
<description>TicTacToe with Spring Boot</description>
1717
<properties>
18-
<java.version>22</java.version>
18+
<java.version>23</java.version>
1919
<maven.dependency.plugin.version>3.5.0</maven.dependency.plugin.version>
2020
<jackson.databind.version>2.15.2</jackson.databind.version>
2121
</properties>

‎src/main/java/com/example/game/ApplicationStartup.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
3131
countTLSHandshake(metricsRegistry, es);
3232
countX509Parser(metricsRegistry, es);
3333

34-
es.onEvent(JDK_X509_VALIDATION, recordedEvent -> {
35-
Gauge.builder(JDK_X509_VALIDATION + VALIDATION_COUNTER,
36-
recordedEvent, e -> e.getLong(VALIDATION_COUNTER))
37-
.description("X509 Certificate Validation Gauge").register(metricsRegistry);
38-
});
34+
es.onEvent(JDK_X509_VALIDATION, recordedEvent -> Gauge.builder(JDK_X509_VALIDATION + VALIDATION_COUNTER,
35+
recordedEvent, e -> e.getLong(VALIDATION_COUNTER))
36+
.description("X509 Certificate Validation Gauge").register(metricsRegistry));
3937

4038
es.start();
4139
} catch (IOException e) {
@@ -44,7 +42,7 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
4442
}
4543

4644
private static void countTLSHandshake(CompositeMeterRegistry metricsRegistry, EventStream es) {
47-
es.onEvent(JDK_TLS_HANDSHAKE, recordedEvent -> {
45+
es.onEvent(JDK_TLS_HANDSHAKE, _ -> {
4846

4947
Counter counter = metricsRegistry.find(JDK_TLS_HANDSHAKE).counter();
5048
if (Objects.nonNull(counter)) {

‎src/main/java/com/example/game/board/BoardService.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.springframework.transaction.annotation.Transactional;
99

1010
import java.util.List;
11+
import java.util.Random;
12+
import java.util.stream.IntStream;
1113

1214
@Service
1315
public class BoardService {
@@ -42,8 +44,17 @@ public Board build(Player player, Cell option) {
4244

4345

4446
public void randomMove(Board board) {
45-
Coordinate location = cellManager.findRandomFreeCell(board.getLines());
46-
move(board, location);
47+
List<List<String>> lines = board.getLines();
48+
List<Coordinate> freeCells = IntStream.range(0, lines.size())
49+
.boxed()
50+
.flatMap(rowIndex -> IntStream.range(0, lines.getFirst().size())
51+
.mapToObj(columnIndex -> new Coordinate(rowIndex, columnIndex)))
52+
.filter(cell -> lines.get(cell.horizontal()).get(cell.vertical()).isEmpty())
53+
.toList();
54+
if (!freeCells.isEmpty()) {
55+
int random = new Random().nextInt(freeCells.size());
56+
move(board, freeCells.get(random));
57+
}
4758
}
4859

4960
public void move(Board board, Coordinate location) {

‎src/main/java/com/example/game/board/cell/CellManager.java

-13
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,4 @@ public static List<List<String>> collectAll(List<List<String>> lines) {
4747
return borders;
4848
}
4949

50-
public Coordinate findRandomFreeCell(List<List<String>> lines) {
51-
List<Coordinate> freeCells = IntStream.range(0, lines.size())
52-
.boxed()
53-
.flatMap(rowIndex -> IntStream.range(0, lines.getFirst().size())
54-
.mapToObj(columnIndex -> new Coordinate(rowIndex, columnIndex)))
55-
.filter(cell -> lines.get(cell.horizontal()).get(cell.vertical()).isEmpty())
56-
.toList();
57-
58-
int random = new Random().nextInt(freeCells.size());
59-
60-
return freeCells.get(random);
61-
62-
}
6350
}

‎src/test/java/com/example/game/board/BoardServiceTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void randomMove() {
6363
when(cellManager.init()).thenCallRealMethod();
6464

6565
Board board = service.build(new Player(), Cell.X);
66-
when(cellManager.findRandomFreeCell(board.getLines())).thenCallRealMethod();
6766

6867
service.randomMove(board);
6968

‎src/test/java/com/example/game/board/cell/CellManagerTest.java

-12
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ void init() {
1919
assertThat(board.size()).isEqualTo(3);
2020
}
2121

22-
@Test
23-
void findRandomFreeCell() {
24-
CellManager cellManager = new CellManager();
25-
List<List<String>> lines = new ArrayList<>();
26-
lines.addAll(Collections.singleton(Arrays.asList(Cell.EMPTY.toString(), Cell.EMPTY.toString(), Cell.EMPTY.toString())));
27-
28-
Coordinate freeCell = cellManager.findRandomFreeCell(lines);
29-
assertThat(freeCell.horizontal()).isNotNegative();
30-
assertThat(freeCell.vertical()).isNotNegative();
31-
32-
}
33-
3422
@Test
3523
void collectAll() {
3624
List<List<String>> lines = new ArrayList<>();

0 commit comments

Comments
 (0)
Please sign in to comment.