diff --git a/client/src/test/java/com/alibaba/nacos/client/ConfigLongPollTest.java b/client/src/test/java/com/alibaba/nacos/client/ConfigLongPollTest.java deleted file mode 100644 index 845205748..000000000 --- a/client/src/test/java/com/alibaba/nacos/client/ConfigLongPollTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.client; - -import com.alibaba.nacos.api.NacosFactory; -import com.alibaba.nacos.api.PropertyKeyConst; -import com.alibaba.nacos.api.config.ConfigService; -import com.alibaba.nacos.api.config.listener.Listener; -import com.alibaba.nacos.api.exception.NacosException; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.Properties; -import java.util.concurrent.Executor; - -/** - * @author liaochuntao - * @date 2019-06-07 16:37 - **/ -@Ignore -public class ConfigLongPollTest { - - private ConfigService configService; - - @Before - public void init() throws NacosException { - Properties properties = new Properties(); - properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); - properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, 2000); - properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, 5000); - configService = NacosFactory.createConfigService(properties); - } - - @Test - public void test() throws InterruptedException, NacosException { - - synchronized (this) { - - configService.addListener("test", "DEFAULT_GROUP", new Listener() { - @Override - public Executor getExecutor() { - return null; - } - - @Override - public void receiveConfigInfo(String configInfo) { - System.out.println(configInfo); - } - }); - - configService.addListener("test-1", "DEFAULT_GROUP", new Listener() { - @Override - public Executor getExecutor() { - return null; - } - - @Override - public void receiveConfigInfo(String configInfo) { - System.out.println(configInfo); - } - }); - - wait(); - } - - } - -} diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigLongPoll_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigLongPoll_ITCase.java new file mode 100644 index 000000000..63237061a --- /dev/null +++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigLongPoll_ITCase.java @@ -0,0 +1,89 @@ +/* + * 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.test.config; + +import com.alibaba.nacos.api.NacosFactory; +import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.api.config.ConfigService; +import com.alibaba.nacos.api.config.listener.Listener; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.config.server.Config; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Properties; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; + +/** + * @author liaochuntao + * @date 2019-06-07 22:24 + **/ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Config.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class ConfigLongPoll_ITCase { + + @LocalServerPort + private int port; + + private ConfigService configService; + + @Before + public void init() throws NacosException { + Properties properties = new Properties(); + properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:" + port); + properties.put(PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT, 2000); + properties.put(PropertyKeyConst.CONFIG_RETRY_TIME, 3000); + configService = NacosFactory.createConfigService(properties); + } + + @Test + public void test() throws InterruptedException, NacosException { + + configService.addListener("test", "DEFAULT_GROUP", new Listener() { + @Override + public Executor getExecutor() { + return null; + } + + @Override + public void receiveConfigInfo(String configInfo) { + System.out.println(configInfo); + } + }); + + configService.addListener("test-1", "DEFAULT_GROUP", new Listener() { + @Override + public Executor getExecutor() { + return null; + } + + @Override + public void receiveConfigInfo(String configInfo) { + System.out.println(configInfo); + } + }); + + TimeUnit.SECONDS.sleep(30); + + } + +}