Skip to content

Commit

Permalink
fix actuator pom, and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdClear committed Sep 25, 2023
1 parent 53a123c commit 48ee18c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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> arkClient;

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.junit.Before;
import org.junit.Test;


/**
* @author lunarscave
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void validateBizListHealth(Health health, final List<Biz> expectedBizLis
Object realBiz = realBizList.get(i);
Biz expectedBiz = expectedBizList.get(i);
Assert.assertTrue(realBiz instanceof BizHealthMeta);
validateBiz((BizHealthMeta)realBiz, expectedBiz);
validateBiz((BizHealthMeta) realBiz, expectedBiz);
}
}

Expand All @@ -75,25 +75,26 @@ private void validatePluginListHealth(Health health, final List<Plugin> 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<Biz> expectedBizList, final List<Plugin> expectedPluginList, final Biz expectedMasterBiz) {
private void validateHealth(Health health, final List<Biz> expectedBizList,
final List<Plugin> 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) {
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);
validateBiz((BizHealthMeta) realBiz, expectedBiz);
}

private void validateHealth(Health health, final Plugin expectedPlugin) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,13 +29,12 @@

public class CustomBizManagerService implements BizManagerService {

private final List<Biz> bizList = Arrays.asList(new Biz[]{
private final List<Biz> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,10 +26,9 @@

public class CustomPluginManagerService implements PluginManagerService {

private final List<Plugin> pluginList = Arrays.asList(new Plugin[]{
private final List<Plugin> pluginList = Arrays.asList(new Plugin[] {
new CustomPlugin("testPlugin1", "testPluginVersion1"),
new CustomPlugin("testPlugin2", "testPluginVersion2")
});
new CustomPlugin("testPlugin2", "testPluginVersion2") });

@Override
public void registerPlugin(Plugin plugin) {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 48ee18c

Please sign in to comment.