From 34e9cce05adba32e6ec7b0fd4e4c151bb2bf8027 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Sat, 9 Sep 2023 22:28:19 +0800 Subject: [PATCH 01/21] Increase the usage of MetaSpace in computing --- .../core/command/record/ProcessRecord.java | 16 ++++++++++++---- .../core/command/record/ProcessRecordHolder.java | 10 +++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index d3e1f62ff..dddf66db6 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -22,12 +22,10 @@ import lombok.Getter; import lombok.Setter; +import java.lang.management.MemoryPoolMXBean; import java.util.Date; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.EXECUTING; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.FAILED; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.INITIALIZED; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.SUCCEEDED; +import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.*; /** * @author: yuanyuan @@ -39,6 +37,8 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); + private MemoryPoolMXBean metaSpaceMXBean; + private String requestId; private ArkBizMeta arkBizMeta; @@ -55,14 +55,20 @@ public class ProcessRecord { private Date startTime; + private long startSpace; + private long startTimestamp; private Date endTime; + private long endSpace; + private long endTimestamp; private long elapsedTime; + private long elapsedSpace; + public enum Status { INITIALIZED("INITIALIZED"), @@ -89,6 +95,8 @@ public void setName(String name) { } public void markFinishTime() { + setEndSpace(getMetaSpaceMXBean().getUsage().getUsed()); + setElapsedSpace(getEndSpace() - getStartSpace()); Date date = new Date(); setEndTime(date); setEndTimestamp(date.getTime()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 01ccd4b75..61570f3e5 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -16,10 +16,11 @@ */ package com.alipay.sofa.serverless.arklet.core.command.record; -import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta; import com.alipay.sofa.serverless.arklet.core.command.meta.bizops.ArkBizMeta; import org.apache.commons.lang3.StringUtils; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -58,10 +59,17 @@ public static List getProcessRecordsByStatus(String status) { public static ProcessRecord createProcessRecord(String rid, ArkBizMeta arkBizMeta) { ProcessRecord pr = new ProcessRecord(); + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + MemoryPoolMXBean metaSpaceMXBean = null; + for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + if (memoryPoolMXBean.getName().equals("Metaspace")) + metaSpaceMXBean = memoryPoolMXBean; pr.setRequestId(rid); pr.setArkBizMeta(arkBizMeta); pr.setStatus(INITIALIZED); Date date = new Date(); + pr.setMetaSpaceMXBean(metaSpaceMXBean); + pr.setStartSpace(metaSpaceMXBean.getUsage().getUsed()); pr.setStartTime(date); pr.setStartTimestamp(date.getTime()); processRecords.put(rid, pr); From bf47eef5f20a729c69f7490eb8eca7b209147d60 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Thu, 14 Sep 2023 23:44:24 +0800 Subject: [PATCH 02/21] optimize code --- .../{PluginModel.java => PluginInfo.java} | 2 +- .../arklet/core/health/HealthService.java | 58 +++++++++++++++++-- .../arklet/core/health/HealthServiceImpl.java | 26 ++++----- .../core/health/indicator/CpuIndicator.java | 4 +- ...rkletBaseIndicator.java => Indicator.java} | 17 +++++- .../core/health/indicator/JvmIndicator.java | 4 +- .../arklet/core/util/ConvertUtils.java | 17 ++++-- .../core/command/HealthHandlerTest.java | 27 +++++++++ .../arklet/core/health/HealthTests.java | 2 +- .../core/health/custom/CustomIndicator.java | 4 +- .../core/health/indicator/IndicatorTests.java | 4 +- .../indicator/MasterBizHealthIndicator.java | 4 +- 12 files changed, 130 insertions(+), 39 deletions(-) rename arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/{PluginModel.java => PluginInfo.java} (98%) rename arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/{ArkletBaseIndicator.java => Indicator.java} (81%) create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginModel.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginInfo.java similarity index 98% rename from arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginModel.java rename to arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginInfo.java index e22540171..72fc52fc1 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginModel.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/model/PluginInfo.java @@ -19,7 +19,7 @@ /** * @author Lunarscave */ -public class PluginModel { +public class PluginInfo { private String pluginName; diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthService.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthService.java index 5716525e7..328a38d09 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthService.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/HealthService.java @@ -17,33 +17,81 @@ package com.alipay.sofa.serverless.arklet.core.health; import com.alipay.sofa.serverless.arklet.core.ArkletComponent; -import com.alipay.sofa.serverless.arklet.core.health.indicator.ArkletBaseIndicator; +import com.alipay.sofa.serverless.arklet.core.health.indicator.Indicator; import com.alipay.sofa.serverless.arklet.core.health.model.Health; import com.alipay.sofa.serverless.arklet.core.command.builtin.model.BizInfo; -import com.alipay.sofa.serverless.arklet.core.command.builtin.model.PluginModel; +import com.alipay.sofa.serverless.arklet.core.command.builtin.model.PluginInfo; /** * @author Lunarscave */ public interface HealthService extends ArkletComponent { + /** + * get system health with all indicators + * @return health with all details of indicators + */ Health getHealth(); + /** + * get system health with indicator id + * @param indicatorId indicator ids + * @return health with indicator detail + */ Health getHealth(String indicatorId); + /** + * get system health with indicator ids + * @param indicatorIds indicator ids + * @return health with indicator detail(s) + */ Health getHealth(String[] indicatorIds); + /** + * query all module info + * @return health with module infos + */ Health queryModuleInfo(); + /** + * query module info with type, name and version + * @param type module type, must in ("biz", "plugin") + * @param name module name + * @param version module version + * @return health with module info(s) + */ Health queryModuleInfo(String type, String name, String version); + /** + * query biz info + * @param bizInfo input plugin info + * @return health with biz info(list) + */ Health queryModuleInfo(BizInfo bizInfo); - Health queryModuleInfo(PluginModel pluginModel); + /** + * query plugin info + * @param pluginInfo input plugin info + * @return health with plugin info(list) + */ + Health queryModuleInfo(PluginInfo pluginInfo); + /** + * query master biz info + * @return health with master biz + */ Health queryMasterBiz(); - ArkletBaseIndicator getIndicator(String indicatorId); + /** + * get indicator by indicator id + * @param indicatorId indicator id + * @return indicator or null + */ + Indicator getIndicator(String indicatorId); - void registerIndicator(ArkletBaseIndicator arkletBaseIndicator); + /** + * register indicator + * @param indicator input indicator + */ + void registerIndicator(Indicator indicator); } 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 ceee9a51c..dc4fb1b7a 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 @@ -24,7 +24,7 @@ import com.alipay.sofa.ark.spi.model.Biz; import com.alipay.sofa.common.utils.ArrayUtil; import com.alipay.sofa.serverless.arklet.core.command.builtin.model.BizInfo; -import com.alipay.sofa.serverless.arklet.core.health.indicator.ArkletBaseIndicator; +import com.alipay.sofa.serverless.arklet.core.health.indicator.Indicator; import com.alipay.sofa.serverless.arklet.core.health.indicator.CpuIndicator; import com.alipay.sofa.serverless.arklet.core.health.indicator.JvmIndicator; import com.alipay.sofa.serverless.arklet.core.health.model.BizHealthMeta; @@ -32,7 +32,7 @@ import com.alipay.sofa.serverless.arklet.core.health.model.Health; import com.alipay.sofa.serverless.arklet.core.health.model.Health.HealthBuilder; import com.alipay.sofa.serverless.arklet.core.health.model.PluginHealthMeta; -import com.alipay.sofa.serverless.arklet.core.command.builtin.model.PluginModel; +import com.alipay.sofa.serverless.arklet.core.command.builtin.model.PluginInfo; import com.alipay.sofa.serverless.arklet.core.common.log.ArkletLogger; import com.alipay.sofa.serverless.arklet.core.common.log.ArkletLoggerFactory; import com.google.inject.Singleton; @@ -53,7 +53,7 @@ public class HealthServiceImpl implements HealthService { .getDefaultLogger(); private final HealthBuilder healthBuilder = new HealthBuilder(); - private final Map indicators = new ConcurrentHashMap<>(3); + private final Map indicators = new ConcurrentHashMap<>(3); @Override public void init() { @@ -68,7 +68,7 @@ public void destroy() { @Override public Health getHealth() { HealthBuilder builder = new HealthBuilder(); - for (ArkletBaseIndicator indicator : this.indicators.values()) { + for (Indicator indicator : this.indicators.values()) { builder.putAllHealthData(indicator.getHealthModel(healthBuilder)); } return builder.build(); @@ -105,7 +105,7 @@ public Health queryModuleInfo() { HealthBuilder builder = new HealthBuilder(); return builder.init().putAllHealthData(queryMasterBiz()) .putAllHealthData(queryModuleInfo(new BizInfo())) - .putAllHealthData(queryModuleInfo(new PluginModel())).build(); + .putAllHealthData(queryModuleInfo(new PluginInfo())).build(); } @Override @@ -121,10 +121,10 @@ public Health queryModuleInfo(String type, String name, String version) { builder.putAllHealthData(queryModuleInfo(bizInfo)); } if (StringUtils.isEmpty(type) || Constants.PLUGIN.equals(type)) { - PluginModel pluginModel = new PluginModel(); - pluginModel.setPluginName(name); - pluginModel.setPluginVersion(version); - builder.putAllHealthData(queryModuleInfo(pluginModel)); + PluginInfo pluginInfo = new PluginInfo(); + pluginInfo.setPluginName(name); + pluginInfo.setPluginVersion(version); + builder.putAllHealthData(queryModuleInfo(pluginInfo)); } } catch (Throwable e) { builder.putErrorData(Constants.HEALTH_ERROR, e.getMessage()); @@ -158,8 +158,8 @@ public Health queryModuleInfo(BizInfo bizInfo) { } @Override - public Health queryModuleInfo(PluginModel pluginModel) { - String pluginName = pluginModel.getPluginName(); + public Health queryModuleInfo(PluginInfo pluginInfo) { + String pluginName = pluginInfo.getPluginName(); healthBuilder.init(); try { if (StringUtils.isEmpty(pluginName)) { @@ -187,12 +187,12 @@ public Health queryMasterBiz() { } @Override - public ArkletBaseIndicator getIndicator(String indicatorId) { + public Indicator getIndicator(String indicatorId) { return indicators.get(indicatorId); } @Override - public void registerIndicator(ArkletBaseIndicator indicator) { + public void registerIndicator(Indicator indicator) { this.indicators.put(indicator.getIndicatorId(), indicator); LOGGER.info("register indicator " + indicator.getIndicatorId()); } diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/CpuIndicator.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/CpuIndicator.java index 42949c489..87e02afe1 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/CpuIndicator.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/CpuIndicator.java @@ -19,8 +19,6 @@ import com.alipay.sofa.serverless.arklet.core.health.model.Constants; import oshi.SystemInfo; import oshi.hardware.CentralProcessor; -import oshi.util.GlobalConfig; -import oshi.util.Util; import java.util.HashMap; import java.util.HashSet; @@ -31,7 +29,7 @@ /** * @author Lunarscave */ -public class CpuIndicator extends ArkletBaseIndicator { +public class CpuIndicator extends Indicator { private final CpuIndicatorHandler cpuIndicatorHandler; diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/Indicator.java similarity index 81% rename from arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java rename to arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/Indicator.java index c0deaad59..cd2a44256 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/Indicator.java @@ -24,20 +24,33 @@ /** * @author Lunarscave */ -public abstract class ArkletBaseIndicator { +public abstract class Indicator { private final String indicatorId; - public ArkletBaseIndicator(String indicatorId) { + public Indicator(String indicatorId) { this.indicatorId = indicatorId; } + /** + * get health details + * @return a map of health details + */ protected abstract Map getHealthDetails(); + /** + * get indicator id + * @return indicator id + */ public String getIndicatorId() { return indicatorId; } + /** + * get health model + * @param builder input health builder + * @return health model + */ public Health getHealthModel(HealthBuilder builder) { return builder.init().putHealthData(getIndicatorId(), getHealthDetails()).build(); } diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/JvmIndicator.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/JvmIndicator.java index 3255219eb..9972572b4 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/JvmIndicator.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/JvmIndicator.java @@ -31,7 +31,7 @@ /** * @author Lunarscave */ -public class JvmIndicator extends ArkletBaseIndicator { +public class JvmIndicator extends Indicator { private final JvmIndicatorHandler jvmIndicatorHandler; @@ -129,7 +129,7 @@ public long getFreeMemory() { } public double getDuration() { - return ConvertUtils.millisecond2Second(new Date(runtimeMxBean.getStartTime())); + return ConvertUtils.getDurationSecond(new Date(runtimeMxBean.getStartTime())); } public long getInitHeapMemory() { diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtils.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtils.java index 7129449c9..b85bd92c4 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtils.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtils.java @@ -24,16 +24,21 @@ */ public class ConvertUtils { + /** + * convert bytes(B) to megabyte(MB) + * @param bytes input byte(B) value + * @return megabyte(MB) + */ public static double bytes2Megabyte(Long bytes) { return ((double) bytes) / 1024 / 1024; } - public static String endDate2Duration(Date date) { - long duration = System.currentTimeMillis() - date.getTime(); - return new SimpleDateFormat("HH-mm-ss").format(duration); - } - - public static double millisecond2Second(Date date) { + /** + * get duration from param date till now and change to second(s) + * @param date input date + * @return output duration(s) + */ + public static double getDurationSecond(Date date) { return ((double) System.currentTimeMillis() - date.getTime()) / 1000; } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java new file mode 100644 index 000000000..8c2ec0dc8 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java @@ -0,0 +1,27 @@ +package com.alipay.sofa.serverless.arklet.core.command; + +import com.alipay.sofa.serverless.arklet.core.BaseTest; +import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; +import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler; +import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler.Input; +import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; +import org.junit.Test; + +/** + * @author lunarscave + */ +public class HealthHandlerTest extends BaseTest { + + private void testValidate(Input input) throws CommandValidationException{ + HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); + handler.validate(input); + } + + @Test(expected = CommandValidationException.class) + public void testValidate_InvalidType() throws CommandValidationException { + Input input = new Input(); + input.setType("non type"); + testValidate(input); + } + +} 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 40be30153..bc2de39dd 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 @@ -50,7 +50,6 @@ private void validateHealth(Health health, String errorCode, String errorMessage @Before public void initHealthService() throws IOException { this.healthService = ArkletComponentRegistry.getHealthServiceInstance(); - // ClassLoader cl = Thread.currentThread().getContextClassLoader(); // URL testBiz = cl.getResource("test-biz.jar"); // BizOperation bizOperation = new BizOperation(); @@ -82,4 +81,5 @@ public void testIndicators() { Assert.assertNotNull(healthService.getIndicator(Constants.CPU)); Assert.assertNotNull(healthService.getIndicator(Constants.JVM)); } + } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomIndicator.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomIndicator.java index fdfef9642..80f2400c4 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomIndicator.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomIndicator.java @@ -16,12 +16,12 @@ */ package com.alipay.sofa.serverless.arklet.core.health.custom; -import com.alipay.sofa.serverless.arklet.core.health.indicator.ArkletBaseIndicator; +import com.alipay.sofa.serverless.arklet.core.health.indicator.Indicator; import java.util.HashMap; import java.util.Map; -public class CustomIndicator extends ArkletBaseIndicator { +public class CustomIndicator extends Indicator { public CustomIndicator() { super("custom"); } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/indicator/IndicatorTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/indicator/IndicatorTests.java index 3d01e1107..34c4e1a1b 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/indicator/IndicatorTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/indicator/IndicatorTests.java @@ -26,7 +26,7 @@ public class IndicatorTests { @Test public void testCpuIndicator() { - ArkletBaseIndicator indicator = new CpuIndicator(); + Indicator indicator = new CpuIndicator(); final String[] indicatorMetrics = new String[] { "count", "type", "total used (%)", "user used (%)", "system used (%)", "free (%)" }; final String indicatorId = "cpu"; @@ -41,7 +41,7 @@ public void testCpuIndicator() { @Test public void testJvmIndicator() { - ArkletBaseIndicator indicator = new JvmIndicator(); + Indicator indicator = new JvmIndicator(); final String[] indicatorMetrics = new String[] { "java version", "java home", "total memory(M)", "max memory(M)", "free memory(M)", "run time(s)", "init heap memory(M)", "used heap memory(M)", "committed heap memory(M)", diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java index 819b3fe48..011d1e1b5 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/extension/indicator/MasterBizHealthIndicator.java @@ -16,7 +16,7 @@ */ package com.alipay.sofa.serverless.arklet.springboot.starter.health.extension.indicator; -import com.alipay.sofa.serverless.arklet.core.health.indicator.ArkletBaseIndicator; +import com.alipay.sofa.serverless.arklet.core.health.indicator.Indicator; import com.alipay.sofa.serverless.arklet.core.health.model.Constants; import com.alipay.sofa.serverless.arklet.core.util.AssertUtils; import org.springframework.boot.availability.ApplicationAvailability; @@ -27,7 +27,7 @@ /** * @author Lunarscave */ -public class MasterBizHealthIndicator extends ArkletBaseIndicator { +public class MasterBizHealthIndicator extends Indicator { private ApplicationAvailability applicationAvailability; From 6463ab5a6d0e498eca745e86dadcccc3e827168f Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Fri, 15 Sep 2023 19:22:08 +0800 Subject: [PATCH 03/21] optimize code --- .../springboot/starter/health/HealthAutoConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java index 1fc02e4ef..962b99875 100644 --- a/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java +++ b/arklet/arklet-springboot-starter/src/main/java/com/alipay/sofa/serverless/arklet/springboot/starter/health/HealthAutoConfiguration.java @@ -66,7 +66,7 @@ public ArkHealthCodeEndpoint arkHealthCodeEndpoint() { } @Bean - @DependsOn("componentRegistry") + @DependsOn("arkletComponentRegistry") public MasterBizHealthIndicator masterBizHealthIndicator() { MasterBizHealthIndicator masterBizHealthIndicator = new MasterBizHealthIndicator(); masterBizHealthIndicator.setApplicationAvailability(context From 100c7ce37bc710290819116a27533461f40ace37 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Fri, 15 Sep 2023 19:28:51 +0800 Subject: [PATCH 04/21] optimize code --- .../arklet/core/health/HealthServiceImpl.java | 5 ++--- .../arklet/core/command/HealthHandlerTest.java | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 4 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 dc4fb1b7a..2c63ba77a 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 @@ -49,9 +49,8 @@ @Singleton public class HealthServiceImpl implements HealthService { - private static final ArkletLogger LOGGER = ArkletLoggerFactory - .getDefaultLogger(); - private final HealthBuilder healthBuilder = new HealthBuilder(); + private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); + private final HealthBuilder healthBuilder = new HealthBuilder(); private final Map indicators = new ConcurrentHashMap<>(3); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java index 8c2ec0dc8..cae78df33 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.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; import com.alipay.sofa.serverless.arklet.core.BaseTest; @@ -12,7 +28,7 @@ */ public class HealthHandlerTest extends BaseTest { - private void testValidate(Input input) throws CommandValidationException{ + private void testValidate(Input input) throws CommandValidationException { HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); handler.validate(input); } From a832a2012370562f7dc610f601c43cff7f60c54c Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Fri, 15 Sep 2023 19:36:18 +0800 Subject: [PATCH 05/21] fix test bug --- .../serverless/arklet/core/component/ComponentRegistryTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/component/ComponentRegistryTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/component/ComponentRegistryTest.java index f68cad083..f0ce7a9fc 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/component/ComponentRegistryTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/component/ComponentRegistryTest.java @@ -29,6 +29,7 @@ public class ComponentRegistryTest { @Test public void run() { ArkletComponentRegistry registry = new ArkletComponentRegistry(); + registry.destroyComponents(); registry.initComponents(); Assert.assertNotNull(ArkletComponentRegistry.getCommandServiceInstance()); Assert.assertNotNull(ArkletComponentRegistry.getOperationServiceInstance()); From 9dfd8a905dd336fd7dfedd1c053e1a6feafad250 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Tue, 19 Sep 2023 22:41:48 +0800 Subject: [PATCH 06/21] fix import --- .../serverless/arklet/core/command/record/ProcessRecord.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index dddf66db6..caf6c3e24 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -25,7 +25,10 @@ import java.lang.management.MemoryPoolMXBean; import java.util.Date; -import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.*; +import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.EXECUTING; +import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.FAILED; +import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.INITIALIZED; +import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.SUCCEEDED; /** * @author: yuanyuan From d0a68a8c3bd3bf4a915cd539380fbd8331e82df3 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 17:21:47 +0800 Subject: [PATCH 07/21] add test --- .../arklet/core/command/CommandTests.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index 452294aea..d759a2886 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -16,7 +16,10 @@ */ package com.alipay.sofa.serverless.arklet.core.command; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; import java.util.HashMap; +import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSONObject; @@ -29,6 +32,7 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; +import com.sun.webkit.Timer; import org.junit.Assert; import org.junit.Test; @@ -73,6 +77,26 @@ public void testInstallHandler() throws InterruptedException { Map map1 = JSONObject.parseObject(JSONObject.toJSONString(input1), Map.class); Output output1 = commandService.process(BuiltinCommand.QUERY_BIZ_OPS.getId(), map1); Assert.assertNotNull(output1); + ProcessRecord processRecord1 = (ProcessRecord) output1.getData(); + Assert.assertNotNull(processRecord1); + Assert.assertNotNull(processRecord1.getEndSpace()); + Assert.assertNotNull(processRecord1.getEndTime()); + } + + @Test + public void testResourceStatistics() throws Exception { + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + MemoryPoolMXBean metaSpaceMXBean = null; + for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + if (memoryPoolMXBean.getName().equals("Metaspace")) + metaSpaceMXBean = memoryPoolMXBean; + Long beforeSpace = metaSpaceMXBean.getUsage().getUsed(); + Long beforeTime = System.currentTimeMillis(); +// 运行指令 + Long time = System.currentTimeMillis() - beforeTime; + Long usedSpace = metaSpaceMXBean.getUsage().getUsed() - beforeSpace; + System.out.println(time); + System.out.println(usedSpace); } } From ccccf62a35c9a9eb09c605a388263e22309b65eb Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 20:48:52 +0800 Subject: [PATCH 08/21] fix --- .../core/command/record/ProcessRecord.java | 2 +- .../arklet/core/health/HealthServiceImpl.java | 5 ++--- .../arklet/core/command/CommandTests.java | 20 +++---------------- .../core/command/HealthHandlerTest.java | 18 ++++++++++++++++- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index caf6c3e24..06bd83ce9 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -40,7 +40,7 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); - private MemoryPoolMXBean metaSpaceMXBean; + private MemoryPoolMXBean metaSpaceMXBean; private String requestId; 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 dc4fb1b7a..2c63ba77a 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 @@ -49,9 +49,8 @@ @Singleton public class HealthServiceImpl implements HealthService { - private static final ArkletLogger LOGGER = ArkletLoggerFactory - .getDefaultLogger(); - private final HealthBuilder healthBuilder = new HealthBuilder(); + private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); + private final HealthBuilder healthBuilder = new HealthBuilder(); private final Map indicators = new ConcurrentHashMap<>(3); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index d759a2886..8492026d2 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -18,6 +18,8 @@ import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,7 +34,7 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; -import com.sun.webkit.Timer; + import org.junit.Assert; import org.junit.Test; @@ -83,20 +85,4 @@ public void testInstallHandler() throws InterruptedException { Assert.assertNotNull(processRecord1.getEndTime()); } - @Test - public void testResourceStatistics() throws Exception { - List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); - MemoryPoolMXBean metaSpaceMXBean = null; - for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) - if (memoryPoolMXBean.getName().equals("Metaspace")) - metaSpaceMXBean = memoryPoolMXBean; - Long beforeSpace = metaSpaceMXBean.getUsage().getUsed(); - Long beforeTime = System.currentTimeMillis(); -// 运行指令 - Long time = System.currentTimeMillis() - beforeTime; - Long usedSpace = metaSpaceMXBean.getUsage().getUsed() - beforeSpace; - System.out.println(time); - System.out.println(usedSpace); - } - } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java index 8c2ec0dc8..cae78df33 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.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; import com.alipay.sofa.serverless.arklet.core.BaseTest; @@ -12,7 +28,7 @@ */ public class HealthHandlerTest extends BaseTest { - private void testValidate(Input input) throws CommandValidationException{ + private void testValidate(Input input) throws CommandValidationException { HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); handler.validate(input); } From 31262feb26c713447a4c34da1cc92d9d9458a0a1 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Wed, 20 Sep 2023 20:50:14 +0800 Subject: [PATCH 09/21] fix --- .../arklet/core/command/CommandTests.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index 8492026d2..c68a89768 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -16,16 +16,7 @@ */ package com.alipay.sofa.serverless.arklet.core.command; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryPoolMXBean; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import com.alibaba.fastjson.JSONObject; - import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler; @@ -34,10 +25,12 @@ import com.alipay.sofa.serverless.arklet.core.command.custom.CustomCommandHandler; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; - import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + /** * @author mingmen * @date 2023/6/26 From a3dccdb13bc20ae00f4e7bfe540a5b2fff5914f9 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Thu, 21 Sep 2023 22:42:12 +0800 Subject: [PATCH 10/21] fix --- .../core/command/CommandServiceImpl.java | 4 ++ .../core/command/record/MetaSpaceRecord.java | 40 +++++++++++++++++++ .../core/command/record/ProcessRecord.java | 3 -- .../command/record/ProcessRecordHolder.java | 7 ---- .../arklet/core/command/CommandTests.java | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java index b566a3c75..037a0c99f 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java @@ -41,6 +41,7 @@ import com.alipay.sofa.serverless.arklet.core.command.meta.Command; import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; +import com.alipay.sofa.serverless.arklet.core.command.record.MetaSpaceRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecordHolder; import com.alipay.sofa.serverless.arklet.core.common.exception.ArkletInitException; @@ -110,6 +111,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept ArkBizMeta arkBizMeta = (ArkBizMeta) input; AssertUtils.assertNotNull(arkBizMeta, "when execute bizOpsHandler, arkBizMeta should not be null"); + final MetaSpaceRecord metaSpaceRecord = new MetaSpaceRecord(); if (arkBizMeta.isAsync()) { String requestId = arkBizMeta.getRequestId(); if (ProcessRecordHolder.getProcessRecord(requestId) != null) { @@ -127,6 +129,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail("command conflict, exist unfinished command for this biz"); } else { processRecord.start(); + processRecord.setStartSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); Output output = handler.handle(input); if (output.success()) { processRecord.success(); @@ -138,6 +141,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail(throwable.getMessage(), throwable); LOGGER.error("Error happened when handling command, requestId=" + requestId, throwable); } finally { + processRecord.setEndSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); processRecord.markFinishTime(); BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java new file mode 100644 index 000000000..3da1e1e74 --- /dev/null +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java @@ -0,0 +1,40 @@ +/* + * 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.record; + +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryPoolMXBean; +import java.util.List; + +/** + * @author sususama + * @since 2023-09-21 + */ + +public class MetaSpaceRecord { + private static MemoryPoolMXBean metaSpaceMXBean; + static { + List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); + for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) + if (memoryPoolMXBean.getName().equals("Metaspace")) + metaSpaceMXBean = memoryPoolMXBean; + } + + public MemoryPoolMXBean getMetaSpaceMXBean() { + return metaSpaceMXBean; + } +} diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index 06bd83ce9..46df73911 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -40,8 +40,6 @@ public class ProcessRecord { private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); - private MemoryPoolMXBean metaSpaceMXBean; - private String requestId; private ArkBizMeta arkBizMeta; @@ -98,7 +96,6 @@ public void setName(String name) { } public void markFinishTime() { - setEndSpace(getMetaSpaceMXBean().getUsage().getUsed()); setElapsedSpace(getEndSpace() - getStartSpace()); Date date = new Date(); setEndTime(date); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 61570f3e5..24899fc41 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -59,17 +59,10 @@ public static List getProcessRecordsByStatus(String status) { public static ProcessRecord createProcessRecord(String rid, ArkBizMeta arkBizMeta) { ProcessRecord pr = new ProcessRecord(); - List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); - MemoryPoolMXBean metaSpaceMXBean = null; - for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) - if (memoryPoolMXBean.getName().equals("Metaspace")) - metaSpaceMXBean = memoryPoolMXBean; pr.setRequestId(rid); pr.setArkBizMeta(arkBizMeta); pr.setStatus(INITIALIZED); Date date = new Date(); - pr.setMetaSpaceMXBean(metaSpaceMXBean); - pr.setStartSpace(metaSpaceMXBean.getUsage().getUsed()); pr.setStartTime(date); pr.setStartTimestamp(date.getTime()); processRecords.put(rid, pr); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index c68a89768..a2147332c 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -66,6 +66,7 @@ public void testInstallHandler() throws InterruptedException { Assert.assertNotNull(output); ProcessRecord processRecord = (ProcessRecord) output.getData(); Assert.assertNotNull(processRecord); + Assert.assertNotNull(processRecord.getEndSpace()); QueryBizOpsHandler.Input input1 = new QueryBizOpsHandler.Input(); input1.setRequestId(rid); @@ -75,7 +76,6 @@ public void testInstallHandler() throws InterruptedException { ProcessRecord processRecord1 = (ProcessRecord) output1.getData(); Assert.assertNotNull(processRecord1); Assert.assertNotNull(processRecord1.getEndSpace()); - Assert.assertNotNull(processRecord1.getEndTime()); } } From 5039b8b174f2a41fa4785705ef1ec2a9402e3a64 Mon Sep 17 00:00:00 2001 From: sususama <1023605039@qq.com> Date: Thu, 21 Sep 2023 22:46:03 +0800 Subject: [PATCH 11/21] fix --- .../arklet/core/command/CommandServiceImpl.java | 5 ++++- .../sofa/serverless/arklet/core/command/meta/Output.java | 9 +++++++++ .../arklet/core/command/record/ProcessRecord.java | 1 - .../arklet/core/command/record/ProcessRecordHolder.java | 2 -- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java index 037a0c99f..093d36fb4 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java @@ -164,7 +164,10 @@ public Output process(String cmd, Map content) throws CommandValidationExcept arkBizMeta.getBizName(), arkBizMeta.getBizVersion()).getId())); } try { - return handler.handle(input); + final long startSpace = metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed(); + Output output = handler.handle(input); + output.setElapsedSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed() - startSpace); + return output; } finally { BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java index c997ed464..57ffe0457 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java @@ -26,6 +26,7 @@ public class Output { private ResponseCode code; private String message; + private long elapsedSpace; private T data; private Output() { @@ -84,4 +85,12 @@ public T getData() { public void setData(T data) { this.data = data; } + + public void setElapsedSpace(long elapsedSpace) { + this.elapsedSpace = elapsedSpace; + } + + public long getElapsedSpace() { + return this.elapsedSpace; + } } diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index 46df73911..c7f8c561f 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -22,7 +22,6 @@ import lombok.Getter; import lombok.Setter; -import java.lang.management.MemoryPoolMXBean; import java.util.Date; import static com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord.Status.EXECUTING; diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index 24899fc41..d270209cf 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -19,8 +19,6 @@ import com.alipay.sofa.serverless.arklet.core.command.meta.bizops.ArkBizMeta; import org.apache.commons.lang3.StringUtils; -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryPoolMXBean; import java.util.ArrayList; import java.util.Date; import java.util.List; From 1505ad4d8c634737e458ec2b4a1a98b379523b5e Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Mon, 25 Sep 2023 15:51:29 +0800 Subject: [PATCH 12/21] fix actuator pom, make springboot-actuator dependencies strong --- arklet/arklet-springboot-starter/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/arklet/arklet-springboot-starter/pom.xml b/arklet/arklet-springboot-starter/pom.xml index 7ec92f8ea..aed166cbd 100644 --- a/arklet/arklet-springboot-starter/pom.xml +++ b/arklet/arklet-springboot-starter/pom.xml @@ -33,7 +33,6 @@ org.springframework.boot spring-boot-starter-actuator - provided From da37affbe4ca1296bc1ac990f8783dc9ec9646a0 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Tue, 26 Sep 2023 06:28:50 +0800 Subject: [PATCH 13/21] fix actuator pom, make springboot-actuator dependencies strong --- arklet/arklet-core/pom.xml | 6 + .../arklet/core/health/HealthServiceImpl.java | 3 +- .../sofa/serverless/arklet/core/BaseTest.java | 12 +- .../core/command/handler/BaseHandlerTest.java | 46 ++++++ .../{ => handler}/HealthHandlerTest.java | 34 +++- .../{ => handler}/HelpHandlerTests.java | 5 +- .../{ => handler}/InstallBizHandlerTests.java | 105 +++++------- .../arklet/core/health/HealthTests.java | 121 ++++++++++++-- .../custom/CustomBizManagerService.java | 125 ++++++++++++++ .../custom/CustomPluginManagerService.java | 44 +++++ .../core/health/custom/model/CustomBiz.java | 129 +++++++++++++++ .../health/custom/model/CustomPlugin.java | 153 ++++++++++++++++++ .../arklet/core/util/ConvertUtilsTest.java | 30 ++++ arklet/pom.xml | 8 + 14 files changed, 733 insertions(+), 88 deletions(-) create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/{ => handler}/HealthHandlerTest.java (58%) rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/{ => handler}/HelpHandlerTests.java (94%) rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/{ => handler}/InstallBizHandlerTests.java (50%) create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java diff --git a/arklet/arklet-core/pom.xml b/arklet/arklet-core/pom.xml index a21b972a8..43d52f144 100644 --- a/arklet/arklet-core/pom.xml +++ b/arklet/arklet-core/pom.xml @@ -75,6 +75,12 @@ test + + org.mockito + mockito-inline + test + + org.apache.commons commons-lang3 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 2c63ba77a..f31f39210 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 @@ -178,11 +178,10 @@ public Health queryModuleInfo(PluginInfo pluginInfo) { @Override public Health queryMasterBiz() { - BizHealthMeta bizHealthMeta = BizHealthMeta.createBizMeta(ArkClient.getMasterBiz()); return healthBuilder .init() .putHealthData(Constants.MASTER_BIZ_INFO, - JSON.parseObject(toJSONString(bizHealthMeta), JSONObject.class)).build(); + BizHealthMeta.createBizMeta(ArkClient.getMasterBiz())).build(); } @Override diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/BaseTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/BaseTest.java index b15cd13eb..9bc6cc688 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/BaseTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/BaseTest.java @@ -16,11 +16,18 @@ */ package com.alipay.sofa.serverless.arklet.core; +import com.alipay.sofa.ark.api.ArkClient; +import com.alipay.sofa.ark.api.ClientResponse; +import com.alipay.sofa.ark.api.ResponseCode; import com.alipay.sofa.serverless.arklet.core.command.CommandService; import com.alipay.sofa.serverless.arklet.core.health.HealthService; -import com.alipay.sofa.serverless.arklet.core.health.model.Health; import com.alipay.sofa.serverless.arklet.core.ops.UnifiedOperationService; import org.junit.Before; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; /** * @author mingmen @@ -33,7 +40,7 @@ public class BaseTest { public static HealthService healthService; @Before - public void setup() { + public void setup() throws Throwable { if (componentRegistry == null) { ArkletComponentRegistry registry = new ArkletComponentRegistry(); registry.initComponents(); @@ -43,4 +50,5 @@ public void setup() { healthService = ArkletComponentRegistry.getHealthServiceInstance(); } } + } 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 new file mode 100644 index 000000000..b015deaf0 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/BaseHandlerTest.java @@ -0,0 +1,46 @@ +package com.alipay.sofa.serverless.arklet.core.command.handler; + +import com.alipay.sofa.ark.api.ArkClient; +import com.alipay.sofa.ark.api.ClientResponse; +import com.alipay.sofa.ark.api.ResponseCode; +import com.alipay.sofa.ark.spi.model.BizOperation; +import com.alipay.sofa.serverless.arklet.core.BaseTest; +import com.alipay.sofa.serverless.arklet.core.command.meta.AbstractCommandHandler; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService; +import jdk.internal.org.objectweb.asm.Handle; +import org.junit.After; +import org.junit.Before; +import org.mockito.MockedStatic; + +import static org.mockito.Mockito.mockStatic; + +/** + * @author lunarscave + */ +public class BaseHandlerTest extends BaseTest { + + public final ClientResponse success = new ClientResponse(); + public final ClientResponse failed = new ClientResponse(); + public MockedStatic arkClient; + + @Before + public void setupHandler() { + success.setCode(ResponseCode.SUCCESS); + failed.setCode(ResponseCode.FAILED); + + arkClient = mockStatic(ArkClient.class); + arkClient.when(() -> { + ArkClient.installOperation(new BizOperation()); + }).thenReturn(success); + arkClient.when(ArkClient::getBizManagerService).thenReturn(new CustomBizManagerService()); + arkClient.when(ArkClient::getPluginManagerService).thenReturn(new CustomPluginManagerService()); + arkClient.when(ArkClient::getMasterBiz).thenReturn(new CustomBizManagerService().getMasterBiz()); + } + + @After + public void tearDown() { + arkClient.close(); + } + +} diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java similarity index 58% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java index cae78df33..6ac287a4a 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java @@ -14,22 +14,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.serverless.arklet.core.command; +package com.alipay.sofa.serverless.arklet.core.command.handler; +import com.alipay.sofa.ark.api.ArkClient; import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler.Input; +import com.alipay.sofa.serverless.arklet.core.command.meta.Command; +import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService; +import com.alipay.sofa.serverless.arklet.core.health.model.Health; +import org.junit.Assert; +import org.junit.Before; import org.junit.Test; +import static org.mockito.Mockito.mockStatic; + /** * @author lunarscave */ -public class HealthHandlerTest extends BaseTest { +public class HealthHandlerTest extends BaseHandlerTest { + + private HealthHandler handler; + + @Before + public void setupHealthHandlerTest() { + handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); + } private void testValidate(Input input) throws CommandValidationException { - HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); handler.validate(input); } @@ -40,4 +56,16 @@ public void testValidate_InvalidType() throws CommandValidationException { testValidate(input); } + @Test + public void testCommand() { + Command result = new HealthHandler().command(); + Assert.assertEquals(result, BuiltinCommand.HEALTH); + } + + @Test + public void testHandle_Success() { + Output output = handler.handle(new Input()); + Assert.assertTrue(output.success()); + } + } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HelpHandlerTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java similarity index 94% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HelpHandlerTests.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java index aed4e55f0..e09d4662d 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HelpHandlerTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.serverless.arklet.core.command; +package com.alipay.sofa.serverless.arklet.core.command.handler; import java.util.List; @@ -35,13 +35,12 @@ * @author mingmen * @date 2023/9/6 */ -public class HelpHandlerTests extends BaseTest { +public class HelpHandlerTests extends BaseHandlerTest { private HelpHandler helpHandler; @Before public void setUp() { - MockitoAnnotations.initMocks(this); helpHandler = (HelpHandler) commandService.getHandler(BuiltinCommand.HELP); } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/InstallBizHandlerTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/InstallBizHandlerTests.java similarity index 50% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/InstallBizHandlerTests.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/InstallBizHandlerTests.java index 2078acfc6..5711923f8 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/InstallBizHandlerTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/InstallBizHandlerTests.java @@ -14,19 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.serverless.arklet.core.command; +package com.alipay.sofa.serverless.arklet.core.command.handler; import com.alipay.sofa.ark.api.ClientResponse; -import com.alipay.sofa.ark.api.ResponseCode; -import com.alipay.sofa.ark.exception.ArkRuntimeException; -import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler.Input; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; -import com.alipay.sofa.serverless.arklet.core.common.exception.ArkletRuntimeException; import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import static org.mockito.Mockito.when; @@ -35,60 +32,43 @@ * @author mingmen * @date 2023/9/5 */ -public class InstallBizHandlerTests extends BaseTest { - - //@Test - //public void testHandle_Success() throws Throwable { - // - // InstallBizHandler handler = (InstallBizHandler)commandService.getHandler(BuiltinCommand.INSTALL_BIZ); - // - // // 准备测试数据 - // Input input = new Input(); - // input.setBizUrl("testUrl"); - // - // ClientResponse response = new ClientResponse(); - // response.setCode(ResponseCode.SUCCESS); - // - // // 设置Mock行为 - // when(operationService.install(anyString())).thenReturn(response); - // - // // 执行测试 - // Output result = handler.handle(input); - // - // // 验证结果 - // assertSame(response, result.getData()); - // assertTrue(result.success()); - //} - - // @Test(expected = ArkRuntimeException.class) - // public void testHandle_Failure() throws Throwable { - // - // InstallBizHandler handler = (InstallBizHandler) commandService - // .getHandler(BuiltinCommand.INSTALL_BIZ); - // - // // 准备测试数据 - // Input input = new Input(); - // input.setBizUrl("testUrl"); - // - // ClientResponse response = new ClientResponse(); - // response.setCode(ResponseCode.FAILED); - // - // // 设置Mock行为 - // when(operationService.install(input.getBizUrl())).thenReturn(response); - // - // // 执行测试 - // Output result = handler.handle(input); - // - // // 验证结果 - // Assert.assertSame(response, result.getData()); - // Assert.assertTrue(result.failed()); - // } +public class InstallBizHandlerTests extends BaseHandlerTest { + + private InstallBizHandler handler; + + @Before + public void setupInstallBizHandler() { + handler = (InstallBizHandler) commandService.getHandler(BuiltinCommand.INSTALL_BIZ); + } + + @Test + public void testHandle_Success() throws Throwable { + Input input = new Input(); + input.setBizUrl("testUrl"); + + when(handler.getOperationService().install(input.getBizUrl())).thenReturn(success); + + Output result = handler.handle(input); + + Assert.assertEquals(success, result.getData()); + Assert.assertTrue(result.success()); + } + + @Test + public void testHandle_Failure() throws Throwable { + Input input = new Input(); + input.setBizUrl("testUrl"); + + when(handler.getOperationService().install(input.getBizUrl())).thenReturn(failed); + + Output result = handler.handle(input); + + Assert.assertSame(failed, result.getData()); + Assert.assertTrue(result.failed()); + } @Test(expected = CommandValidationException.class) public void testValidate_BlankBizName() throws CommandValidationException { - - InstallBizHandler handler = (InstallBizHandler) commandService - .getHandler(BuiltinCommand.INSTALL_BIZ); // 准备测试数据 Input input = new Input(); input.setBizName(""); @@ -99,9 +79,6 @@ public void testValidate_BlankBizName() throws CommandValidationException { @Test(expected = CommandValidationException.class) public void testValidate_BlankBizVersion() throws CommandValidationException { - - InstallBizHandler handler = (InstallBizHandler) commandService - .getHandler(BuiltinCommand.INSTALL_BIZ); // 准备测试数据 Input input = new Input(); input.setBizVersion(""); @@ -112,11 +89,7 @@ public void testValidate_BlankBizVersion() throws CommandValidationException { @Test(expected = CommandValidationException.class) public void testValidate_BlankRequestId() throws CommandValidationException { - - InstallBizHandler handler = (InstallBizHandler) commandService - .getHandler(BuiltinCommand.INSTALL_BIZ); - - // 准备测试数据 + // 执行测试 Input input = new Input(); input.setAsync(true); input.setRequestId(""); @@ -127,9 +100,6 @@ public void testValidate_BlankRequestId() throws CommandValidationException { @Test(expected = CommandValidationException.class) public void testValidate_BlankBizUrl() throws CommandValidationException { - InstallBizHandler handler = (InstallBizHandler) commandService - .getHandler(BuiltinCommand.INSTALL_BIZ); - // 准备测试数据 Input input = new Input(); input.setBizUrl(""); @@ -137,4 +107,5 @@ public void testValidate_BlankBizUrl() throws CommandValidationException { // 执行测试 handler.validate(input); } + } 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 bc2de39dd..0313061b4 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 @@ -16,21 +16,31 @@ */ package com.alipay.sofa.serverless.arklet.core.health; -import com.alipay.sofa.serverless.arklet.core.ArkletComponentRegistry; +import com.alipay.sofa.ark.api.ArkClient; +import com.alipay.sofa.ark.spi.model.Biz; +import com.alipay.sofa.ark.spi.model.Plugin; import com.alipay.sofa.serverless.arklet.core.BaseTest; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService; import com.alipay.sofa.serverless.arklet.core.health.custom.CustomIndicator; +import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService; +import com.alipay.sofa.serverless.arklet.core.health.model.BizHealthMeta; import com.alipay.sofa.serverless.arklet.core.health.model.Constants; import com.alipay.sofa.serverless.arklet.core.health.model.Health; +import com.alipay.sofa.serverless.arklet.core.health.model.PluginHealthMeta; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.MockedStatic; -import java.io.IOException; +import java.util.List; import java.util.Map; +import static org.mockito.Mockito.mockStatic; + public class HealthTests extends BaseTest { - private HealthService healthService; + private MockedStatic arkClient; private void validateHealth(Health health, final String[] expectedMetrics) { Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); @@ -41,20 +51,81 @@ private void validateHealth(Health health, final String[] expectedMetrics) { } } - private void validateHealth(Health health, String errorCode, String errorMessage) { + private void validateBizListHealth(Health health, final List expectedBizList) { + Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); + Assert.assertTrue(health.getHealthData().containsKey(Constants.BIZ_LIST_INFO)); + + List realBizList = (List) health.getHealthData().get(Constants.BIZ_LIST_INFO); + Assert.assertEquals(realBizList.size(), expectedBizList.size()); + for (int i = 0, L = realBizList.size(); i < L; i++) { + Object realBiz = realBizList.get(i); + Biz expectedBiz = expectedBizList.get(i); + Assert.assertTrue(realBiz instanceof BizHealthMeta); + validateBiz((BizHealthMeta)realBiz, expectedBiz); + } + } + + private void validatePluginListHealth(Health health, final List expectedPluginList) { + Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); + Assert.assertTrue(health.getHealthData().containsKey(Constants.PLUGIN_LIST_INFO)); + + List realPluginList = (List) health.getHealthData().get(Constants.PLUGIN_LIST_INFO); + Assert.assertEquals(realPluginList.size(), expectedPluginList.size()); + for (int i = 0, L = realPluginList.size(); i < L; i++) { + Object realPlugin = realPluginList.get(i); + Plugin expectedPlugin = expectedPluginList.get(i); + Assert.assertTrue(realPlugin instanceof PluginHealthMeta); + validatePlugin((PluginHealthMeta)realPlugin, expectedPlugin); + } + } + + 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); + } + + private void validateHealth(Health health, final Biz expectedBiz) { + Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); + 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); + } + + private void validateHealth(Health health, final Plugin expectedPlugin) { + Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); + Assert.assertTrue(health.getHealthData().containsKey(Constants.PLUGIN_INFO)); + Object realPlugin = health.getHealthData().get(Constants.PLUGIN_INFO); + Assert.assertTrue(realPlugin instanceof PluginHealthMeta); + validatePlugin((PluginHealthMeta) realPlugin, expectedPlugin); + } + + private void validateHealth(Health health, final String errorCode, final String errorMessage) { Assert.assertTrue(health != null && !health.getHealthData().isEmpty()); Assert.assertTrue(health.getHealthData().containsKey(errorCode)); Assert.assertEquals(health.getHealthData().get(errorCode), errorMessage); } + private void validateBiz(BizHealthMeta realBiz, final Biz expectedBiz) { + Assert.assertEquals(realBiz.getBizName(), expectedBiz.getBizName()); + Assert.assertEquals(realBiz.getBizVersion(), expectedBiz.getBizVersion()); + } + + private void validatePlugin(PluginHealthMeta realPlugin, final Plugin expectedPlugin) { + Assert.assertEquals(realPlugin.getPluginName(), expectedPlugin.getPluginName()); + Assert.assertEquals(realPlugin.getPluginVersion(), expectedPlugin.getVersion()); + } + @Before - public void initHealthService() throws IOException { - this.healthService = ArkletComponentRegistry.getHealthServiceInstance(); - // ClassLoader cl = Thread.currentThread().getContextClassLoader(); - // URL testBiz = cl.getResource("test-biz.jar"); - // BizOperation bizOperation = new BizOperation(); - // bizOperation.setBizVersion("test version"); - // ArkClient.getBizFactoryService().createBiz(bizOperation, new File(testBiz.getFile())); + public void initHealthService() { + arkClient = mockStatic(ArkClient.class); + arkClient.when(ArkClient::getBizManagerService).thenReturn(new CustomBizManagerService()); + arkClient.when(ArkClient::getPluginManagerService).thenReturn(new CustomPluginManagerService()); + arkClient.when(ArkClient::getMasterBiz).thenReturn(new CustomBizManagerService().getMasterBiz()); } @Test @@ -76,10 +147,38 @@ public void testGetHealth() { "indicator not registered"); } + @Test + public void testGetModuleInfo() { + final CustomBizManagerService bizService = new CustomBizManagerService(); + final CustomPluginManagerService pluginService = new CustomPluginManagerService(); + final String bizName = "testBiz1"; + final String pluginName = "testPlugin1"; + final String bizVersion = "testBizVersion1"; + final String errorType = "errorType"; + 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"); + } + @Test public void testIndicators() { Assert.assertNotNull(healthService.getIndicator(Constants.CPU)); Assert.assertNotNull(healthService.getIndicator(Constants.JVM)); } + @After + public void destroyHealthService() { + arkClient.close(); + } + } 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 new file mode 100644 index 000000000..10dc31c65 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomBizManagerService.java @@ -0,0 +1,125 @@ +package com.alipay.sofa.serverless.arklet.core.health.custom; + +import com.alipay.sofa.ark.spi.model.Biz; +import com.alipay.sofa.ark.spi.model.BizState; +import com.alipay.sofa.ark.spi.service.biz.BizManagerService; +import com.alipay.sofa.serverless.arklet.core.health.custom.model.CustomBiz; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +public class CustomBizManagerService implements BizManagerService { + + 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") + }); + + public Biz getMasterBiz() { + return bizList.get(0); + } + + @Override + public boolean registerBiz(Biz biz) { + return false; + } + + @Override + public Biz unRegisterBiz(String s, String s1) { + return null; + } + + @Override + public Biz unRegisterBizStrictly(String s, String s1) { + return null; + } + + @Override + public List getBiz(String s) { + List bizList = new ArrayList<>(); + for (Biz item : this.bizList) { + if (s.equals(item.getBizName())) { + bizList.add(item); + } + } + return bizList; + } + + @Override + public Biz getBiz(String s, String s1) { + Biz biz = null; + for (Biz item : this.bizList) { + if (s.equals(item.getBizName()) && s1.equals(item.getBizVersion())) { + biz = item; + break; + } + } + return biz; + } + + @Override + public Biz getBizByIdentity(String s) { + return null; + } + + @Override + public Biz getBizByClassLoader(ClassLoader classLoader) { + return null; + } + + @Override + public Set getAllBizNames() { + return null; + } + + @Override + public Set getAllBizIdentities() { + return null; + } + + @Override + public List getBizInOrder() { + return bizList; + } + + @Override + public Biz getActiveBiz(String s) { + return null; + } + + @Override + public boolean isActiveBiz(String s, String s1) { + return false; + } + + @Override + public void activeBiz(String s, String s1) { + + } + + @Override + public BizState getBizState(String s, String s1) { + return null; + } + + @Override + public BizState getBizState(String s) { + return null; + } + + @Override + public boolean removeAndAddBiz(Biz biz, Biz biz1) { + return true; + } + + @Override + public ConcurrentHashMap> getBizRegistration() { + return null; + } +} 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 new file mode 100644 index 000000000..7fc00df3f --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/CustomPluginManagerService.java @@ -0,0 +1,44 @@ +package com.alipay.sofa.serverless.arklet.core.health.custom; + +import com.alipay.sofa.ark.spi.model.Plugin; +import com.alipay.sofa.ark.spi.service.plugin.PluginManagerService; +import com.alipay.sofa.serverless.arklet.core.health.custom.model.CustomPlugin; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +public class CustomPluginManagerService implements PluginManagerService { + + private final List pluginList = Arrays.asList(new Plugin[]{ + new CustomPlugin("testPlugin1", "testPluginVersion1"), + new CustomPlugin("testPlugin2", "testPluginVersion2") + }); + + @Override + public void registerPlugin(Plugin plugin) { + + } + + @Override + public Plugin getPluginByName(String s) { + Plugin plugin = null; + for (Plugin item: pluginList) { + if (s.equals(item.getPluginName())) { + plugin = item; + break; + } + } + return plugin; + } + + @Override + public Set getAllPluginNames() { + return null; + } + + @Override + public List getPluginsInOrder() { + return pluginList; + } +} 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 new file mode 100644 index 000000000..1b687ca88 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomBiz.java @@ -0,0 +1,129 @@ +package com.alipay.sofa.serverless.arklet.core.health.custom.model; + +import com.alipay.sofa.ark.spi.model.Biz; +import com.alipay.sofa.ark.spi.model.BizState; + +import java.net.URL; +import java.util.Map; +import java.util.Set; + +public class CustomBiz implements Biz { + + private final String bizName; + private final String bizVersion; + + public CustomBiz(String bizName, String bizVersion) { + this.bizName = bizName; + this.bizVersion = bizVersion; + } + + @Override + public void start(String[] strings) throws Throwable { + + } + + @Override + public void stop() throws Throwable { + + } + + @Override + public boolean isDeclared(URL url, String s) { + return true; + } + + @Override + public boolean isDeclaredMode() { + return true; + } + + @Override + public void setCustomBizName(String s) { + + } + + @Override + public String getBizName() { + return this.bizName; + } + + @Override + public String getBizVersion() { + return bizVersion; + } + + @Override + public String getIdentity() { + return null; + } + + @Override + public String getMainClass() { + return null; + } + + @Override + public URL[] getClassPath() { + return new URL[0]; + } + + @Override + public Set getDenyImportPackages() { + return null; + } + + @Override + public Set getDenyImportPackageNodes() { + return null; + } + + @Override + public Set getDenyImportPackageStems() { + return null; + } + + @Override + public Set getDenyImportClasses() { + return null; + } + + @Override + public Set getDenyImportResources() { + return null; + } + + @Override + public Set getDenyPrefixImportResourceStems() { + return null; + } + + @Override + public Set getDenySuffixImportResourceStems() { + return null; + } + + @Override + public ClassLoader getBizClassLoader() { + return null; + } + + @Override + public BizState getBizState() { + return null; + } + + @Override + public String getWebContextPath() { + return null; + } + + @Override + public Map getAttributes() { + return null; + } + + @Override + public int getPriority() { + return 0; + } +} 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 new file mode 100644 index 000000000..6a0abb1f5 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/custom/model/CustomPlugin.java @@ -0,0 +1,153 @@ +package com.alipay.sofa.serverless.arklet.core.health.custom.model; + +import com.alipay.sofa.ark.exception.ArkRuntimeException; +import com.alipay.sofa.ark.spi.model.Plugin; +import com.alipay.sofa.ark.spi.model.PluginContext; + +import java.net.URL; +import java.util.Set; + +public class CustomPlugin implements Plugin { + + private final String pluginName; + private final String pluginVersion; + + public CustomPlugin(String pluginName, String pluginVersion) { + this.pluginName = pluginName; + this.pluginVersion = pluginVersion; + } + + @Override + public String getPluginName() { + return pluginName; + } + + @Override + public String getGroupId() { + return null; + } + + @Override + public String getArtifactId() { + return null; + } + + @Override + public String getVersion() { + return pluginVersion; + } + + @Override + public int getPriority() { + return 0; + } + + @Override + public String getPluginActivator() { + return null; + } + + @Override + public URL[] getClassPath() { + return new URL[0]; + } + + @Override + public ClassLoader getPluginClassLoader() { + return null; + } + + @Override + public PluginContext getPluginContext() { + return null; + } + + @Override + public Set getExportPackages() { + return null; + } + + @Override + public Set getExportPackageNodes() { + return null; + } + + @Override + public Set getExportPackageStems() { + return null; + } + + @Override + public Set getExportClasses() { + return null; + } + + @Override + public Set getImportPackages() { + return null; + } + + @Override + public Set getImportPackageNodes() { + return null; + } + + @Override + public Set getImportPackageStems() { + return null; + } + + @Override + public Set getImportClasses() { + return null; + } + + @Override + public Set getImportResources() { + return null; + } + + @Override + public Set getImportPrefixResourceStems() { + return null; + } + + @Override + public Set getImportSuffixResourceStems() { + return null; + } + + @Override + public Set getExportResources() { + return null; + } + + @Override + public Set getExportPrefixResourceStems() { + return null; + } + + @Override + public Set getExportSuffixResourceStems() { + return null; + } + + @Override + public URL getPluginURL() { + try { + return new URL("https://test.path"); + } catch (Throwable throwable) { + return null; + } + } + + @Override + public void start() throws ArkRuntimeException { + + } + + @Override + public void stop() throws 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 new file mode 100644 index 000000000..3b5bd26cb --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java @@ -0,0 +1,30 @@ +package com.alipay.sofa.serverless.arklet.core.util; + +import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Date; + +public class ConvertUtilsTest extends TestCase { + + @Test + public void testBytes2Megabyte() { + final long bytes = 1024 * 1024; + final double delta = 1e-5; + Assert.assertEquals(1., ConvertUtils.bytes2Megabyte(bytes), delta); + } + + @Test + public void testGetDurationSecond() { + try { + final Date date = new Date(System.currentTimeMillis()); + final long millis = 1000; + final double delta = 1e-2; + Thread.sleep(millis); + Assert.assertEquals(millis / 1000., ConvertUtils.getDurationSecond(date), delta); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/arklet/pom.xml b/arklet/pom.xml index 0161e2e8a..16160b01b 100644 --- a/arklet/pom.xml +++ b/arklet/pom.xml @@ -187,6 +187,14 @@ ${mockito.version} test + + + org.mockito + mockito-inline + ${mockito.version} + test + + From 53a123c6e3baa98e83aba63b68a6d652f455b3b5 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Tue, 26 Sep 2023 06:34:29 +0800 Subject: [PATCH 14/21] remove useless code --- .../arklet/core/command/handler/BaseHandlerTest.java | 2 -- .../arklet/core/command/handler/HealthHandlerTest.java | 5 ----- 2 files changed, 7 deletions(-) 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 b015deaf0..df937f65d 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 @@ -5,10 +5,8 @@ import com.alipay.sofa.ark.api.ResponseCode; import com.alipay.sofa.ark.spi.model.BizOperation; import com.alipay.sofa.serverless.arklet.core.BaseTest; -import com.alipay.sofa.serverless.arklet.core.command.meta.AbstractCommandHandler; import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService; import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService; -import jdk.internal.org.objectweb.asm.Handle; import org.junit.After; import org.junit.Before; import org.mockito.MockedStatic; 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 6ac287a4a..066368363 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 @@ -16,22 +16,17 @@ */ package com.alipay.sofa.serverless.arklet.core.command.handler; -import com.alipay.sofa.ark.api.ArkClient; -import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HealthHandler.Input; import com.alipay.sofa.serverless.arklet.core.command.meta.Command; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; -import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService; -import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService; import com.alipay.sofa.serverless.arklet.core.health.model.Health; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import static org.mockito.Mockito.mockStatic; /** * @author lunarscave 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 15/21] 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; From 1d8972b964eda11e6d8d2e46e93dae026300a565 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Tue, 26 Sep 2023 07:11:16 +0800 Subject: [PATCH 16/21] fix actuator pom, and add unit test --- .../serverless/arklet/core/health/HealthServiceImpl.java | 1 - .../health/{HealthTests.java => HealthServiceTests.java} | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/{HealthTests.java => HealthServiceTests.java} (98%) 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 17676b852..e588d2d14 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 @@ -41,7 +41,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import static com.alibaba.fastjson.JSON.toJSONString; /** * @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/HealthServiceTests.java similarity index 98% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthTests.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceTests.java index 5cd6faf4a..923d36237 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/HealthServiceTests.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.mockStatic; -public class HealthTests extends BaseTest { +public class HealthServiceTests extends BaseTest { private MockedStatic arkClient; @@ -139,10 +139,11 @@ public void registerCustomCIndicator() { @Test public void testGetHealth() { final String[] allMetrics = new String[] { Constants.CPU, Constants.JVM }; - final String[] testMetrics = new String[] { Constants.CPU }; + final String[] testMetrics = new String[] { Constants.CPU, Constants.JVM }; final String[] errorMetrics = new String[] { "nonMetrics" }; validateHealth(healthService.getHealth(), allMetrics); validateHealth(healthService.getHealth(new String[0]), allMetrics); + validateHealth(healthService.getHealth(testMetrics[0]), new String[]{testMetrics[0]}); validateHealth(healthService.getHealth(testMetrics), testMetrics); validateHealth(healthService.getHealth(errorMetrics), Constants.HEALTH_ERROR, "indicator not registered"); From 3c8ec4b688f78f3b1105597a9f2175ad1a90911f Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Tue, 26 Sep 2023 07:12:22 +0800 Subject: [PATCH 17/21] fix actuator pom, and add unit test --- .../sofa/serverless/arklet/core/health/HealthServiceImpl.java | 1 - .../sofa/serverless/arklet/core/health/HealthServiceTests.java | 2 +- 2 files changed, 1 insertion(+), 2 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 e588d2d14..07ef96a24 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 @@ -41,7 +41,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; - /** * @author Lunarscave */ diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceTests.java index 923d36237..cd111909c 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/health/HealthServiceTests.java @@ -143,7 +143,7 @@ public void testGetHealth() { final String[] errorMetrics = new String[] { "nonMetrics" }; validateHealth(healthService.getHealth(), allMetrics); validateHealth(healthService.getHealth(new String[0]), allMetrics); - validateHealth(healthService.getHealth(testMetrics[0]), new String[]{testMetrics[0]}); + validateHealth(healthService.getHealth(testMetrics[0]), new String[] { testMetrics[0] }); validateHealth(healthService.getHealth(testMetrics), testMetrics); validateHealth(healthService.getHealth(errorMetrics), Constants.HEALTH_ERROR, "indicator not registered"); From 15977184df06e8d2f07cf7b8cf9b5d806c229049 Mon Sep 17 00:00:00 2001 From: Jaime Zhang Date: Wed, 27 Sep 2023 11:36:08 +0800 Subject: [PATCH 18/21] Revert "Increase the usage of MetaSpace in computing" --- .../core/command/CommandServiceImpl.java | 9 +---- .../arklet/core/command/meta/Output.java | 9 ----- .../core/command/record/MetaSpaceRecord.java | 40 ------------------- .../core/command/record/ProcessRecord.java | 7 ---- .../command/record/ProcessRecordHolder.java | 1 + .../arklet/core/health/HealthServiceImpl.java | 5 ++- .../arklet/core/command/CommandTests.java | 11 ++--- .../core/command/HealthHandlerTest.java | 18 +-------- 8 files changed, 10 insertions(+), 90 deletions(-) delete mode 100644 arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java index 093d36fb4..b566a3c75 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/CommandServiceImpl.java @@ -41,7 +41,6 @@ import com.alipay.sofa.serverless.arklet.core.command.meta.Command; import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta; import com.alipay.sofa.serverless.arklet.core.command.meta.Output; -import com.alipay.sofa.serverless.arklet.core.command.record.MetaSpaceRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecord; import com.alipay.sofa.serverless.arklet.core.command.record.ProcessRecordHolder; import com.alipay.sofa.serverless.arklet.core.common.exception.ArkletInitException; @@ -111,7 +110,6 @@ public Output process(String cmd, Map content) throws CommandValidationExcept ArkBizMeta arkBizMeta = (ArkBizMeta) input; AssertUtils.assertNotNull(arkBizMeta, "when execute bizOpsHandler, arkBizMeta should not be null"); - final MetaSpaceRecord metaSpaceRecord = new MetaSpaceRecord(); if (arkBizMeta.isAsync()) { String requestId = arkBizMeta.getRequestId(); if (ProcessRecordHolder.getProcessRecord(requestId) != null) { @@ -129,7 +127,6 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail("command conflict, exist unfinished command for this biz"); } else { processRecord.start(); - processRecord.setStartSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); Output output = handler.handle(input); if (output.success()) { processRecord.success(); @@ -141,7 +138,6 @@ public Output process(String cmd, Map content) throws CommandValidationExcept processRecord.fail(throwable.getMessage(), throwable); LOGGER.error("Error happened when handling command, requestId=" + requestId, throwable); } finally { - processRecord.setEndSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed()); processRecord.markFinishTime(); BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); @@ -164,10 +160,7 @@ public Output process(String cmd, Map content) throws CommandValidationExcept arkBizMeta.getBizName(), arkBizMeta.getBizVersion()).getId())); } try { - final long startSpace = metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed(); - Output output = handler.handle(input); - output.setElapsedSpace(metaSpaceRecord.getMetaSpaceMXBean().getUsage().getUsed() - startSpace); - return output; + return handler.handle(input); } finally { BizOpsCommandCoordinator .unlock(arkBizMeta.getBizName(), arkBizMeta.getBizVersion()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java index 57ffe0457..c997ed464 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/meta/Output.java @@ -26,7 +26,6 @@ public class Output { private ResponseCode code; private String message; - private long elapsedSpace; private T data; private Output() { @@ -85,12 +84,4 @@ public T getData() { public void setData(T data) { this.data = data; } - - public void setElapsedSpace(long elapsedSpace) { - this.elapsedSpace = elapsedSpace; - } - - public long getElapsedSpace() { - return this.elapsedSpace; - } } diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java deleted file mode 100644 index 3da1e1e74..000000000 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/MetaSpaceRecord.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.record; - -import java.lang.management.ManagementFactory; -import java.lang.management.MemoryPoolMXBean; -import java.util.List; - -/** - * @author sususama - * @since 2023-09-21 - */ - -public class MetaSpaceRecord { - private static MemoryPoolMXBean metaSpaceMXBean; - static { - List memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); - for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) - if (memoryPoolMXBean.getName().equals("Metaspace")) - metaSpaceMXBean = memoryPoolMXBean; - } - - public MemoryPoolMXBean getMetaSpaceMXBean() { - return metaSpaceMXBean; - } -} diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java index c7f8c561f..d3e1f62ff 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecord.java @@ -55,20 +55,14 @@ public class ProcessRecord { private Date startTime; - private long startSpace; - private long startTimestamp; private Date endTime; - private long endSpace; - private long endTimestamp; private long elapsedTime; - private long elapsedSpace; - public enum Status { INITIALIZED("INITIALIZED"), @@ -95,7 +89,6 @@ public void setName(String name) { } public void markFinishTime() { - setElapsedSpace(getEndSpace() - getStartSpace()); Date date = new Date(); setEndTime(date); setEndTimestamp(date.getTime()); diff --git a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java index d270209cf..01ccd4b75 100644 --- a/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java +++ b/arklet/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/record/ProcessRecordHolder.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.serverless.arklet.core.command.record; +import com.alipay.sofa.serverless.arklet.core.command.meta.InputMeta; import com.alipay.sofa.serverless.arklet.core.command.meta.bizops.ArkBizMeta; import org.apache.commons.lang3.StringUtils; 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 2c63ba77a..dc4fb1b7a 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 @@ -49,8 +49,9 @@ @Singleton public class HealthServiceImpl implements HealthService { - private static final ArkletLogger LOGGER = ArkletLoggerFactory.getDefaultLogger(); - private final HealthBuilder healthBuilder = new HealthBuilder(); + private static final ArkletLogger LOGGER = ArkletLoggerFactory + .getDefaultLogger(); + private final HealthBuilder healthBuilder = new HealthBuilder(); private final Map indicators = new ConcurrentHashMap<>(3); diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java index a2147332c..452294aea 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/CommandTests.java @@ -16,7 +16,11 @@ */ package com.alipay.sofa.serverless.arklet.core.command; +import java.util.HashMap; +import java.util.Map; + import com.alibaba.fastjson.JSONObject; + import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler; @@ -28,9 +32,6 @@ import org.junit.Assert; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - /** * @author mingmen * @date 2023/6/26 @@ -66,16 +67,12 @@ public void testInstallHandler() throws InterruptedException { Assert.assertNotNull(output); ProcessRecord processRecord = (ProcessRecord) output.getData(); Assert.assertNotNull(processRecord); - Assert.assertNotNull(processRecord.getEndSpace()); QueryBizOpsHandler.Input input1 = new QueryBizOpsHandler.Input(); input1.setRequestId(rid); Map map1 = JSONObject.parseObject(JSONObject.toJSONString(input1), Map.class); Output output1 = commandService.process(BuiltinCommand.QUERY_BIZ_OPS.getId(), map1); Assert.assertNotNull(output1); - ProcessRecord processRecord1 = (ProcessRecord) output1.getData(); - Assert.assertNotNull(processRecord1); - Assert.assertNotNull(processRecord1.getEndSpace()); } } diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java index cae78df33..8c2ec0dc8 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/HealthHandlerTest.java @@ -1,19 +1,3 @@ -/* - * 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; import com.alipay.sofa.serverless.arklet.core.BaseTest; @@ -28,7 +12,7 @@ */ public class HealthHandlerTest extends BaseTest { - private void testValidate(Input input) throws CommandValidationException { + private void testValidate(Input input) throws CommandValidationException{ HealthHandler handler = (HealthHandler) commandService.getHandler(BuiltinCommand.HEALTH); handler.validate(input); } From c87cc57318aa4652026094d741c4b7f7619c0332 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Thu, 28 Sep 2023 16:38:37 +0800 Subject: [PATCH 19/21] fix actuator pom, and add unit test --- .../handler/UninstallBizHandlerTests.java | 84 +++++++++++++++++++ .../core/command/handler/BaseHandlerTest.java | 2 + ...ndlerTest.java => HealthHandlerTests.java} | 2 +- .../command/handler/HelpHandlerTests.java | 2 - .../arklet/core/util/AssertUtilsTests.java | 61 ++++++++++++++ ...tUtilsTest.java => ConvertUtilsTests.java} | 2 +- 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/UninstallBizHandlerTests.java rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/{HealthHandlerTest.java => HealthHandlerTests.java} (97%) create mode 100644 arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java rename arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/{ConvertUtilsTest.java => ConvertUtilsTests.java} (96%) diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/UninstallBizHandlerTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/UninstallBizHandlerTests.java new file mode 100644 index 000000000..7eef3b7c9 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/UninstallBizHandlerTests.java @@ -0,0 +1,84 @@ +package com.alipay.sofa.serverless.arklet.core.command.builtin.handler; + +import com.alipay.sofa.ark.api.ClientResponse; +import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; +import com.alipay.sofa.serverless.arklet.core.command.handler.BaseHandlerTest; +import com.alipay.sofa.serverless.arklet.core.command.meta.Output; +import com.alipay.sofa.serverless.arklet.core.common.exception.CommandValidationException; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.mockito.Mockito.when; + +public class UninstallBizHandlerTests extends BaseHandlerTest { + + private UninstallBizHandler handler; + + @Before + public void setupInstallBizHandler() { + handler = (UninstallBizHandler) commandService.getHandler(BuiltinCommand.UNINSTALL_BIZ); + } + + @Test + public void testHandle_Success() throws Throwable { + UninstallBizHandler.Input input = new UninstallBizHandler.Input(); + input.setBizName("testBizName"); + input.setBizVersion("testBizVersion"); + + when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(success); + + Output result = handler.handle(input); + + Assert.assertEquals(success, result.getData()); + Assert.assertTrue(result.success()); + } + + @Test + public void testHandle_Failure() throws Throwable { + UninstallBizHandler.Input input = new UninstallBizHandler.Input(); + input.setBizName("testBizName"); + input.setBizVersion("testBizVersion"); + + when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(failed); + + Output result = handler.handle(input); + + Assert.assertSame(failed, result.getData()); + Assert.assertTrue(result.failed()); + } + + @Test(expected = CommandValidationException.class) + public void testValidate_BlankBizName() throws CommandValidationException { + // 准备测试数据 + UninstallBizHandler.Input input = new UninstallBizHandler.Input(); + input.setBizName(""); + input.setBizVersion("testBizVersion"); + + // 执行测试 + handler.validate(input); + } + + @Test(expected = CommandValidationException.class) + public void testValidate_BlankBizVersion() throws CommandValidationException { + // 准备测试数据 + UninstallBizHandler.Input input = new UninstallBizHandler.Input(); + input.setBizName("testBizName"); + input.setBizVersion(""); + + // 执行测试 + handler.validate(input); + } + + @Test(expected = CommandValidationException.class) + public void testValidate_BlankRequestId() throws CommandValidationException { + // 执行测试 + UninstallBizHandler.Input input = new UninstallBizHandler.Input(); + input.setAsync(true); + input.setRequestId(""); + + // 执行测试 + handler.validate(input); + } + +} \ No newline at end of file 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 55d356b22..9e95ae8cc 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 @@ -27,6 +27,7 @@ import org.junit.Before; import org.mockito.MockedStatic; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mockStatic; /** @@ -46,6 +47,7 @@ public void setupHandler() { arkClient = mockStatic(ArkClient.class); arkClient.when(() -> { ArkClient.installOperation(new BizOperation()); + ArkClient.uninstallBiz(anyString(), anyString()); }).thenReturn(success); arkClient.when(ArkClient::getBizManagerService).thenReturn(new CustomBizManagerService()); arkClient.when(ArkClient::getPluginManagerService).thenReturn(new CustomPluginManagerService()); 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/HealthHandlerTests.java similarity index 97% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTest.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HealthHandlerTests.java index e9574d332..ba80a4ec4 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/HealthHandlerTests.java @@ -30,7 +30,7 @@ /** * @author lunarscave */ -public class HealthHandlerTest extends BaseHandlerTest { +public class HealthHandlerTests extends BaseHandlerTest { private HealthHandler handler; diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java index e09d4662d..959b4d9bd 100644 --- a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/HelpHandlerTests.java @@ -18,7 +18,6 @@ import java.util.List; -import com.alipay.sofa.serverless.arklet.core.BaseTest; import com.alipay.sofa.serverless.arklet.core.command.builtin.BuiltinCommand; import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.HelpHandler; import com.alipay.sofa.serverless.arklet.core.command.builtin.model.CommandModel; @@ -29,7 +28,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.MockitoAnnotations; /** * @author mingmen diff --git a/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java new file mode 100644 index 000000000..a3a609087 --- /dev/null +++ b/arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java @@ -0,0 +1,61 @@ +package com.alipay.sofa.serverless.arklet.core.util; + +import org.junit.Assert; +import org.junit.Test; + +public class AssertUtilsTests { + + @Test + public void testTestAssertNotNull_Success() { + Object instance = new Object(); + final String message = "instance is not null"; + AssertUtils.assertNotNull(instance, message); + } + + @Test(expected = IllegalArgumentException.class) + public void testTestAssertNotNull_Failure() { + final String message = "instance is null"; + AssertUtils.assertNotNull(null, message); + } + + @Test + public void testTestAssertNull_Success() { + final String message = "instance is null"; + AssertUtils.assertNull(null, message); + } + + @Test(expected = IllegalArgumentException.class) + public void testTestAssertNull_Failure() { + Object instance = new Object(); + final String message = "instance is not null"; + AssertUtils.assertNull(instance, message); + } + + @Test + public void testIsTrue_Success() { + final boolean expression = true; + final String message = "expression is true"; + AssertUtils.isTrue(expression, message); + } + + @Test(expected = IllegalArgumentException.class) + public void testIsTrue_Failure() { + final boolean expression = false; + final String message = "expression is false"; + AssertUtils.isTrue(expression, message); + } + + @Test + public void testIsFalse_Success() { + final boolean expression = false; + final String message = "expression is false"; + AssertUtils.isFalse(expression, message); + } + + @Test(expected = IllegalArgumentException.class) + public void testIsFalse_Failure() { + final boolean expression = true; + final String message = "expression is true"; + AssertUtils.isFalse(expression, message); + } +} \ No newline at end of file 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/ConvertUtilsTests.java similarity index 96% rename from arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTest.java rename to arklet/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTests.java index 14ab07879..2246a305b 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/ConvertUtilsTests.java @@ -22,7 +22,7 @@ import java.util.Date; -public class ConvertUtilsTest extends TestCase { +public class ConvertUtilsTests extends TestCase { @Test public void testBytes2Megabyte() { From 5c8e6eb465334af2b719a9a1b715576beea03ec1 Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Thu, 28 Sep 2023 18:41:53 +0800 Subject: [PATCH 20/21] remove useless code --- .../health/indicator/ArkletBaseIndicator.java | 57 ------------------- .../arklet/core/util/ConvertUtilsTests.java | 3 +- 2 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java diff --git a/sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java b/sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java deleted file mode 100644 index cd2a44256..000000000 --- a/sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/health/indicator/ArkletBaseIndicator.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.indicator; - -import com.alipay.sofa.serverless.arklet.core.health.model.Health; -import com.alipay.sofa.serverless.arklet.core.health.model.Health.HealthBuilder; - -import java.util.Map; - -/** - * @author Lunarscave - */ -public abstract class Indicator { - - private final String indicatorId; - - public Indicator(String indicatorId) { - this.indicatorId = indicatorId; - } - - /** - * get health details - * @return a map of health details - */ - protected abstract Map getHealthDetails(); - - /** - * get indicator id - * @return indicator id - */ - public String getIndicatorId() { - return indicatorId; - } - - /** - * get health model - * @param builder input health builder - * @return health model - */ - public Health getHealthModel(HealthBuilder builder) { - return builder.init().putHealthData(getIndicatorId(), getHealthDetails()).build(); - } -} diff --git a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTests.java b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTests.java index 2246a305b..a5bdc65d6 100644 --- a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTests.java +++ b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/ConvertUtilsTests.java @@ -16,13 +16,12 @@ */ package com.alipay.sofa.serverless.arklet.core.util; -import junit.framework.TestCase; import org.junit.Assert; import org.junit.Test; import java.util.Date; -public class ConvertUtilsTests extends TestCase { +public class ConvertUtilsTests { @Test public void testBytes2Megabyte() { From d146fb26d6e36e4ed5b2b4468da856b1f058fb2c Mon Sep 17 00:00:00 2001 From: ColdClear <3124364150@qq.com> Date: Thu, 28 Sep 2023 18:43:42 +0800 Subject: [PATCH 21/21] remove useless code --- .../handler/UninstallBizHandlerTests.java | 22 +++++++++++++++++-- .../arklet/core/util/AssertUtilsTests.java | 16 ++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/UninstallBizHandlerTests.java b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/UninstallBizHandlerTests.java index cbb7782d3..b2c164d7d 100644 --- a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/UninstallBizHandlerTests.java +++ b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/command/handler/UninstallBizHandlerTests.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.ClientResponse; @@ -27,7 +43,8 @@ public void testHandle_Success() throws Throwable { input.setBizName("testBizName"); input.setBizVersion("testBizVersion"); - when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(success); + when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())) + .thenReturn(success); Output result = handler.handle(input); @@ -41,7 +58,8 @@ public void testHandle_Failure() throws Throwable { input.setBizName("testBizName"); input.setBizVersion("testBizVersion"); - when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())).thenReturn(failed); + when(handler.getOperationService().uninstall(input.getBizName(), input.getBizVersion())) + .thenReturn(failed); Output result = handler.handle(input); diff --git a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java index a3a609087..73f01ada7 100644 --- a/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.java +++ b/sofa-serverless-runtime/arklet-core/src/test/java/com/alipay/sofa/serverless/arklet/core/util/AssertUtilsTests.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 org.junit.Assert;