From ff8ea23a5b25677fedf7160002521abd9e832788 Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 29 Sep 2022 17:12:26 +0200 Subject: [PATCH 1/2] perf: run live-event call asynchronously --- .../LiveEventNotificationService.java | 2 + .../config/apiclient/SpringAsyncConfig.java | 10 +++++ .../LiveEventNotificationServiceIT.java | 38 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/main/java/de/caritas/cob/videoservice/config/apiclient/SpringAsyncConfig.java create mode 100644 src/test/java/de/caritas/cob/videoservice/api/service/liveevent/LiveEventNotificationServiceIT.java 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..791756c --- /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 +public 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()); + } +} From 5db04d78663e1d82210c2e9f1b05446145c7f10e Mon Sep 17 00:00:00 2001 From: Torsten Krohn Date: Thu, 29 Sep 2022 17:16:13 +0200 Subject: [PATCH 2/2] chore: remove smelling modifier --- .../api/service/liveevent/LiveEventNotificationServiceIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 791756c..8519d74 100644 --- 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 @@ -17,7 +17,7 @@ @SpringBootTest @ActiveProfiles("testing") @DirtiesContext -public class LiveEventNotificationServiceIT { +class LiveEventNotificationServiceIT { @Autowired private LiveEventNotificationService underTest;