Skip to content

Commit

Permalink
[ISSUE #2847] Fix config IT (#3120)
Browse files Browse the repository at this point in the history
* improvement: merge upstream/develop

* fix: fix config ut bug

* style: fix code style

* fix: fix ut bug
  • Loading branch information
chuntaojun authored Jun 19, 2020
1 parent 532aad6 commit bb7cfbc
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,4 @@ private static void checkState() {
throw new IllegalStateException("WatchFileCenter already shutdown");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -90,6 +92,12 @@ public void cleanup() throws Exception {
Assert.fail();
}
}

@BeforeClass
@AfterClass
public static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}

/**
* @TCDescription : nacos_正常获取数据
Expand Down Expand Up @@ -383,10 +391,13 @@ public void nacos_addListener_3() throws InterruptedException, NacosException {
final AtomicInteger count = new AtomicInteger(0);
final String dataId = "nacos_addListener_3";
final String group = "nacos_addListener_3";
final String content = "test-abc";
final String newContent = "nacos_addListener_3";
final String content = "test-abc-" + System.currentTimeMillis();
final String newContent = "nacos_addListener_3-" + System.currentTimeMillis();
boolean result = iconfig.publishConfig(dataId, group, content);
Assert.assertTrue(result);

// Maximum assurance level notification has been performed
ThreadUtils.sleep(5000);

Listener ml = new AbstractListener() {
@Override
Expand All @@ -395,7 +406,8 @@ public void receiveConfigInfo(String configInfo) {
Assert.assertEquals(newContent, configInfo);
}
};
iconfig.addListener(dataId, group, ml);
String receive = iconfig.getConfigAndSignListener(dataId, group, 5000L, ml);
Assert.assertEquals(content, receive);
result = iconfig.publishConfig(dataId, group, newContent);
Assert.assertTrue(result);
// Get enough sleep to ensure that the monitor is triggered only once
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
import com.alibaba.nacos.test.base.Params;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -61,6 +63,12 @@ public class ConfigBeta_CITCase {
String tenant = "dungu";
String content = "test";
String appName = "nacos";

@BeforeClass
@AfterClass
public static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}

@Before
public void init() throws NacosException {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.test.config;

import com.alibaba.nacos.client.config.impl.LocalConfigInfoProcessor;
import com.alibaba.nacos.core.utils.DiskUtils;

import java.io.IOException;

/**
* Cache files to clear tool classes.
*
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
public class ConfigCleanUtils {

public static void cleanClientCache() throws IOException {
DiskUtils.deleteDirThenMkdir(LocalConfigInfoProcessor.LOCAL_SNAPSHOT_PATH);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public class ConfigExportAndImportAPI_CITCase {
private String SERVER_ADDR = null;

private HttpAgent agent = null;


@BeforeClass
@AfterClass
public static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}

@Before
public void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.listener.impl.AbstractConfigChangeListener;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -46,6 +48,12 @@ public class ConfigLongPollReturnChanges_CITCase {
private int port;

private ConfigService configService;

@BeforeClass
@AfterClass
public static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}

@Before
public void init() throws NacosException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -47,6 +49,12 @@ public class ConfigLongPoll_CITCase {
private int port;

private ConfigService configService;

@BeforeClass
@AfterClass
public static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}

@Before
public void init() throws NacosException {
Expand Down

0 comments on commit bb7cfbc

Please sign in to comment.