wgy8283335 commented on a change in pull request #3620: Apollo as a ConfigCenter. URL: https://github.com/apache/incubator-shardingsphere/pull/3620#discussion_r352267897
########## File path: sharding-orchestration/sharding-orchestration-center/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloInstanceTest.java ########## @@ -0,0 +1,80 @@ +/* + * 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 org.apache.shardingsphere.orchestration.center.instance; + +import com.ctrip.framework.apollo.Config; +import com.ctrip.framework.apollo.openapi.client.ApolloOpenApiClient; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; +import lombok.SneakyThrows; +import org.apache.shardingsphere.orchestration.center.api.ConfigCenter; +import org.apache.shardingsphere.orchestration.center.instance.node.ConfigTreeNode; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.internal.util.reflection.FieldSetter; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Set; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public final class ApolloInstanceTest { + + private static ConfigCenter configCenter = new ApolloInstance(); + + @BeforeClass + @SneakyThrows + public static void init() { + Config apolloConfig = mock(Config.class); + when(apolloConfig.getProperty("test.children.1", "")).thenReturn("value1"); + FieldSetter.setField(configCenter, ApolloInstance.class.getDeclaredField("apolloConfig"), apolloConfig); + Set<String> instanceKeys = Sets.newHashSet(); + instanceKeys.add("test.children.1"); + instanceKeys.add("test.children.2"); + instanceKeys.add("test1.children.3"); + ConfigTreeNode root = new ConfigTreeNode(null, "/", Sets.<ConfigTreeNode>newHashSet()); + root.initTree(instanceKeys, "."); Review comment: Shall we provide one initialize method to make creating a config tree node more easily, as we need two lines now? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
