diff --git a/Dockerfile b/Dockerfile index 3abf471..e58728a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:11.0.10-jre-slim-buster +FROM adoptopenjdk/openjdk11 VOLUME ["/tmp","/log"] EXPOSE 8080 ARG JAR_FILE diff --git a/src/main/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationService.java b/src/main/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationService.java index e372699..50102b3 100644 --- a/src/main/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationService.java +++ b/src/main/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationService.java @@ -7,6 +7,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; /** @@ -26,6 +27,7 @@ public class LiveEventNotificationService { * @param liveEventMessage {@link LiveEventMessage} * @param userIds list of receiver user Ids */ + @Async public void sendVideoCallRequestLiveEvent(LiveEventMessage liveEventMessage, List userIds) { await(); diff --git a/src/main/java/de/caritas/cob/videoservice/config/apiclient/SpringAsyncConfig.java b/src/main/java/de/caritas/cob/videoservice/config/apiclient/SpringAsyncConfig.java new file mode 100644 index 0000000..7523b93 --- /dev/null +++ b/src/main/java/de/caritas/cob/videoservice/config/apiclient/SpringAsyncConfig.java @@ -0,0 +1,10 @@ +package de.caritas.cob.videoservice.config.apiclient; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; + +@Configuration +@EnableAsync +public class SpringAsyncConfig { + +} diff --git a/src/test/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationServiceIT.java b/src/test/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationServiceIT.java new file mode 100644 index 0000000..8519d74 --- /dev/null +++ b/src/test/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationServiceIT.java @@ -0,0 +1,38 @@ +package de.caritas.cob.videoservice.api.service.liveevent; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import de.caritas.cob.videoservice.liveservice.generated.web.LiveControllerApi; +import de.caritas.cob.videoservice.liveservice.generated.web.model.LiveEventMessage; +import java.lang.management.ManagementFactory; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; + +@SpringBootTest +@ActiveProfiles("testing") +@DirtiesContext +class LiveEventNotificationServiceIT { + + @Autowired + private LiveEventNotificationService underTest; + + @MockBean + @Qualifier("liveControllerApi") + @SuppressWarnings("unused") + private LiveControllerApi liveControllerApi; + + @Test + void sendVideoCallRequestLiveEventShouldRunInAnotherThread() { + var threadCount = ManagementFactory.getThreadMXBean().getThreadCount(); + + underTest.sendVideoCallRequestLiveEvent(new LiveEventMessage(), List.of()); + + assertEquals(threadCount + 1, ManagementFactory.getThreadMXBean().getThreadCount()); + } +}