Copilot commented on code in PR #7580: URL: https://github.com/apache/incubator-seata/pull/7580#discussion_r2265764555
########## server/src/test/java/org/apache/seata/server/spring/listener/ClearServerServicePortInitializer.java: ########## @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.server.spring.listener; + +import org.apache.seata.config.ConfigurationCache; +import org.apache.seata.core.constants.ConfigurationKeys; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; +import org.springframework.boot.context.logging.LoggingApplicationListener; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.event.GenericApplicationListener; +import org.springframework.core.Ordered; +import org.springframework.core.ResolvableType; + +/** + * Application listener to clear the SERVER_SERVICE_PORT_CAMEL system property + * during Spring context environment preparation, refresh, and close events. + * It runs with higher priority than ServerApplicationListener. + */ +public class ClearServerServicePortInitializer implements GenericApplicationListener, Ordered { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Override + public boolean supportsEventType(ResolvableType eventType) { + Class<?> rawClass = eventType.getRawClass(); + if (rawClass == null) { + return false; + } + // Listen to environment preparation, context refresh, and context close events + return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(rawClass) + || ContextClosedEvent.class.isAssignableFrom(rawClass); + } + + @Override + public void onApplicationEvent(ApplicationEvent event) { + ConfigurationCache.clear(); Review Comment: The ConfigurationCache.clear() call should include proper error handling. If this operation fails, it could leave the test environment in an inconsistent state. ```suggestion try { ConfigurationCache.clear(); } catch (Exception e) { log.error("Failed to clear ConfigurationCache", e); } ``` ########## server/src/test/java/org/apache/seata/server/DynamicPortTestConfig.java: ########## @@ -23,6 +23,8 @@ import java.io.IOException; import java.net.ServerSocket; +import static org.apache.seata.common.ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL; Review Comment: The import statement references 'org.apache.seata.common.ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL' but the actual usage in the code references 'org.apache.seata.core.constants.ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL'. This import mismatch will cause a compilation error. ```suggestion import static org.apache.seata.core.constants.ConfigurationKeys.SERVER_SERVICE_PORT_CAMEL; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org