Skip to content

Commit d13c921

Browse files
committed
fix test and format
1 parent 38cfd9b commit d13c921

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

koupleless-base-plugin/src/main/java/com/alipay/sofa/koupleless/plugin/ServerlessRuntimeActivator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ private void registerEventHandler(final PluginContext context) {
4141
EventAdminService eventAdminService = context.referenceService(EventAdminService.class)
4242
.getService();
4343

44-
eventAdminService.register(new StopLoggerCxtAfterBizStopEventHandler());
4544
eventAdminService.register(new BizUninstallEventHandler());
4645
eventAdminService.register(new BeforeBizStartupEventHandler());
4746

4847
// 清理用户主动托管给 Serverless 运行时的 ExecutorService (含线程池), Timer 和 Thread.
4948
eventAdminService.register(new ShutdownExecutorServicesOnUninstallEventHandler());
5049
eventAdminService.register(new CancelTimersOnUninstallEventHandler());
5150
eventAdminService.register(new ForceStopThreadsOnUninstallEventHandler());
51+
eventAdminService.register(new StopLoggerCxtAfterBizStopEventHandler());
5252
}
5353

5454
/** {@inheritDoc} */

koupleless-base-plugin/src/main/java/com/alipay/sofa/koupleless/plugin/manager/handler/StopLoggerCxtAfterBizStopEventHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public class StopLoggerCxtAfterBizStopEventHandler implements EventHandler<Befor
4242
private static final Logger LOGGER = getLogger(
4343
StopLoggerCxtAfterBizStopEventHandler.class);
4444

45-
public static final String LOGGER_CONTEXT_STOP_TIMEOUT_MILLISECOND = "com.alipay.koupleless.loggerContext.stop.timeout.millisecond";
46-
public static final String LOG4J2_FACTORY_CLASS_NAME = "org.apache.logging.log4j.core.impl.Log4jContextFactory";
47-
45+
public static final String LOGGER_CONTEXT_STOP_TIMEOUT_MILLISECOND = "com.alipay.koupleless.loggerContext.stop.timeout.millisecond";
46+
public static final String LOG4J2_FACTORY_CLASS_NAME = "org.apache.logging.log4j.core.impl.Log4jContextFactory";
4847

4948
@Override
5049
public void handleEvent(BeforeBizStopEvent beforeBizStopEvent) {

koupleless-base-plugin/src/test/java/com/alipay/sofa/koupleless/plugin/ServerlessRuntimeActivatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public List<ServiceReference> referenceServices(ServiceFilter serviceFilter) {
131131
};
132132

133133
serverlessRuntimeActivator.start(pluginContext);
134-
assertEquals(5, eventhandlers.size());
134+
assertEquals(6, eventhandlers.size());
135135
assertEquals(ShutdownExecutorServicesOnUninstallEventHandler.class,
136136
eventhandlers.get(2).getClass());
137137
assertEquals(CancelTimersOnUninstallEventHandler.class, eventhandlers.get(3).getClass());
@@ -149,7 +149,7 @@ public void testRegisterCount() {
149149
when(pluginContext.referenceService(EventAdminService.class)).thenReturn((impl));
150150

151151
serverlessRuntimeActivator.start(pluginContext);
152-
verify(eventAdminService, times(5)).register(any());
152+
verify(eventAdminService, times(6)).register(any());
153153
}
154154

155155
@Test

koupleless-base-plugin/src/test/java/com/alipay/sofa/koupleless/plugin/manager/handler/StopLoggerCxtAfterBizStopEventHandlerTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
* @author gaowh
4343
*/
4444
public class StopLoggerCxtAfterBizStopEventHandlerTest {
45-
private final ClassLoader bizClassLoader = currentThread()
46-
.getContextClassLoader();
45+
private final ClassLoader bizClassLoader = currentThread()
46+
.getContextClassLoader();
4747
private static MockedStatic<PropertiesUtil> propertiesUtil;
4848

49-
private static final ClassLoader rootClassLoader = new ClassLoader() {};
49+
private static final ClassLoader rootClassLoader = new ClassLoader() {
50+
};
5051

5152
@BeforeClass
5253
public static void beforeClass() {
@@ -85,14 +86,16 @@ public void testCloseLoggerContext() {
8586
Log4jContextFactory contextFactory = (Log4jContextFactory) LogManager.getFactory();
8687
String name = contextFactory.getSelector().getLoggerContexts().get(0).getName();
8788
LogManager.getContext(bizClassLoader, false);
88-
assertEquals("Should have two logger context initially", 2, contextFactory.getSelector().getLoggerContexts().size());
89+
assertEquals("Should have two logger context initially", 2,
90+
contextFactory.getSelector().getLoggerContexts().size());
8991
BizModel bizModel = new BizModel();
9092
bizModel.setClassLoader(bizClassLoader);
9193
BeforeBizStopEvent event = new BeforeBizStopEvent(bizModel);
9294
handler.handleEvent(event);
9395
int afterSize = contextFactory.getSelector().getLoggerContexts().size();
9496
assertEquals("only one logger context should be closed", afterSize, 1);
95-
assertEquals("active logger context name is ", name, contextFactory.getSelector().getLoggerContexts().get(0).getName());
97+
assertEquals("active logger context name is ", name,
98+
contextFactory.getSelector().getLoggerContexts().get(0).getName());
9699
}
97100

98101
@Test

0 commit comments

Comments
 (0)