diff --git a/common/src/main/java/com/alibaba/nacos/common/Beta.java b/common/src/main/java/com/alibaba/nacos/common/Beta.java new file mode 100644 index 000000000..c880a7de9 --- /dev/null +++ b/common/src/main/java/com/alibaba/nacos/common/Beta.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.common; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Means a class is in beta version. + * + * @author wuzhiguo + */ +@Documented +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.SOURCE) +public @interface Beta { + +} diff --git a/consistency/src/main/java/com/alibaba/nacos/consistency/IdGenerator.java b/consistency/src/main/java/com/alibaba/nacos/consistency/IdGenerator.java index 29abfdefb..22de686e3 100644 --- a/consistency/src/main/java/com/alibaba/nacos/consistency/IdGenerator.java +++ b/consistency/src/main/java/com/alibaba/nacos/consistency/IdGenerator.java @@ -37,6 +37,13 @@ public interface IdGenerator { */ long currentId(); + /** + * worker id info. + * + * @return worker id + */ + long workerId(); + /** * Get next id. * diff --git a/core/src/main/java/com/alibaba/nacos/core/cluster/ServerMemberManager.java b/core/src/main/java/com/alibaba/nacos/core/cluster/ServerMemberManager.java index 5a9317c0b..977bbdd39 100644 --- a/core/src/main/java/com/alibaba/nacos/core/cluster/ServerMemberManager.java +++ b/core/src/main/java/com/alibaba/nacos/core/cluster/ServerMemberManager.java @@ -236,7 +236,7 @@ public class ServerMemberManager implements ApplicationListener raftOps(@RequestBody Map commands) { + return protocolManager.getCpProtocol().execute(commands); + } + + /** + * Gets the current health of the ID generator. + * + * @return {@link RestResult} + */ + @GetMapping(value = "/ids") + public RestResult> ids() { + List result = new ArrayList<>(); + idGeneratorManager.getGeneratorMap().forEach((resource, idGenerator) -> { + IdGeneratorVO vo = new IdGeneratorVO(); + vo.setResource(resource); + + IdGeneratorVO.IdInfo info = new IdGeneratorVO.IdInfo(); + info.setCurrentId(idGenerator.currentId()); + info.setWorkerId(idGenerator.workerId()); + vo.setInfo(info); + + result.add(vo); + }); + + return RestResultUtils.success(result); + } + + @PutMapping(value = "/log") + public RestResult updateLog(@RequestBody LogUpdateRequest logUpdateRequest) { + Loggers.setLogLevel(logUpdateRequest.getLogName(), logUpdateRequest.getLogLevel()); + return RestResultUtils.success(); + } + +} diff --git a/core/src/main/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2Controller.java b/core/src/main/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2Controller.java new file mode 100644 index 000000000..f62b1aa64 --- /dev/null +++ b/core/src/main/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2Controller.java @@ -0,0 +1,226 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.controller.v2; + +import com.alibaba.nacos.common.Beta; +import com.alibaba.nacos.common.http.Callback; +import com.alibaba.nacos.common.http.HttpClientBeanHolder; +import com.alibaba.nacos.common.http.HttpUtils; +import com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate; +import com.alibaba.nacos.common.http.param.Header; +import com.alibaba.nacos.common.model.RestResult; +import com.alibaba.nacos.common.model.RestResultUtils; +import com.alibaba.nacos.common.utils.LoggerUtils; +import com.alibaba.nacos.common.utils.StringUtils; +import com.alibaba.nacos.core.cluster.Member; +import com.alibaba.nacos.core.cluster.MemberUtil; +import com.alibaba.nacos.core.cluster.NodeState; +import com.alibaba.nacos.core.cluster.ServerMemberManager; +import com.alibaba.nacos.core.model.request.LookupUpdateRequest; +import com.alibaba.nacos.core.utils.Commons; +import com.alibaba.nacos.core.utils.GenericType; +import com.alibaba.nacos.core.utils.Loggers; +import com.alibaba.nacos.sys.env.EnvUtil; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Cluster communication interface v2. + * + * @author wuzhiguo + */ +@Beta +@RestController +@RequestMapping(Commons.NACOS_CORE_CONTEXT_V2 + "/cluster") +public class NacosClusterV2Controller { + + private final ServerMemberManager memberManager; + + public NacosClusterV2Controller(ServerMemberManager memberManager) { + this.memberManager = memberManager; + } + + @GetMapping(value = "/nodes/self") + public RestResult self() { + return RestResultUtils.success(memberManager.getSelf()); + } + + /** + * The console displays the list of cluster members. + * + * @param address match address + * @param state match state + * + * @return members that matches condition + */ + @GetMapping(value = "/nodes") + public RestResult> listNodes( + @RequestParam(value = "address", required = false) String address, + @RequestParam(value = "state", required = false) String state) { + + NodeState nodeState = null; + if (StringUtils.isNoneBlank(state)) { + try { + nodeState = NodeState.valueOf(state.toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException e) { + return RestResultUtils.failedWithMsg(400, "Illegal state: " + state); + } + } + + Collection members = memberManager.allMembers(); + Collection result = new ArrayList<>(); + + for (Member member : members) { + if (StringUtils.isNoneBlank(address) && !StringUtils.startsWith(member.getAddress(), address)) { + continue; + } + + if (nodeState != null && member.getState() != nodeState) { + continue; + } + + result.add(member); + } + + return RestResultUtils.success(result); + } + + // The client can get all the nacos node information in the current + // cluster according to this interface + + /** + * Other nodes return their own metadata information. + * + * @param nodes List of {@link Member} + * @return {@link RestResult} + */ + @PutMapping(value = "/nodes") + public RestResult updateNodes(@RequestBody List nodes) { + for (Member node : nodes) { + if (!node.check()) { + LoggerUtils.printIfWarnEnabled(Loggers.CLUSTER, "node information is illegal, ignore node: {}", node); + continue; + } + + LoggerUtils.printIfDebugEnabled(Loggers.CLUSTER, "node state updating, node: {}", node); + node.setState(NodeState.UP); + node.setFailAccessCnt(0); + + boolean update = memberManager.update(node); + if (!update) { + LoggerUtils.printIfErrorEnabled(Loggers.CLUSTER, "node state update failed, node: {}", node); + } + } + + return RestResultUtils.success(); + } + + /** + * Addressing mode switch. + * + * @param request {@link LookupUpdateRequest} + * @return {@link RestResult} + */ + @PutMapping(value = "/lookup") + public RestResult updateLookup(@RequestBody LookupUpdateRequest request) { + try { + memberManager.switchLookup(request.getType()); + return RestResultUtils.success(); + } catch (Throwable ex) { + return RestResultUtils.failed(ex.getMessage()); + } + } + + /** + * member leave. + * + * @param addresses member ip list, example [ip1:port1,ip2:port2,...] + * @return {@link RestResult} + * @throws Exception throw {@link Exception} + */ + @DeleteMapping("/nodes") + public RestResult deleteNodes(@RequestParam("addresses") List addresses) throws Exception { + Collection memberList = MemberUtil.multiParse(addresses); + memberManager.memberLeave(memberList); + final NacosAsyncRestTemplate nacosAsyncRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate( + Loggers.CLUSTER); + final GenericType> genericType = new GenericType>() { + }; + final Collection notifyList = memberManager.allMembersWithoutSelf(); + notifyList.removeAll(memberList); + CountDownLatch latch = new CountDownLatch(notifyList.size()); + for (Member member : notifyList) { + final String url = HttpUtils.buildUrl(false, member.getAddress(), EnvUtil.getContextPath(), + Commons.NACOS_CORE_CONTEXT_V2, "/cluster/nodes"); + nacosAsyncRestTemplate.delete(url, Header.EMPTY, StringUtils.join(addresses, ","), genericType.getType(), + new Callback() { + @Override + public void onReceive(RestResult result) { + try { + if (result.ok()) { + LoggerUtils.printIfDebugEnabled(Loggers.CLUSTER, + "The node : [{}] success to process the request", member); + MemberUtil.onSuccess(memberManager, member); + } else { + Loggers.CLUSTER.warn( + "The node : [{}] failed to process the request, response is : {}", member, + result); + MemberUtil.onFail(memberManager, member); + } + } finally { + latch.countDown(); + } + } + + @Override + public void onError(Throwable throwable) { + try { + Loggers.CLUSTER.error("Failed to communicate with the node : {}", member); + MemberUtil.onFail(memberManager, member); + } finally { + latch.countDown(); + } + } + + @Override + public void onCancel() { + + } + }); + } + + try { + latch.await(10_000, TimeUnit.MILLISECONDS); + return RestResultUtils.success(); + } catch (Throwable ex) { + return RestResultUtils.failed(ex.getMessage()); + } + } + +} diff --git a/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java b/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java index 50d310477..ae0841279 100644 --- a/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java +++ b/core/src/main/java/com/alibaba/nacos/core/distributed/id/SnowFlowerIdGenerator.java @@ -115,6 +115,11 @@ public class SnowFlowerIdGenerator implements IdGenerator { return currentId; } + @Override + public long workerId() { + return workerId; + } + @Override public synchronized long nextId() { long currentMillis = currentTimeMillis(); diff --git a/core/src/main/java/com/alibaba/nacos/core/model/request/LogUpdateRequest.java b/core/src/main/java/com/alibaba/nacos/core/model/request/LogUpdateRequest.java new file mode 100644 index 000000000..6f8cc6749 --- /dev/null +++ b/core/src/main/java/com/alibaba/nacos/core/model/request/LogUpdateRequest.java @@ -0,0 +1,45 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.request; + +/** + * Request entity for log operator interface. + * + * @author wuzhiguo + */ +public class LogUpdateRequest { + + private String logName; + + private String logLevel; + + public String getLogName() { + return logName; + } + + public void setLogName(String logName) { + this.logName = logName; + } + + public String getLogLevel() { + return logLevel; + } + + public void setLogLevel(String logLevel) { + this.logLevel = logLevel; + } +} diff --git a/core/src/main/java/com/alibaba/nacos/core/model/request/LookupUpdateRequest.java b/core/src/main/java/com/alibaba/nacos/core/model/request/LookupUpdateRequest.java new file mode 100644 index 000000000..56d6e5bcb --- /dev/null +++ b/core/src/main/java/com/alibaba/nacos/core/model/request/LookupUpdateRequest.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.request; + +/** + * Update member lookup type. + * + * @author wuzhiguo + */ +public class LookupUpdateRequest { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/core/src/main/java/com/alibaba/nacos/core/model/vo/IdGeneratorVO.java b/core/src/main/java/com/alibaba/nacos/core/model/vo/IdGeneratorVO.java new file mode 100644 index 000000000..60a0ddab9 --- /dev/null +++ b/core/src/main/java/com/alibaba/nacos/core/model/vo/IdGeneratorVO.java @@ -0,0 +1,78 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.vo; + +/** + * Id generator vo. + * + * @author wuzhiguo + */ +public class IdGeneratorVO { + + private String resource; + + private IdInfo info; + + public String getResource() { + return resource; + } + + public void setResource(String resource) { + this.resource = resource; + } + + public IdInfo getInfo() { + return info; + } + + public void setInfo(IdInfo info) { + this.info = info; + } + + public static class IdInfo { + + private Long currentId; + + private Long workerId; + + public Long getCurrentId() { + return currentId; + } + + public void setCurrentId(Long currentId) { + this.currentId = currentId; + } + + public Long getWorkerId() { + return workerId; + } + + public void setWorkerId(Long workerId) { + this.workerId = workerId; + } + + @Override + public String toString() { + return "IdInfo{" + "currentId=" + currentId + ", workerId=" + workerId + '}'; + } + } + + @Override + public String toString() { + return "IdGeneratorVO{" + "resource='" + resource + '\'' + ", info=" + info + '}'; + } +} diff --git a/core/src/test/java/com/alibaba/nacos/core/controller/v2/CoreOpsV2ControllerTest.java b/core/src/test/java/com/alibaba/nacos/core/controller/v2/CoreOpsV2ControllerTest.java new file mode 100644 index 000000000..d3ecfaf6c --- /dev/null +++ b/core/src/test/java/com/alibaba/nacos/core/controller/v2/CoreOpsV2ControllerTest.java @@ -0,0 +1,102 @@ +/* + * Copyright 1999-2021 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.controller.v2; + +import com.alibaba.nacos.common.model.RestResult; +import com.alibaba.nacos.common.model.RestResultUtils; +import com.alibaba.nacos.consistency.IdGenerator; +import com.alibaba.nacos.consistency.cp.CPProtocol; +import com.alibaba.nacos.core.distributed.ProtocolManager; +import com.alibaba.nacos.core.distributed.id.IdGeneratorManager; +import com.alibaba.nacos.core.distributed.id.SnowFlowerIdGenerator; +import com.alibaba.nacos.core.model.request.LogUpdateRequest; +import com.alibaba.nacos.core.model.vo.IdGeneratorVO; +import com.alibaba.nacos.core.utils.Loggers; +import com.alibaba.nacos.sys.env.EnvUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.mock.env.MockEnvironment; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@RunWith(MockitoJUnitRunner.class) +public class CoreOpsV2ControllerTest { + + @InjectMocks + private CoreOpsV2Controller coreOpsV2Controller; + + @Mock + private ProtocolManager protocolManager; + + @Mock + private IdGeneratorManager idGeneratorManager; + + private final MockEnvironment mockEnvironment = new MockEnvironment(); + + @Before + public void setUp() { + EnvUtil.setEnvironment(mockEnvironment); + } + + @Test + public void testRaftOps() { + Mockito.when(protocolManager.getCpProtocol()).thenAnswer(invocationOnMock -> { + CPProtocol cpProtocol = Mockito.mock(CPProtocol.class); + Mockito.when(cpProtocol.execute(Mockito.anyMap())).thenReturn(RestResultUtils.success("res")); + return cpProtocol; + }); + + RestResult result = coreOpsV2Controller.raftOps(new HashMap<>()); + Assert.assertEquals("res", result.getData()); + } + + @Test + public void testIdInfo() { + mockEnvironment.setProperty("nacos.core.snowflake.worker-id", "1"); + + Map idGeneratorMap = new HashMap<>(); + idGeneratorMap.put("resource", new SnowFlowerIdGenerator()); + Mockito.when(idGeneratorManager.getGeneratorMap()).thenReturn(idGeneratorMap); + RestResult> res = coreOpsV2Controller.ids(); + + Assert.assertTrue(res.ok()); + Assert.assertEquals(1, res.getData().size()); + Assert.assertEquals("resource", res.getData().get(0).getResource()); + Assert.assertEquals(1L, res.getData().get(0).getInfo().getWorkerId().longValue()); + Assert.assertEquals(0L, res.getData().get(0).getInfo().getCurrentId().longValue()); + } + + @Test + public void testSetLogLevel() { + LogUpdateRequest request = new LogUpdateRequest(); + request.setLogName("core"); + request.setLogLevel("debug"); + RestResult res = coreOpsV2Controller.updateLog(request); + + Assert.assertTrue(res.ok()); + Assert.assertTrue(Loggers.CORE.isDebugEnabled()); + } +} diff --git a/core/src/test/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2ControllerTest.java b/core/src/test/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2ControllerTest.java new file mode 100644 index 000000000..93c4afee7 --- /dev/null +++ b/core/src/test/java/com/alibaba/nacos/core/controller/v2/NacosClusterV2ControllerTest.java @@ -0,0 +1,115 @@ +/* + * Copyright 1999-2021 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.controller.v2; + +import com.alibaba.nacos.common.model.RestResult; +import com.alibaba.nacos.core.cluster.Member; +import com.alibaba.nacos.core.cluster.NodeState; +import com.alibaba.nacos.core.cluster.ServerMemberManager; +import com.alibaba.nacos.core.model.request.LookupUpdateRequest; +import com.alibaba.nacos.sys.env.EnvUtil; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.mock.env.MockEnvironment; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class NacosClusterV2ControllerTest { + + @InjectMocks + private NacosClusterV2Controller nacosClusterV2Controller; + + @Mock + private ServerMemberManager serverMemberManager; + + private final MockEnvironment environment = new MockEnvironment(); + + @Before + public void setUp() { + EnvUtil.setEnvironment(environment); + } + + @Test + public void testSelf() { + Member self = new Member(); + Mockito.when(serverMemberManager.getSelf()).thenReturn(self); + + RestResult result = nacosClusterV2Controller.self(); + Assert.assertTrue(result.ok()); + Assert.assertEquals(self, result.getData()); + } + + @Test + public void testListNodes() { + Member member1 = new Member(); + member1.setIp("1.1.1.1"); + member1.setPort(8848); + member1.setState(NodeState.DOWN); + Member member2 = new Member(); + member2.setIp("2.2.2.2"); + member2.setPort(8848); + + List members = Arrays.asList(member1, member2); + Mockito.when(serverMemberManager.allMembers()).thenReturn(members); + + RestResult> result1 = nacosClusterV2Controller.listNodes("1.1.1.1", null); + Assert.assertTrue(result1.getData().stream().findFirst().isPresent()); + Assert.assertEquals("1.1.1.1:8848", result1.getData().stream().findFirst().get().getAddress()); + + RestResult> result2 = nacosClusterV2Controller.listNodes(null, "up"); + Assert.assertTrue(result2.getData().stream().findFirst().isPresent()); + Assert.assertEquals("2.2.2.2:8848", result2.getData().stream().findFirst().get().getAddress()); + } + + @Test + public void testUpdate() { + Mockito.when(serverMemberManager.update(Mockito.any())).thenReturn(true); + + Member member = new Member(); + member.setIp("1.1.1.1"); + member.setPort(8848); + member.setAddress("test"); + RestResult result = nacosClusterV2Controller.updateNodes(Collections.singletonList(member)); + Assert.assertTrue(result.ok()); + } + + @Test + public void testSwitchLookup() { + LookupUpdateRequest request = new LookupUpdateRequest(); + request.setType("test"); + + RestResult result = nacosClusterV2Controller.updateLookup(request); + Assert.assertTrue(result.ok()); + } + + @Test + public void testLeave() throws Exception { + RestResult result = nacosClusterV2Controller.deleteNodes(Collections.singletonList("1.1.1.1")); + Assert.assertTrue(result.ok()); + } +} diff --git a/core/src/test/java/com/alibaba/nacos/core/model/request/LogUpdateRequestTest.java b/core/src/test/java/com/alibaba/nacos/core/model/request/LogUpdateRequestTest.java new file mode 100644 index 000000000..c5eabe5cc --- /dev/null +++ b/core/src/test/java/com/alibaba/nacos/core/model/request/LogUpdateRequestTest.java @@ -0,0 +1,33 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.request; + +import org.junit.Assert; +import org.junit.Test; + +public class LogUpdateRequestTest { + + @Test + public void test() { + LogUpdateRequest request = new LogUpdateRequest(); + request.setLogName("test"); + request.setLogLevel("info"); + + Assert.assertEquals(request.getLogName(), "test"); + Assert.assertEquals(request.getLogLevel(), "info"); + } +} diff --git a/core/src/test/java/com/alibaba/nacos/core/model/request/LookupUpdateRequestTest.java b/core/src/test/java/com/alibaba/nacos/core/model/request/LookupUpdateRequestTest.java new file mode 100644 index 000000000..4414dec78 --- /dev/null +++ b/core/src/test/java/com/alibaba/nacos/core/model/request/LookupUpdateRequestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.request; + +import org.junit.Assert; +import org.junit.Test; + +public class LookupUpdateRequestTest { + + @Test + public void test() { + LookupUpdateRequest request = new LookupUpdateRequest(); + request.setType("type"); + + Assert.assertEquals(request.getType(), "type"); + } +} diff --git a/core/src/test/java/com/alibaba/nacos/core/model/vo/IdGeneratorVOTest.java b/core/src/test/java/com/alibaba/nacos/core/model/vo/IdGeneratorVOTest.java new file mode 100644 index 000000000..63e06a5b3 --- /dev/null +++ b/core/src/test/java/com/alibaba/nacos/core/model/vo/IdGeneratorVOTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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.alibaba.nacos.core.model.vo; + +import org.junit.Assert; +import org.junit.Test; + +public class IdGeneratorVOTest { + + @Test + public void test() { + IdGeneratorVO vo = new IdGeneratorVO(); + IdGeneratorVO.IdInfo info = new IdGeneratorVO.IdInfo(); + info.setWorkerId(1L); + info.setCurrentId(2L); + vo.setResource("test"); + vo.setInfo(info); + + Assert.assertEquals(vo.getInfo(), info); + Assert.assertEquals(vo.getResource(), "test"); + Assert.assertEquals(vo.getInfo().getWorkerId().longValue(), 1L); + Assert.assertEquals(vo.getInfo().getCurrentId().longValue(), 2L); + } +} diff --git a/style/NacosCheckStyle.xml b/style/NacosCheckStyle.xml index c55ea6b48..c44031b63 100644 --- a/style/NacosCheckStyle.xml +++ b/style/NacosCheckStyle.xml @@ -60,6 +60,7 @@ +