Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KPMP-5209_upgrade-to-java21 #29

Merged
merged 9 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-gradle-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
build-gradle-project:
env:
IMAGE_TAG: 2.2
IMAGE_TAG: 4.1
runs-on: ubuntu-latest
steps:
- name: Get branch names
Expand All @@ -21,12 +21,12 @@ jobs:
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '21'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4
gradle-version: 8.5

- name: Login to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ build/
.idea
*.iml
bin/
.vscode
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dist: trusty
language: java

jdk:
- oraclejdk8
- oraclejdk21

install: true

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM alpine
FROM alpine:3.19.1

RUN apk update && \
apk upgrade
RUN apk add openjdk8
RUN apk add openjdk21

VOLUME /tmp
ARG DEPENDENCY=target/dependency
Expand Down
31 changes: 16 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.4")
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.2.5")
}

}

plugins {
id 'com.palantir.docker' version '0.22.1'
id 'java'
id 'com.palantir.docker' version '0.35.0'
id 'org.springframework.boot' version '3.2.5'
}

group = 'kingstonduo'

group='kingstonduo'
version='4.1'


apply plugin: 'java'
Expand All @@ -22,27 +24,26 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.docker'

jar {
baseName='state-manager-service'
version= '2.2'
}


repositories {
mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = '21'
targetCompatibility = '21'

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.apache.commons:commons-compress:1.21'
implementation 'org.apache.commons:commons-compress:1.26.0'
implementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.data:spring-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core'
testImplementation 'junit:junit:4.12'
testImplementation('org.mockito:mockito-junit-jupiter:3.12.4')
testImplementation 'org.springframework:spring-test:5.2.25.RELEASE'
}

springBoot {
Expand Down Expand Up @@ -71,15 +72,15 @@ def getCurrentGitBranch() {
} catch (e) {
}
if (gitBranch == "develop" || gitBranch == "master"){
return jar.version
return project.version
}else{
return gitBranch
}
}
}

docker {
name "kingstonduo/${jar.baseName}:" + getCurrentGitBranch()
name "kingstonduo/state-manager-service:" + getCurrentGitBranch()
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class DluPackageInventoryService {
private String dataManagerHost;
@Value("${data-manager.service.endpoint}")
private String dataManagerEndpoint;
private RestTemplate restTemplate;
private final RestTemplate restTemplate;

private static final Log log = LogFactory.getLog(DluPackageInventoryService.class);

Expand All @@ -26,7 +26,7 @@ public DluPackageInventoryService(RestTemplate restTemplate) {
}

public String setPackageInError(String packageId) {
HashMap payload = new HashMap<>();
HashMap<String, Boolean> payload = new HashMap<>();
payload.put("dlu_error", true);
String retPackageId = null;
String url = dataManagerHost + dataManagerEndpoint + "/package/" + packageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NotificationHandler {
private String notificationServiceHost;
@Value("${notification.endpoint}")
private String notificationEndpoint;
private RestTemplate restTemplate;
private final RestTemplate restTemplate;

public NotificationHandler(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/kpmp/stateManager/StateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,10 +17,12 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.async.DeferredResult;

import jakarta.servlet.http.HttpServletRequest;

@Controller
public class StateController {

private StateService stateService;
private final StateService stateService;
private static final Log log = LogFactory.getLog(StateController.class);

@Value("${package.state.longpoll.timeout}")
Expand Down Expand Up @@ -60,10 +60,11 @@ public StateController(StateService stateService) {
return stateService.getAllStateDisplays();
}


@RequestMapping(value = "/v1/state/events/{afterTime}", method = RequestMethod.GET)
public @ResponseBody DeferredResult<List<State>> getStateEvents(@PathVariable("afterTime") String afterTime,
HttpServletRequest request) {
Date stateChangeDate = new Date(new Long(afterTime));
Date stateChangeDate = new Date(Long.parseLong(afterTime));

log.info("URI: " + request.getRequestURI() + " | MSG: Long poll for events after " + stateChangeDate);

Expand All @@ -73,7 +74,7 @@ public StateController(StateService stateService) {
try {
List<State> result = stateService.findPackagesChangedAfterStateChangeDate(stateChangeDate);

while (result.size() == 0) {
while (result.isEmpty()) {
TimeUnit.SECONDS.sleep(2);
result = stateService.findPackagesChangedAfterStateChangeDate(stateChangeDate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand All @@ -10,9 +10,9 @@
import java.util.List;

import org.bson.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.data.mongodb.core.MongoTemplate;
Expand All @@ -29,14 +29,15 @@ public class CustomStateRepositoryTest {
private MongoTemplate mongoTemplate;
private CustomStateRepository customRepo;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
customRepo = new CustomStateRepository(stateRepository, mongoTemplate);
}

@After
@AfterEach
public void tearDown() throws Exception {
MockitoAnnotations.openMocks(this).close();
customRepo = null;
}

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/kpmp/stateManager/NotificationHandlerTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand All @@ -20,16 +20,17 @@ public class NotificationHandlerTest {
private RestTemplate restTemplate;
private NotificationHandler handler;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
handler = new NotificationHandler(restTemplate);
ReflectionTestUtils.setField(handler, "notificationServiceHost", "host");
ReflectionTestUtils.setField(handler, "notificationEndpoint", "/endpoint");
}

@After
@AfterEach
public void tearDown() throws Exception {
MockitoAnnotations.openMocks(this).close();
handler = null;
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/kpmp/stateManager/StateChangeEventTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class StateChangeEventTest {

private StateChangeEvent event;

@Before
@BeforeEach
public void setUp() throws Exception {
event = new StateChangeEvent("origin", "packageId", "state", "codicil");
}

@After
@AfterEach
public void tearDown() throws Exception {
event = null;
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/org/kpmp/stateManager/StateControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand All @@ -22,13 +22,13 @@ public class StateControllerTest {
private StateService stateService;
private StateController controller;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this).close();
controller = new StateController(stateService);
}

@After
@AfterEach
public void tearDown() throws Exception {
controller = null;
}
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/kpmp/stateManager/StateDisplayTest.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import org.bson.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;

public class StateDisplayTest {

private StateDisplay stateDisplay;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
stateDisplay = new StateDisplay();
}

@After
@AfterEach
public void tearDown() throws Exception {
MockitoAnnotations.openMocks(this).close();
stateDisplay = null;
}

Expand Down
Loading
Loading