Skip to content

Commit

Permalink
Merge pull request #16 from dm-drogeriemarkt/spring-boot-3
Browse files Browse the repository at this point in the history
Spring boot 3
  • Loading branch information
PatrickTheBaker authored Nov 2, 2023
2 parents 155a64b + e1fd802 commit 54227cd
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-with-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 8
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '8'
java-version: '17'
distribution: 'adopt'
cache: maven

Expand Down
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.12.RELEASE</version>
<version>3.1.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.version>2.0.0-SNAPSHOT</project.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
<jacoco.version>0.8.3</jacoco.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-release-plugin.version>3.0.1</maven-release-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -149,7 +149,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -173,7 +173,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -186,7 +186,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.6.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -224,7 +224,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.15.0</version>
<version>2.16.1</version>
<configuration>
<generateBackupPoms>false</generateBackupPoms>
</configuration>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/de/dm/retrylib/ApplicationShutdownHandler.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package de.dm.retrylib;

import jakarta.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.PreDestroy;

import java.util.concurrent.LinkedBlockingQueue;

class ApplicationShutdownHandler {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/de/dm/retrylib/RetrylibAutoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -12,6 +13,7 @@
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

@AutoConfiguration
@Configuration
@EnableScheduling
@EnableConfigurationProperties(RetrylibProperties.class)
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/META-INF/spring.factories

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
de.dm.retrylib.RetrylibAutoConfiguration
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.dm.retrylib;

import org.junit.Test;

import org.junit.jupiter.api.Test;

import java.util.concurrent.LinkedBlockingQueue;

Expand Down
32 changes: 15 additions & 17 deletions src/test/java/de/dm/retrylib/RetryAspectUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@

import org.aspectj.lang.ProceedingJoinPoint;
import org.hamcrest.CoreMatchers;
import org.junit.Before;
import org.junit.Test;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

public class RetryAspectUnitTest {
class RetryAspectUnitTest {

private RetryAspect retryAspect;

private RetryService retryService = mock(RetryService.class);
private RetryHandler retryHandler = mock(RetryHandler.class);

@Before
public void setUp() {
@BeforeEach
void setUp() {
retryAspect = new RetryAspect(retryService);
}

@Test
public void runWithRetryProceedsJoinPoint() throws Throwable {
void runWithRetryProceedsJoinPoint() throws Throwable {
ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);

retryAspect.runWithRetry(proceedingJoinPoint);
Expand All @@ -33,8 +31,8 @@ public void runWithRetryProceedsJoinPoint() throws Throwable {
}


@Test(expected = UnknownError.class)
public void runWithRetryRequeuesInvocationOnError() throws Throwable {
@Test
void runWithRetryRequeuesInvocationOnError() throws Throwable {
ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);
doThrow(new UnknownError("Testerror")).when(proceedingJoinPoint).proceed();
String payload = "payload";
Expand All @@ -43,14 +41,14 @@ public void runWithRetryRequeuesInvocationOnError() throws Throwable {
when(proceedingJoinPoint.getArgs()).thenReturn(invocationArguments);
when(proceedingJoinPoint.getTarget()).thenReturn(retryHandler);

retryAspect.runWithRetry(proceedingJoinPoint);
Assertions.assertThrows(UnknownError.class, () -> retryAspect.runWithRetry(proceedingJoinPoint));

verify(proceedingJoinPoint).proceed();
verify(retryService).queueForRetry(retryHandler.getClass(), payload);
}

@Test
public void runWithRetryRequeuesInvocationOnThrowable() throws Throwable {
void runWithRetryRequeuesInvocationOnThrowable() throws Throwable {
ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);
doThrow(new Throwable("TestThrowable")).when(proceedingJoinPoint).proceed();
String payload = "payload";
Expand All @@ -60,14 +58,14 @@ public void runWithRetryRequeuesInvocationOnThrowable() throws Throwable {
when(proceedingJoinPoint.getTarget()).thenReturn(retryHandler);

Object returnValue = retryAspect.runWithRetry(proceedingJoinPoint);
assertThat(returnValue, CoreMatchers.nullValue());
MatcherAssert.assertThat(returnValue, CoreMatchers.nullValue());

verify(proceedingJoinPoint).proceed();
verify(retryService).queueForRetry(retryHandler.getClass(), payload);
}

@Test
public void retryableMethodsPointcutExistsAndCanBeInvoked() {
void retryableMethodsPointcutExistsAndCanBeInvoked() {
retryAspect.retryableMethods();
}

Expand Down
18 changes: 10 additions & 8 deletions src/test/java/de/dm/retrylib/RetryEntitySerializerUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class RetryEntitySerializerUnitTest {
class RetryEntitySerializerUnitTest {

private final ObjectMapper objectMapper = mock(ObjectMapper.class);

private final RetryEntitySerializer retryEntitySerializer = new RetryEntitySerializer(objectMapper);

@Test
public void serialize() throws Exception {
void serialize() throws Exception {
String payload = "payload";
RetryEntity retryEntity = new RetryEntity("key", ExternalServiceRetryHandler.class, payload);
when(objectMapper.writeValueAsString(retryEntity)).thenReturn("{}");
Expand All @@ -27,13 +29,13 @@ public void serialize() throws Exception {
assertThat(serializedEntityAsJson, is("{}"));
}

@Test(expected = IllegalArgumentException.class)
public void serializeThrowsExceptionIfEntityCouldNotBeSerialized() throws Exception {
@Test
void serializeThrowsExceptionIfEntityCouldNotBeSerialized() throws Exception {
String payload = "payload";
RetryEntity retryEntity = new RetryEntity("key", ExternalServiceRetryHandler.class, payload);
when(objectMapper.writeValueAsString(retryEntity)).thenThrow(JsonMappingException.from(mock(DeserializationContext.class), "provoked exception"));
doThrow(JsonMappingException.from(mock(DeserializationContext.class), "provoked exception")).when(objectMapper).writeValueAsString(retryEntity);

retryEntitySerializer.serialize(retryEntity);
Assertions.assertThrows(IllegalArgumentException.class, () -> retryEntitySerializer.serialize(retryEntity));
}

}
27 changes: 15 additions & 12 deletions src/test/java/de/dm/retrylib/RetryProcessorUnitTest.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package de.dm.retrylib;

import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.mockito.Matchers.anyInt;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

public class RetryProcessorUnitTest {
class RetryProcessorUnitTest {

private RetryProcessor retryProcessor;
private List<RetryHandler> retryHandlers;
Expand All @@ -28,29 +30,30 @@ public void handleWithRetry(String payload) {
};
private RetryEntitySerializer retryEntitySerializer = mock(RetryEntitySerializer.class);

@Before
public void setUp() {
@BeforeEach
void setUp() {
validRetryHandler = spy(validRetryHandler);

retryHandlers = new ArrayList<>();
retryHandlers.add(validRetryHandler);
retryProcessor = new RetryProcessor(retryService, retryHandlers, retryEntitySerializer);
}

@Test(expected = IllegalArgumentException.class)
public void processNextRetryBatchThrowsExceptionWhenNoHandlerIsAvailable() {
@Test
void processNextRetryBatchThrowsExceptionWhenNoHandlerIsAvailable() {
RetryEntity retryEntity = new RetryEntity("key", String.class, "payload");
List<RetryEntity> retryEntities = Collections.singletonList(retryEntity);

when(retryService.loadNextRetryEntities(anyInt())).thenReturn(retryEntities);

retryProcessor.processNextRetryBatch();
Assertions.assertThrows(IllegalArgumentException.class, () -> retryProcessor.processNextRetryBatch());

verifyZeroInteractions(retryService);
verify(retryService).loadNextRetryEntities(anyInt());
verifyNoMoreInteractions(retryService);
}

@Test
public void processNextRetryBatchTriggersRetry() {
void processNextRetryBatchTriggersRetry() {
RetryEntity retryEntity1 = new RetryEntity("key1", validRetryHandler.getClass(), "payload1");
RetryEntity retryEntity2 = new RetryEntity("key2", validRetryHandler.getClass(), "payload2");
List<RetryEntity> retryEntities = Arrays.asList(retryEntity1, retryEntity2);
Expand Down
27 changes: 15 additions & 12 deletions src/test/java/de/dm/retrylib/RetryServiceUnitTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package de.dm.retrylib;

import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;

public class RetryServiceUnitTest {
class RetryServiceUnitTest {

private RetryService retryService;

Expand All @@ -25,24 +27,25 @@ public void handleWithRetry(String payload) {
};
private LinkedBlockingQueue<RetryEntity> retryEntities;

@Before
public void setUp() {
@BeforeEach
void setUp() {
retryEntities = new LinkedBlockingQueue<>(5);
retryService = new RetryService(retryEntities, retryEntitySerializer);
}

@Test(expected = IllegalStateException.class)
public void queueForRetryThrowsIllegalStateExceptionOnLimitReached() {
@Test
void queueForRetryThrowsIllegalStateExceptionOnLimitReached() {
LinkedBlockingQueue<RetryEntity> retryEntities = new LinkedBlockingQueue<>(1);
retryService = new RetryService(retryEntities, retryEntitySerializer);

retryService.queueForRetry(demoRetryHandler.getClass(), "payload1");
retryService.queueForRetry(demoRetryHandler.getClass(), "payload2");

Assertions.assertThrows(IllegalStateException.class, () -> retryService.queueForRetry(demoRetryHandler.getClass(), "payload2"));
}


@Test
public void queueForRetryWritesToQueueSuccessfully() throws InterruptedException {
void queueForRetryWritesToQueueSuccessfully() throws InterruptedException {
String payload = "payload";
retryService.queueForRetry(demoRetryHandler.getClass(), payload);

Expand All @@ -53,7 +56,7 @@ public void queueForRetryWritesToQueueSuccessfully() throws InterruptedException
}

@Test
public void loadNextRetryEntitiesReturnsListOfEntries() {
void loadNextRetryEntitiesReturnsListOfEntries() {
String payload = "payload";
retryService.queueForRetry(demoRetryHandler.getClass(), payload);

Expand All @@ -63,7 +66,7 @@ public void loadNextRetryEntitiesReturnsListOfEntries() {
}

@Test
public void loadNextRetryEntitiesReturnsListOfEntriesLimitedByBatchSize() {
void loadNextRetryEntitiesReturnsListOfEntriesLimitedByBatchSize() {
retryService.queueForRetry(demoRetryHandler.getClass(), "payload1");
retryService.queueForRetry(demoRetryHandler.getClass(), "payload2");
retryService.queueForRetry(demoRetryHandler.getClass(), "payload3");
Expand Down
Loading

0 comments on commit 54227cd

Please sign in to comment.