Skip to content

Commit

Permalink
perf: run live-event call asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
webatspeed committed Sep 29, 2022
1 parent f732f54 commit ff8ea23
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
Expand All @@ -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<String> userIds) {
await();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit ff8ea23

Please sign in to comment.