From 0dde2070515ae410248e2741dae4514672ee89d4 Mon Sep 17 00:00:00 2001 From: JamesChenX Date: Wed, 12 Jun 2024 18:46:03 +0800 Subject: [PATCH] Add missing class `NotificationLoggingManager` --- .../notification/service/NotificationService.java | 9 ++++++--- ...ionLogging.java => NotificationLoggingManager.java} | 10 +++++----- .../notification/service/NotificationServiceTests.java | 6 +++++- 3 files changed, 16 insertions(+), 9 deletions(-) rename turms-gateway/src/main/java/im/turms/gateway/infra/logging/{NotificationLogging.java => NotificationLoggingManager.java} (89%) diff --git a/turms-gateway/src/main/java/im/turms/gateway/domain/notification/service/NotificationService.java b/turms-gateway/src/main/java/im/turms/gateway/domain/notification/service/NotificationService.java index 4d44c12955..a262a42894 100644 --- a/turms-gateway/src/main/java/im/turms/gateway/domain/notification/service/NotificationService.java +++ b/turms-gateway/src/main/java/im/turms/gateway/domain/notification/service/NotificationService.java @@ -32,7 +32,7 @@ import im.turms.gateway.domain.session.manager.UserSessionsManager; import im.turms.gateway.domain.session.service.SessionService; import im.turms.gateway.infra.logging.ApiLoggingContext; -import im.turms.gateway.infra.logging.NotificationLogging; +import im.turms.gateway.infra.logging.NotificationLoggingManager; import im.turms.gateway.infra.plugin.extension.NotificationHandler; import im.turms.gateway.infra.proto.SimpleTurmsNotification; import im.turms.gateway.infra.proto.TurmsNotificationParser; @@ -64,6 +64,7 @@ public class NotificationService implements RpcNotificationService { private final ApiLoggingContext apiLoggingContext; private final SessionService sessionService; + private final NotificationLoggingManager notificationLoggingManager; private final PluginManager pluginManager; private final boolean isNotificationLoggingEnabled; @@ -80,10 +81,12 @@ public class NotificationService implements RpcNotificationService { public NotificationService( ApiLoggingContext apiLoggingContext, SessionService sessionService, + NotificationLoggingManager notificationLoggingManager, PluginManager pluginManager, TurmsPropertiesManager propertiesManager) { this.apiLoggingContext = apiLoggingContext; this.sessionService = sessionService; + this.notificationLoggingManager = notificationLoggingManager; this.pluginManager = pluginManager; isNotificationLoggingEnabled = propertiesManager.getLocalProperties() .getGateway() @@ -182,7 +185,7 @@ public Mono> sendNotificationToLocalClients( int notificationBytes = notificationData.readableBytes(); try (TracingCloseableContext ignored = TracingContext.getCloseableContext(context)) { - NotificationLogging.log(notification, + notificationLoggingManager.log(notification, notificationBytes, recipientCount, recipientCount - offlineRecipientCount); @@ -230,4 +233,4 @@ private void invokeExtensionPointHandlers( .subscribe(null, LOGGER::error); } -} +} \ No newline at end of file diff --git a/turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLogging.java b/turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLoggingManager.java similarity index 89% rename from turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLogging.java rename to turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLoggingManager.java index 58fd8cc486..b888dc5382 100644 --- a/turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLogging.java +++ b/turms-gateway/src/main/java/im/turms/gateway/infra/logging/NotificationLoggingManager.java @@ -18,9 +18,11 @@ package im.turms.gateway.infra.logging; import io.netty.buffer.ByteBuf; +import org.springframework.stereotype.Component; import im.turms.gateway.infra.proto.SimpleTurmsNotification; import im.turms.server.common.infra.lang.NumberFormatter; +import im.turms.server.common.infra.logging.BaseNotificationLoggingManager; import im.turms.server.common.infra.netty.ByteBufUtil; import static im.turms.server.common.infra.logging.CommonLogger.LOG_FIELD_DELIMITER; @@ -29,12 +31,10 @@ /** * @author James Chen */ -public final class NotificationLogging { +@Component +public class NotificationLoggingManager extends BaseNotificationLoggingManager { - private NotificationLogging() { - } - - public static void log( + public void log( SimpleTurmsNotification notification, int notificationBytes, int recipientCount, diff --git a/turms-gateway/src/test/java/unit/im/turms/gateway/domain/notification/service/NotificationServiceTests.java b/turms-gateway/src/test/java/unit/im/turms/gateway/domain/notification/service/NotificationServiceTests.java index c5c49c4c50..684393d17e 100644 --- a/turms-gateway/src/test/java/unit/im/turms/gateway/domain/notification/service/NotificationServiceTests.java +++ b/turms-gateway/src/test/java/unit/im/turms/gateway/domain/notification/service/NotificationServiceTests.java @@ -34,6 +34,7 @@ import im.turms.gateway.domain.session.manager.UserSessionsManager; import im.turms.gateway.domain.session.service.SessionService; import im.turms.gateway.infra.logging.ApiLoggingContext; +import im.turms.gateway.infra.logging.NotificationLoggingManager; import im.turms.gateway.infra.plugin.extension.NotificationHandler; import im.turms.server.common.access.client.dto.constant.DeviceType; import im.turms.server.common.access.client.dto.request.TurmsRequestTypePool; @@ -60,7 +61,7 @@ void constructor_shouldReturnInstance() { when(propertiesManager.getLocalProperties()).thenReturn(new TurmsProperties()); NotificationService notificationService = - new NotificationService(null, null, null, propertiesManager); + new NotificationService(null, null, null, null, propertiesManager); assertThat(notificationService).isNotNull(); } @@ -132,6 +133,8 @@ private NotificationService newOutboundMessageService(UserSessionsManager userSe ApiLoggingContext apiLoggingContext = mock(ApiLoggingContext.class); when(apiLoggingContext.shouldLogNotification(any())).thenReturn(true); + NotificationLoggingManager notificationLoggingManager = + mock(NotificationLoggingManager.class); PluginManager pluginManager = mock(PluginManager.class); TurmsPropertiesManager propertiesManager = mock(TurmsPropertiesManager.class); @@ -142,6 +145,7 @@ private NotificationService newOutboundMessageService(UserSessionsManager userSe return new NotificationService( apiLoggingContext, sessionService, + notificationLoggingManager, pluginManager, propertiesManager); }