Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

record meta space #138

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,49 @@
import lombok.Getter;
import lombok.Setter;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;

/**
* @author mingmen
* @date 2023/6/8
*/
public class InstallBizHandler extends
AbstractCommandHandler<InstallBizHandler.Input, ClientResponse>
implements
ArkBizOps {
public class InstallBizHandler
extends
AbstractCommandHandler<InstallBizHandler.Input, InstallBizHandler.InstallBizClientResponse>
implements
ArkBizOps {

@Override
public Output<ClientResponse> handle(Input input) {
public Output<InstallBizClientResponse> handle(Input input) {
MemoryPoolMXBean metaSpaceMXBean = getMetaSpaceMXBean();
long startSpace = metaSpaceMXBean.getUsage().getUsed();

Check warning on line 50 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L49-L50

Added lines #L49 - L50 were not covered by tests
InstallBizClientResponse installBizClientResponse;
try {
ClientResponse res = getOperationService().install(input.getBizUrl());
installBizClientResponse = (InstallBizClientResponse) res;
installBizClientResponse.setElapsedSpace(metaSpaceMXBean.getUsage().getUsed()

Check warning on line 55 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L54-L55

Added lines #L54 - L55 were not covered by tests
- startSpace);
if (ResponseCode.SUCCESS.equals(res.getCode())) {
return Output.ofSuccess(res);
return Output.ofSuccess(installBizClientResponse);

Check warning on line 58 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L58

Added line #L58 was not covered by tests
} else {
return Output.ofFailed(res, "install biz not success!");
return Output.ofFailed(installBizClientResponse, "install biz not success!");

Check warning on line 60 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L60

Added line #L60 was not covered by tests
}
} catch (Throwable e) {
throw new ArkletRuntimeException(e);
}
}

private MemoryPoolMXBean getMetaSpaceMXBean() {
MemoryPoolMXBean metaSpaceMXBean = null;
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();

Check warning on line 69 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L68-L69

Added lines #L68 - L69 were not covered by tests
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans)
if (memoryPoolMXBean.getName().equals("Metaspace"))
metaSpaceMXBean = memoryPoolMXBean;
return metaSpaceMXBean;

Check warning on line 73 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L72-L73

Added lines #L72 - L73 were not covered by tests
}

@Override
public Command command() {
return BuiltinCommand.INSTALL_BIZ;
Expand All @@ -73,4 +93,10 @@
private String bizUrl;
}

@Getter
@Setter
public static class InstallBizClientResponse extends ClientResponse {
private long elapsedSpace;

Check warning on line 99 in sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java

View check run for this annotation

Codecov / codecov/patch

sofa-serverless-runtime/arklet-core/src/main/java/com/alipay/sofa/serverless/arklet/core/command/builtin/handler/InstallBizHandler.java#L97-L99

Added lines #L97 - L99 were not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
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.builtin.handler.InstallBizHandler;
import com.alipay.sofa.serverless.arklet.core.health.custom.CustomBizManagerService;
import com.alipay.sofa.serverless.arklet.core.health.custom.CustomPluginManagerService;
import org.junit.After;
Expand All @@ -35,9 +35,9 @@
*/
public class BaseHandlerTest extends BaseTest {

public final ClientResponse success = new ClientResponse();
public final ClientResponse failed = new ClientResponse();
public MockedStatic<ArkClient> arkClient;
public final InstallBizHandler.InstallBizClientResponse success = new InstallBizHandler.InstallBizClientResponse();
public final InstallBizHandler.InstallBizClientResponse failed = new InstallBizHandler.InstallBizClientResponse();
public MockedStatic<ArkClient> arkClient;

@Before
public void setupHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.serverless.arklet.core.command.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.builtin.handler.InstallBizHandler;
import com.alipay.sofa.serverless.arklet.core.command.builtin.handler.InstallBizHandler.Input;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void testHandle_Success() throws Throwable {

when(handler.getOperationService().install(input.getBizUrl())).thenReturn(success);

Output<ClientResponse> result = handler.handle(input);
Output<?> result = handler.handle(input);

Assert.assertEquals(success, result.getData());
Assert.assertTrue(result.success());
Expand All @@ -61,7 +60,7 @@ public void testHandle_Failure() throws Throwable {

when(handler.getOperationService().install(input.getBizUrl())).thenReturn(failed);

Output<ClientResponse> result = handler.handle(input);
Output<InstallBizHandler.InstallBizClientResponse> result = handler.handle(input);

Assert.assertSame(failed, result.getData());
Assert.assertTrue(result.failed());
Expand Down
Loading