diff options
author | Guobiao Mo <guobiaomo@chinamobile.com> | 2019-05-30 22:09:01 -0700 |
---|---|---|
committer | Guobiao Mo <guobiaomo@chinamobile.com> | 2019-05-30 22:09:01 -0700 |
commit | b2952abd55264de281a85e0ed1b6bd53211b1c91 (patch) | |
tree | c20a16cb36f1c39b91e8dd1f316a775b78d9eef7 /components/datalake-handler/feeder/src/main/java/org/onap | |
parent | 7e6ede10cc2dffcc56b1df3c4484b28881c63212 (diff) |
Unit tests to improve sonar coverage
Issue-ID: DCAEGEN2-1468
Change-Id: Ie322142a2298ca55d32d64861e71ebc64cd8c09e
Signed-off-by: Guobiao Mo <guobiaomo@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder/src/main/java/org/onap')
4 files changed, 11 insertions, 9 deletions
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/FeederController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/FeederController.java index 4fc9b7b6..6a44c4f2 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/FeederController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/FeederController.java @@ -86,7 +86,7 @@ public class FeederController { @ApiOperation(value="Retrieve feeder status.") public String status() { String status = "Feeder is running: "+pullService.isRunning(); - log.info("senting feeder status ...");//TODO we can send what topics are monitored, how many messages are sent, etc. + log.info("sending feeder status ...");//TODO we can send what topics are monitored, how many messages are sent, etc. return "{\"version\": \""+config.getDatalakeVersion()+"\", \"running\": "+pullService.isRunning()+"}"; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DmaapService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DmaapService.java index 2274ce99..3be5be6e 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DmaapService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DmaapService.java @@ -58,11 +58,13 @@ public class DmaapService { @Autowired private TopicService topicService; - ZooKeeper zk; + private ZooKeeper zk; @PreDestroy public void cleanUp() throws InterruptedException { - zk.close(); + if (zk != null) { + zk.close(); + } } @PostConstruct @@ -71,6 +73,7 @@ public class DmaapService { } //get all topic names from Zookeeper + //This method returns empty list if nothing found. public List<String> getTopics() { try { if (zk == null) { @@ -84,7 +87,7 @@ public class DmaapService { return topics; } catch (Exception e) { zk = null; - log.error("Can not get topic list from Zookeeper, for testing, going to use hard coded topic list.", e); + log.error("Can not get topic list from Zookeeper, return empty list.", e); return Collections.emptyList(); } } @@ -119,9 +122,6 @@ public class DmaapService { public List<TopicConfig> getActiveTopicConfigs() throws IOException { log.debug("entering getActiveTopicConfigs()..."); List<String> allTopics = getTopics(); - if (allTopics == null) { - return Collections.emptyList(); - } List<TopicConfig> ret = new ArrayList<>(allTopics.size()); for (String topicStr : allTopics) { diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/StoreService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/StoreService.java index 126e23b2..03faeb81 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/StoreService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/StoreService.java @@ -91,8 +91,9 @@ public class StoreService { for (Pair<Long, String> pair : messages) { try { docs.add(messageToJson(topicConfig, pair)); - } catch (IOException e) { - log.error(pair.getRight(), e); + } catch (Exception e) { + //may see org.json.JSONException. + log.error("Error when converting this message to JSON: " + pair.getRight(), e); } } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicConfigPollingService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicConfigPollingService.java index 80da55fd..58b27834 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicConfigPollingService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicConfigPollingService.java @@ -102,6 +102,7 @@ public class TopicConfigPollingService implements Runnable { Thread.sleep(config.getDmaapCheckNewTopicInterval()); } catch (InterruptedException e) { log.error("Thread.sleep(config.getDmaapCheckNewTopicInterval())", e); + Thread.currentThread().interrupt(); } try { |