From 1e79b974640e1a4cf656799a51eac699e82c4ef8 Mon Sep 17 00:00:00 2001 From: DongUk <68818952+Kim0914@users.noreply.github.com> Date: Thu, 25 Jan 2024 18:35:19 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A3=BC=EC=84=9D=20=ED=95=B4?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pium/admin/service/TestService.java | 99 +++++++++---------- .../pium/admin/ui/TestController.java | 24 ++--- 2 files changed, 57 insertions(+), 66 deletions(-) diff --git a/backend/pium/src/main/java/com/official/pium/admin/service/TestService.java b/backend/pium/src/main/java/com/official/pium/admin/service/TestService.java index 0a3b2856..e42cd300 100644 --- a/backend/pium/src/main/java/com/official/pium/admin/service/TestService.java +++ b/backend/pium/src/main/java/com/official/pium/admin/service/TestService.java @@ -1,6 +1,9 @@ package com.official.pium.admin.service; +import com.official.pium.petPlant.domain.PetPlant; +import com.official.pium.petPlant.event.notification.NotificationEvent; import com.official.pium.petPlant.repository.PetPlantRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationEventPublisher; @@ -16,63 +19,49 @@ public class TestService { private final PetPlantRepository petPlantRepository; private final ApplicationEventPublisher publisher; -// public void sendWaterNotificationTest() { -// List petPlants = petPlantRepository.findAllByMemberId(7L); -// List events = petPlants.stream() -// .map(plant -> NotificationEvent.builder() -// .title(plant.getNickname()) -// .body("(테스트 중) 물을 줄 시간이에요!") -// .deviceToken(plant.getMember().getDeviceToken()) -// .build() -// ).toList(); -// log.info("동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); -// publisher.publishEvent(NotificationEvents.from(events)); -// log.info("동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); -// } + public void sendWaterNotificationAsyncRampTest() { + List petPlants = petPlantRepository.findAllByMemberId(7L); + List events = petPlants.stream() + .map(plant -> NotificationEvent.builder() + .title(plant.getNickname()) + .body("(테스트 중) 물을 줄 시간이에요!") + .deviceToken(plant.getMember().getDeviceToken()) + .build() + ).toList(); -// public void sendWaterNotificationAsyncRampTest() { -// List petPlants = petPlantRepository.findAllByMemberId(7L); -// List events = petPlants.stream() -// .map(plant -> NotificationEvent.builder() -// .title(plant.getNickname()) -// .body("(테스트 중) 물을 줄 시간이에요!") -// .deviceToken(plant.getMember().getDeviceToken()) -// .build() -// ).toList(); + for (int i = 0; i < 100; i++) { + PetPlant petPlant = petPlants.get(i); + NotificationEvent event = NotificationEvent.builder() + .title(petPlant.getNickname()) + .body("물줘") + .deviceToken(petPlant.getMember().getDeviceToken()) + .build(); + publisher.publishEvent(event); + } -// for (int i = 0; i < 100; i++) { -// PetPlant petPlant = petPlants.get(i); -// NotificationEvent event = NotificationEvent.builder() -// .title(petPlant.getNickname()) -// .body("물줘") -// .deviceToken(petPlant.getMember().getDeviceToken()) -// .build(); -// publisher.publishEvent(event); -// } + log.info("비동기 테스트 램프업 시작"); + for (int i = 0; i < 100; i++) { + NotificationEvent notificationEvent = events.get(i); + publisher.publishEvent(notificationEvent); + } + } -// log.info("비동기 테스트 램프업 시작"); -// for (int i = 0; i < 100; i++) { -// NotificationEvent notificationEvent = events.get(i); -// publisher.publishEvent(notificationEvent); -// } -// } + public void sendWaterNotificationAsyncTest() { + List petPlants = petPlantRepository.findAllByMemberId(7L); + List events = petPlants.stream() + .map(plant -> NotificationEvent.builder() + .title(plant.getNickname()) + .body("(테스트 중) 물을 줄 시간이에요!") + .deviceToken(plant.getMember().getDeviceToken()) + .build() + ).toList(); -// public void sendWaterNotificationAsyncTest() { -// List petPlants = petPlantRepository.findAllByMemberId(7L); -// List events = petPlants.stream() -// .map(plant -> NotificationEvent.builder() -// .title(plant.getNickname()) -// .body("(테스트 중) 물을 줄 시간이에요!") -// .deviceToken(plant.getMember().getDeviceToken()) -// .build() -// ).toList(); -// -// int i = 1; -// log.info("비동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); -// for (NotificationEvent event : events) { -// log.info(i++ + "번째 알림 이벤트"); -// publisher.publishEvent(event); -// } -// log.info("비동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); -// } + int i = 1; + log.info("비동기 알림 테스트 시작. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); + for (NotificationEvent event : events) { + log.info(i++ + "번째 알림 이벤트"); + publisher.publishEvent(event); + } + log.info("비동기 알림 테스트 종료. Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName()); + } } diff --git a/backend/pium/src/main/java/com/official/pium/admin/ui/TestController.java b/backend/pium/src/main/java/com/official/pium/admin/ui/TestController.java index 1d0514a0..e40fdfcf 100644 --- a/backend/pium/src/main/java/com/official/pium/admin/ui/TestController.java +++ b/backend/pium/src/main/java/com/official/pium/admin/ui/TestController.java @@ -2,6 +2,8 @@ import com.official.pium.admin.service.TestService; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -12,15 +14,15 @@ public class TestController { private final TestService testService; -// @GetMapping("/notifications/ramp") -// public ResponseEntity notificationRampTest() { -// testService.sendWaterNotificationAsyncRampTest(); -// return ResponseEntity.ok("비동기 알림 기능 테스트 램프업 성공"); -// } -// -// @GetMapping("/notifications/async") -// public ResponseEntity notificationAsyncTest() { -// testService.sendWaterNotificationAsyncTest(); -// return ResponseEntity.ok("비동기 알림 기능 테스트 성공"); -// } + @GetMapping("/notifications/ramp") + public ResponseEntity notificationRampTest() { + testService.sendWaterNotificationAsyncRampTest(); + return ResponseEntity.ok("비동기 알림 기능 테스트 램프업 성공"); + } + + @GetMapping("/notifications/async") + public ResponseEntity notificationAsyncTest() { + testService.sendWaterNotificationAsyncTest(); + return ResponseEntity.ok("비동기 알림 기능 테스트 성공"); + } }