From 48ee18cccb17070388686cd8d2ea5aa7122c36da Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Tue, 26 Sep 2023 06:40:26 +0800 Subject: [PATCH] fix actuator pom, and add unit test --- .../arklet/core/health/HealthServiceImpl.java | 2 +- .../core/command/handler/BaseHandlerTest.java | 20 +++++++++- .../command/handler/HealthHandlerTest.java | 1 - .../arklet/core/health/HealthTests.java | 37 +++++++++++-------- .../custom/CustomBizManagerService.java | 21 +++++++++-- .../custom/CustomPluginManagerService.java | 23 ++++++++++-- .../core/health/custom/model/CustomBiz.java | 16 ++++++++ .../health/custom/model/CustomPlugin.java | 16 ++++++++ .../arklet/core/util/ConvertUtilsTest.java | 16 ++++++++ 9 files changed, 126 insertions(+), 26 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java index f31f39210..17676b852 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceImpl.java @@ -181,7 +181,7 @@ public Health queryMasterBiz() { return healthBuilder .init() .putHealthData(Constants.MASTER_BIZ_INFO, - BizHealthMeta.createBizMeta(ArkClient.getMasterBiz())).build(); + BizHealthMeta.createBizMeta(ArkClient.getMasterBiz())).build(); } @Override diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java index df937f65d..55d356b22 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.command.handler; import com.alipay.sofa.ark.api.ArkClient; @@ -18,8 +34,8 @@ */ public class BaseHandlerTest extends BaseTest { - public final ClientResponse success = new ClientResponse(); - public final ClientResponse failed = new ClientResponse(); + public final ClientResponse success = new ClientResponse(); + public final ClientResponse failed = new ClientResponse(); public MockedStatic arkClient; @Before diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java index 066368363..e9574d332 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java @@ -27,7 +27,6 @@ import org.junit.Before; import org.junit.Test; - /** * @author lunarscave */ diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthTests.java index 0313061b4..5cd6faf4a 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthTests.java @@ -61,7 +61,7 @@ private void validateBizListHealth(Health health, final List expectedBizLis Object realBiz = realBizList.get(i); Biz expectedBiz = expectedBizList.get(i); Assert.assertTrue(realBiz instanceof BizHealthMeta); - validateBiz((BizHealthMeta)realBiz, expectedBiz); + validateBiz((BizHealthMeta) realBiz, expectedBiz); } } @@ -75,17 +75,18 @@ private void validatePluginListHealth(Health health, final List expected Object realPlugin = realPluginList.get(i); Plugin expectedPlugin = expectedPluginList.get(i); Assert.assertTrue(realPlugin instanceof PluginHealthMeta); - validatePlugin((PluginHealthMeta)realPlugin, expectedPlugin); + validatePlugin((PluginHealthMeta) realPlugin, expectedPlugin); } } - private void validateHealth(Health health, final List expectedBizList, final List expectedPluginList, final Biz expectedMasterBiz) { + private void validateHealth(Health health, final List expectedBizList, + final List expectedPluginList, final Biz expectedMasterBiz) { validateBizListHealth(health, expectedBizList); validatePluginListHealth(health, expectedPluginList); Assert.assertTrue(health.getHealthData().containsKey(Constants.MASTER_BIZ_INFO)); Object realMasterBiz = health.getHealthData().get(Constants.MASTER_BIZ_INFO); Assert.assertTrue(realMasterBiz instanceof BizHealthMeta); - validateBiz((BizHealthMeta)realMasterBiz, expectedMasterBiz); + validateBiz((BizHealthMeta) realMasterBiz, expectedMasterBiz); } private void validateHealth(Health health, final Biz expectedBiz) { @@ -93,7 +94,7 @@ private void validateHealth(Health health, final Biz expectedBiz) { Assert.assertTrue(health.getHealthData().containsKey(Constants.BIZ_INFO)); Object realBiz = health.getHealthData().get(Constants.BIZ_INFO); Assert.assertTrue(realBiz instanceof BizHealthMeta); - validateBiz((BizHealthMeta)realBiz, expectedBiz); + validateBiz((BizHealthMeta) realBiz, expectedBiz); } private void validateHealth(Health health, final Plugin expectedPlugin) { @@ -158,16 +159,22 @@ public void testGetModuleInfo() { final String errorBizName = "errorBiz"; final String errorPluginName = "errorPlugin"; - validateHealth(healthService.queryModuleInfo(), bizService.getBizInOrder(), pluginService.getPluginsInOrder(), bizService.getMasterBiz()); - validateBizListHealth(healthService.queryModuleInfo(Constants.BIZ, null, null), bizService.getBizInOrder()); - validateBizListHealth(healthService.queryModuleInfo(Constants.BIZ, bizName, null), bizService.getBiz(bizName)); - validateHealth(healthService.queryModuleInfo(Constants.BIZ, bizName, bizVersion), bizService.getBiz(bizName, bizVersion)); - validatePluginListHealth(healthService.queryModuleInfo(Constants.PLUGIN, null, null), pluginService.getPluginsInOrder()); - validateHealth(healthService.queryModuleInfo(Constants.PLUGIN, pluginName, null), pluginService.getPluginByName(pluginName)); - validateHealth(healthService.queryModuleInfo(Constants.BIZ, errorBizName, bizVersion), Constants.HEALTH_ERROR, - "can not find biz"); - validateHealth(healthService.queryModuleInfo(Constants.PLUGIN, errorPluginName, null), Constants.HEALTH_ERROR, - "can not find plugin"); + validateHealth(healthService.queryModuleInfo(), bizService.getBizInOrder(), + pluginService.getPluginsInOrder(), bizService.getMasterBiz()); + validateBizListHealth(healthService.queryModuleInfo(Constants.BIZ, null, null), + bizService.getBizInOrder()); + validateBizListHealth(healthService.queryModuleInfo(Constants.BIZ, bizName, null), + bizService.getBiz(bizName)); + validateHealth(healthService.queryModuleInfo(Constants.BIZ, bizName, bizVersion), + bizService.getBiz(bizName, bizVersion)); + validatePluginListHealth(healthService.queryModuleInfo(Constants.PLUGIN, null, null), + pluginService.getPluginsInOrder()); + validateHealth(healthService.queryModuleInfo(Constants.PLUGIN, pluginName, null), + pluginService.getPluginByName(pluginName)); + validateHealth(healthService.queryModuleInfo(Constants.BIZ, errorBizName, bizVersion), + Constants.HEALTH_ERROR, "can not find biz"); + validateHealth(healthService.queryModuleInfo(Constants.PLUGIN, errorPluginName, null), + Constants.HEALTH_ERROR, "can not find plugin"); } @Test diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java index 10dc31c65..bb922d89a 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.health.custom; import com.alipay.sofa.ark.spi.model.Biz; @@ -13,13 +29,12 @@ public class CustomBizManagerService implements BizManagerService { - private final List bizList = Arrays.asList(new Biz[]{ + private final List bizList = Arrays.asList(new Biz[] { new CustomBiz("masterBiz", "masterBizVersion"), new CustomBiz("testBiz1", "testBizVersion1"), new CustomBiz("testBiz1", "testBizVersion2"), new CustomBiz("testBiz2", "testBizVersion2"), - new CustomBiz("testBiz3", "testBizVersion3") - }); + new CustomBiz("testBiz3", "testBizVersion3") }); public Biz getMasterBiz() { return bizList.get(0); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java index 7fc00df3f..57557f878 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.health.custom; import com.alipay.sofa.ark.spi.model.Plugin; @@ -10,10 +26,9 @@ public class CustomPluginManagerService implements PluginManagerService { - private final List pluginList = Arrays.asList(new Plugin[]{ + private final List pluginList = Arrays.asList(new Plugin[] { new CustomPlugin("testPlugin1", "testPluginVersion1"), - new CustomPlugin("testPlugin2", "testPluginVersion2") - }); + new CustomPlugin("testPlugin2", "testPluginVersion2") }); @Override public void registerPlugin(Plugin plugin) { @@ -23,7 +38,7 @@ public void registerPlugin(Plugin plugin) { @Override public Plugin getPluginByName(String s) { Plugin plugin = null; - for (Plugin item: pluginList) { + for (Plugin item : pluginList) { if (s.equals(item.getPluginName())) { plugin = item; break; diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java index 1b687ca88..c7aa82049 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.health.custom.model; import com.alipay.sofa.ark.spi.model.Biz; diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java index 6a0abb1f5..12d5163e9 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.health.custom.model; import com.alipay.sofa.ark.exception.ArkRuntimeException; diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java index 3b5bd26cb..14ab07879 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java @@ -1,3 +1,19 @@ +/* + * 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 com.alipay.sofa.serverless.arklet.core.util; import junit.framework.TestCase;