Commit f454e0b2 by Nepxion

修改测试用例

parent fa229594
......@@ -10,10 +10,11 @@ package com.nepxion.discovery.plugin.example.impl;
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
import com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader;
// 模拟从本地配置或远程配置中心获取配置
......@@ -21,7 +22,13 @@ public class DiscoveryConfigLoader extends AbstractConfigLoader {
@Override
public InputStream getRemoteInputStream() {
// 本地文件模拟代替远程文件
return getInputStream("src/main/resources/rule1.xml");
try {
return FileUtils.openInputStream(new File("src/main/resources/rule1.xml"));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
......@@ -32,14 +39,4 @@ public class DiscoveryConfigLoader extends AbstractConfigLoader {
// 配置文件放在工程根目录下
// return "file:rule1.xml";
}
private InputStream getInputStream(String fileName) {
try {
return new FileInputStream(new File(fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
}
\ No newline at end of file
......@@ -10,8 +10,7 @@ package com.nepxion.discovery.plugin.example.impl;
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
......@@ -19,6 +18,7 @@ import java.util.concurrent.ThreadLocalRandom;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.nepxion.discovery.plugin.framework.event.PluginPublisher;
......@@ -39,19 +39,14 @@ public class DiscoveryConfigSubscriber {
// 本地文件模拟代替远程文件,随机读取
int index = threadLocalRandom.nextInt(5) + 1;
System.out.println("-------------------- rule" + index + ".xml is loaded --------------------");
InputStream inputStream = getInputStream("src/main/resources/rule" + index + ".xml");
pluginPublisher.publish(inputStream);
}
}, 10000L, 15000L);
}
private InputStream getInputStream(String fileName) {
try {
return new FileInputStream(new File(fileName));
} catch (FileNotFoundException e) {
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule" + index + ".xml"));
pluginPublisher.publish(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}, 10000L, 15000L);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment