diff options
author | yangyan <yangyanyj@chinamobile.com> | 2018-03-22 13:50:00 +0800 |
---|---|---|
committer | yangyan <yangyanyj@chinamobile.com> | 2018-03-22 13:50:32 +0800 |
commit | db3106cd598bdcf002643da03b3278af719ed7b0 (patch) | |
tree | 84c0e3d7055eb63326ef9bb0f7c917c5cde1ffd2 | |
parent | 844b0ab933e484c3c3367ad89481c7dc1f6a6565 (diff) |
Fix stream closed bug and improve test code
Issue-ID: VFC-836
Change-Id: Ia3e4dac565b68205b4c59d6af01b217ff915f260
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
9 files changed, 143 insertions, 92 deletions
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java index 94d9c56..f4ffe06 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java @@ -104,7 +104,7 @@ public class TaskThread implements Runnable { String nename = ma.group(1); boolean parseResult = false; if (Constant.COLLECT_TYPE_CM.equalsIgnoreCase(collectVo.getType())) { - parseResult = processCMXml(tempfile, nename, "CM"); + //parseResult = processCMXml(tempfile, nename, "CM");//The logic is not exist now, but need to add in the future } else { if (unfileName.indexOf(".csv") > -1) {//changed to -1 for coding practice as having ".csv" must have some some legal name parseResult = processPMCsv(tempfile); @@ -373,7 +373,7 @@ public class TaskThread implements Runnable { } - private boolean processCMXml(File tempfile, String nename, String type) { +/* private boolean processCMXml(File tempfile, String nename, String type) { String csvpath = localPath + nename + "/" + type + "/"; File csvpathfile = new File(csvpath); @@ -499,7 +499,7 @@ public class TaskThread implements Runnable { return false; } return true; - } + }*/ private void setMessage(String message) { try { diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java index 6c6cebe..20dd4fd 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java @@ -115,6 +115,7 @@ public class AlarmTaskThread extends Thread { if (retString == null) { Thread.sleep(100); } + }//while return retString; diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtil.java index fc5cd71..313ce63 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtil.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtil.java @@ -68,8 +68,8 @@ public class MessageUtil { public static Msg readOneMsg(BufferedInputStream is) throws IOException { byte[] inputB = new byte[9]; Msg msg = new Msg(); + DataInputStream dis = new DataInputStream(is); try( - DataInputStream dis = new DataInputStream(is); ByteArrayInputStream bais = new ByteArrayInputStream(inputB); DataInputStream ois = new DataInputStream(bais)){ dis.readFully(inputB); @@ -87,6 +87,7 @@ public class MessageUtil { byte[] b = new byte[bodylength]; dis.readFully(b); msg.newBodyfromBytes(b); + } catch (Exception e) { throw new IOException("readOneMsg",e); } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java index 68665c7..2dbc568 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java @@ -58,21 +58,18 @@ public class AlarmSocketServer { Msg msg = new Msg("ackLoginAlarm;result=succ;resDesc= ", MsgType.ACK_LOGIN_ALARM); MessageUtil.writeMsg(msg, dos); - } - if (restlu.contains("reqHeartBeat")) { + } else if (restlu.contains("reqHeartBeat")) { Msg msg = new Msg("ackHeartBeat;result=succ;resDesc= ", MsgType.ACK_HEARTBEAT); MessageUtil.writeMsg(msg, dos); - } - Msg msg = new Msg("realTimeAlarm;result=succ;resDesc= ", MsgType.REALTIME_ALARM); - - MessageUtil.writeMsg(msg, dos); - - - } else { - System.out.println("len:" + len); + } + Msg msg = new Msg("realTimeAlarm;result=succ;resDesc= ", MsgType.REALTIME_ALARM); + MessageUtil.writeMsg(msg, dos); + + }else { + //System.out.println("len:" + len); Thread.sleep(10); - } + } } } catch (Exception e) { diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java index fc6c755..6b2b6c8 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java @@ -25,68 +25,64 @@ import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo; public class AlarmTaskThreadTest { - private AlarmTaskThread taskThread; - private AlarmSocketServer server; + private AlarmTaskThread taskThread; + private AlarmSocketServer server; - @Before - public void setUp() throws IOException { - new Thread() { - public void run() { - server = new AlarmSocketServer(); - server.socketServer(); - } - }.start(); + @Before + public void setUp() throws IOException { + new Thread() { + public void run() { + server = new AlarmSocketServer(); + server.socketServer(); + } + }.start(); + CollectVo collectVo = new CollectVo(); + collectVo.setIP("127.0.0.1"); + collectVo.setPort("12345"); + collectVo.setUser("user"); + collectVo.setPassword("12345"); + collectVo.setReadTimeout("10000"); + taskThread = new AlarmTaskThread(collectVo); + } - CollectVo collectVo = new CollectVo(); - collectVo.setIP("127.0.0.1"); - collectVo.setPort("12345"); - collectVo.setUser("user"); - collectVo.setPassword("12345"); - taskThread = new AlarmTaskThread(collectVo); - } - - @Test - public void build120Alarm() { - String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}"; - try { - new Thread() { - public void run() { - try { - Thread.sleep(3000); - - server.stop(); - taskThread.setStop(true); - taskThread.close(); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }.start(); - - taskThread.init(); - taskThread.receive(); - - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - assertNotNull(alarm); - } + @Test + public void build120Alarm() { + String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}"; + try { + new Thread() { + public void run() { + try { + Thread.sleep(3000); + server.stop(); + taskThread.setStop(true); + taskThread.close(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }.start(); + taskThread.init(); + taskThread.receive(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + assertNotNull(alarm); + } - @Test - public void runAlarmTaskThread(){ - try { - taskThread.run(); - Thread.sleep(3000); - taskThread.setStop(true); - server.stop(); + @Test + public void runAlarmTaskThread() { + try { + taskThread.run(); + Thread.sleep(10000); + taskThread.setStop(true); + server.stop(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } - } - + } + } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/HeartBeatTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/HeartBeatTest.java index 301d876..2ffb589 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/HeartBeatTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/HeartBeatTest.java @@ -38,7 +38,7 @@ public class HeartBeatTest { } @Test - public void runHeartBeatThread(){ + public void testHeartBeatThread(){ try { Socket socket = new Socket("127.0.0.1",12345); Msg msg = MessageUtil.putHeartBeatMsg(1); diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java index fb420ca..4ed614f 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectManagerTest.java @@ -33,10 +33,15 @@ public class CollectManagerTest { configurationInterface = new ConfigurationImp(); collectManager = new CollectManager(); collectManager.setConfigurationInterface(configurationInterface); - collectManager.dispose(); + //collectManager.dispose(); } @Test + public void testDispose(){ + collectManager.dispose(); + + } + @Test public void test() { Thread t = new Thread(collectManager); t.start(); diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectOderJobTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectOderJobTest.java index b7847b4..fedf50c 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectOderJobTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/CollectOderJobTest.java @@ -16,39 +16,86 @@ package org.onap.vfc.nfvo.emsdriver.taskscheduler;
+import java.util.Date;
+
import org.junit.Test;
import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
import org.quartz.Job;
+import org.quartz.JobDetail;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.impl.StdSchedulerFactory;
public class CollectOderJobTest {
-
+
@Test
- public void executeCollectOderJob(){
+ public void testExecuteCollectOderJob1() {
CollectVo collectVo = new CollectVo();
collectVo.setEmsName("zteEms");
collectVo.setType("ems-p");
collectVo.setIP("127.0.0.1");
collectVo.setCrontab("*/5 * * * * ?");
-
- String jobName = collectVo.getEmsName() + "_" + collectVo.getType() + collectVo.getIP();
- Job job = new CollectOderJob();
- String jobClass = job.getClass().getName();
- String time = collectVo.getCrontab();
- if (time != null && !"".equals(time)) {
- QuartzManager.addJob(jobName, jobClass, time, collectVo);
- try {
+ String jobName = collectVo.getEmsName() + "_" + collectVo.getType()
+ + collectVo.getIP();
+ Job job = new CollectOderJob();
+ String jobClass = job.getClass().getName();
+ String time = collectVo.getCrontab();
+ if (time != null && !"".equals(time)) {
+ QuartzManager.addJob(jobName, jobClass, time, collectVo);
+ try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } finally{
- QuartzManager.removeJob(jobName);
+ } finally {
+ QuartzManager.removeJob(jobName);
}
- } else {
- System.out.println("type =[" + collectVo.getType() + "]ip=[" + collectVo.getIP() + "] crontab is null");
- }
-
+ } else {
+ System.out.println("type =[" + collectVo.getType() + "]ip=["
+ + collectVo.getIP() + "] crontab is null");
+ }
+
}
-
+ @Test
+ public void testExecuteCollectOderJob2() {
+ CollectVo collectVo = new CollectVo();
+ collectVo.setEmsName("zteEms");
+ collectVo.setType("ems-p");
+ collectVo.setIP("127.0.0.1");
+ collectVo.setCrontab("*/5 * * * * ?");
+
+ try {
+ Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
+ SimpleTrigger trigger = new SimpleTrigger("trigger1",
+ "trigger_group");
+ trigger.setStartTime(new Date());
+ trigger.setRepeatInterval(1);
+ trigger.setRepeatCount(0);
+
+ String jobName = collectVo.getEmsName() + "_" + collectVo.getType()
+ + collectVo.getIP();
+ Job job = new CollectOderJob();
+ String jobClass = job.getClass().getName();
+ JobDetail jobDetail;
+ jobDetail = new JobDetail(jobName, "job_group",
+ Class.forName(jobClass));
+
+ scheduler.scheduleJob(jobDetail, trigger);
+ scheduler.start();
+
+ Thread.sleep(10000);
+ scheduler.shutdown(true);
+
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SchedulerException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java index efc023c..3e41725 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/taskscheduler/QuartzManagerTest.java @@ -15,8 +15,6 @@ */ package org.onap.vfc.nfvo.emsdriver.taskscheduler; -import static org.junit.Assert.*; - import org.junit.Before; import org.junit.Test; import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo; @@ -39,5 +37,11 @@ public class QuartzManagerTest { QuartzManager.removeJob("QuartzManager"); } + + @Test + public void modifyJobTime(){ + QuartzManager.addJob("QuartzManager", "org.onap.vfc.nfvo.emsdriver.taskscheduler", "*/5 * * * * ?", collectVo); + QuartzManager.modifyJobTime("QuartzManager", "*/10 * * * * ?", collectVo); + } } |