Skip to content

Commit

Permalink
DMP-3387 Upgrade Java to version 21 (#1707)
Browse files Browse the repository at this point in the history
Co-authored-by: Dave Thompson <[email protected]>
  • Loading branch information
jackmaloney and davet1985 authored Jul 12, 2024
1 parent e6cc9dd commit 75fe306
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'
cache: 'gradle'
- name: Build
run: ./gradlew check -x integration
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
java-version: '21'

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# renovate: datasource=github-releases depName=microsoft/ApplicationInsights-Java
ARG APP_INSIGHTS_AGENT_VERSION=3.5.3

FROM openjdk:17.0.2-jdk-slim-bullseye AS build-env
FROM openjdk:21-jdk-slim-bullseye AS build-env
WORKDIR /usr/local/bin
# Linux Static Builds (http://www.ffmpeg.org/download.html#build-linux)
# https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
Expand All @@ -14,7 +14,7 @@ RUN cp -p azcopy*/azcopy /usr/bin
RUN chmod 777 /usr/bin/azcopy

# renovate: datasource=github-releases depName=microsoft/ApplicationInsights-Java
FROM hmctspublic.azurecr.io/base/java:17-distroless
FROM hmctspublic.azurecr.io/base/java:21-distroless
COPY --from=build-env /usr/bin/ffmpeg /usr/bin
COPY --from=build-env /usr/bin/azcopy /usr/bin

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## Prerequisites

- [Java 17](https://www.oracle.com/java)
- [Java 21](https://www.oracle.com/java)
- ffmpeg

### Environment variables
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ group = 'uk.gov.hmcts'
version = '0.0.1'

compileJava {
sourceCompatibility = '17'
targetCompatibility = '17'
sourceCompatibility = '21'
targetCompatibility = '21'
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
languageVersion = JavaLanguageVersion.of(21)
}
}

Expand Down Expand Up @@ -180,13 +180,17 @@ pmd {
toolVersion = "7.3.0"
sourceSets = [sourceSetsCopy.main]
reportsDir = file("$project.buildDir/reports/pmd")
// https://github.com/pmd/pmd/issues/876
ruleSets = []
ruleSetFiles = files("config/pmd/main-ruleset.xml")
}

pmd {
toolVersion = "7.3.0"
sourceSets = [sourceSetsCopy.test, sourceSetsCopy.functionalTest, sourceSetsCopy.integrationTest, sourceSetsCopy.smokeTest]
reportsDir = file("$project.buildDir/reports/pmd")
// https://github.com/pmd/pmd/issues/876
ruleSets = []
ruleSetFiles = files("config/pmd/test-ruleset.xml")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,26 @@ void testSummationWithConcurrency() throws InterruptedException {
dartsGateway.darNotificationReturnsSuccess();

int numberOfThreads = 100;
ExecutorService service = Executors.newFixedThreadPool(5);
CountDownLatch latch = new CountDownLatch(numberOfThreads);


for (int i = 0; i < numberOfThreads; i++) {
int nanoSec = i * 1000;
service.submit(() -> {
DartsEvent dartsEvent = someMinimalDartsEvent()
.caseNumbers(List.of("asyncTestCaseNumber"))
.courthouse(SOME_COURTHOUSE)
.courtroom("asyncTestCourtroom")
.dateTime(HEARING_DATE_ODT.withNano(nanoSec))
.eventId(null);
eventDispatcher.receive(dartsEvent);
latch.countDown();
});
try (ExecutorService service = Executors.newFixedThreadPool(5)) {
CountDownLatch latch = new CountDownLatch(numberOfThreads);

for (int i = 0; i < numberOfThreads; i++) {
int nanoSec = i * 1000;
service.submit(() -> {
DartsEvent dartsEvent = someMinimalDartsEvent()
.caseNumbers(List.of("asyncTestCaseNumber"))
.courthouse(SOME_COURTHOUSE)
.courtroom("asyncTestCourtroom")
.dateTime(HEARING_DATE_ODT.withNano(nanoSec))
.eventId(null);
eventDispatcher.receive(dartsEvent);
latch.countDown();
});
}
latch.await(5, TimeUnit.SECONDS);
assertEquals(1, dartsDatabase.getHearingRepository().findAll().size());
assertEquals(numberOfThreads, dartsDatabase.getAllEvents().size());
}
latch.await(5, TimeUnit.SECONDS);
assertEquals(1, dartsDatabase.getHearingRepository().findAll().size());
assertEquals(numberOfThreads, dartsDatabase.getAllEvents().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ void generateReadmeCreatesReadmeWithContent() throws IOException {
if (line.startsWith(COURTHOUSE_README_LABEL)) {
assertEquals("Courthouse: Trainwell Crown Court", line);
} else if (line.startsWith(START_TIME_README_LABEL)) {
assertEquals("Start Time: 24 March 2023 at 09:00:00 GMT", line);
assertEquals("Start Time: 24 March 2023, 09:00:00 GMT", line);
} else if (line.startsWith(END_TIME_README_LABEL)) {
assertEquals("End Time: 24 March 2023 at 12:00:00 GMT", line);
assertEquals("End Time: 24 March 2023, 12:00:00 GMT", line);
} else if (line.startsWith(RAISED_BY_README_LABEL)) {
assertEquals("Raised by: ", line);
} else if (line.startsWith(REQUEST_TYPE_README_LABEL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ class CommandRunnerTest {

@Test
void callSuccessWhenCorrectCommandIsSent() throws Exception {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<String> future = executorService.submit(new CommandRunner(new CommandLine("hostname")));
String threadResponse = future.get();
assertEquals("0", threadResponse);
try (ExecutorService executorService = Executors.newSingleThreadExecutor()) {
Future<String> future = executorService.submit(new CommandRunner(new CommandLine("hostname")));
String threadResponse = future.get();
assertEquals("0", threadResponse);
}
}

@Test
void callFailWhenWrongCommandIsSent() {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Future<String> future = executorService.submit(new CommandRunner(new CommandLine("Dummy Command")));
assertThrows(ExecutionException.class, future::get);
try (ExecutorService executorService = Executors.newSingleThreadExecutor()) {
Future<String> future = executorService.submit(new CommandRunner(new CommandLine("Dummy Command")));
assertThrows(ExecutionException.class, future::get);
}
}
}

0 comments on commit 75fe306

Please sign in to comment.