From da4ba6e2c81f3dd7157e1cc06a92e91c5a38aa95 Mon Sep 17 00:00:00 2001 From: Guobiao Mo Date: Tue, 16 Apr 2019 23:54:45 -0700 Subject: Unit test to improve sonar coverage Issue-ID: DCAEGEN2-1309 Change-Id: Ia3651bb105d92013d6d2a9d60fffe3b6066adf64 Signed-off-by: Guobiao Mo --- .../CollectibleDocumentFieldNameValidator.java | 2 +- .../java/org/onap/datalake/feeder/domain/Topic.java | 2 +- .../datalake/feeder/service/CouchbaseService.java | 2 +- .../org/onap/datalake/feeder/service/DbService.java | 4 ---- .../feeder/service/ElasticsearchService.java | 8 +++++--- .../onap/datalake/feeder/service/PullService.java | 20 ++++++++++---------- .../onap/datalake/feeder/service/TopicService.java | 11 ----------- .../java/org/onap/datalake/feeder/util/Util.java | 7 ------- 8 files changed, 18 insertions(+), 38 deletions(-) (limited to 'components/datalake-handler/feeder/src/main') diff --git a/components/datalake-handler/feeder/src/main/java/com/mongodb/internal/validator/CollectibleDocumentFieldNameValidator.java b/components/datalake-handler/feeder/src/main/java/com/mongodb/internal/validator/CollectibleDocumentFieldNameValidator.java index 2bc6faad..e7a8e1b9 100644 --- a/components/datalake-handler/feeder/src/main/java/com/mongodb/internal/validator/CollectibleDocumentFieldNameValidator.java +++ b/components/datalake-handler/feeder/src/main/java/com/mongodb/internal/validator/CollectibleDocumentFieldNameValidator.java @@ -8,7 +8,7 @@ package com.mongodb.internal.validator; * ================================================================================ * Copyright 2018 China Mobile *================================================================================= -* Licensed under the Apache License, Version 2.0 (the "License"); +* 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 * diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java index 20ebf94a..65478702 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java @@ -100,7 +100,7 @@ public class Topic { @Column(name = "correlate_cleared_message") private Boolean correlateClearedMessage; - //the value in the JSON with this path will be used as DB id + //paths to the values in the JSON that are used to composite DB id, comma separated, example: "/event-header/id,/event-header/entity-type,/entity/product-name" @Column(name = "message_id_path") private String messageIdPath; diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/CouchbaseService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/CouchbaseService.java index a63a927c..01c908ef 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/CouchbaseService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/CouchbaseService.java @@ -70,7 +70,7 @@ public class CouchbaseService { cluster.authenticate(couchbase.getLogin(), couchbase.getPass()); bucket = cluster.openBucket(couchbase.getDatabase()); - log.info("Connect to Couchbase " + couchbase.getHost()); + log.info("Connect to Couchbase {}", couchbase.getHost()); // Create a N1QL Primary Index (but ignore if it exists) bucket.bucketManager().createN1qlPrimaryIndex(true, false); diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DbService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DbService.java index f0d943d3..e859270f 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DbService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DbService.java @@ -24,8 +24,6 @@ import java.util.Optional; import org.onap.datalake.feeder.domain.Db; import org.onap.datalake.feeder.repository.DbRepository; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,8 +36,6 @@ import org.springframework.stereotype.Service; @Service public class DbService { - private final Logger log = LoggerFactory.getLogger(this.getClass()); - @Autowired private DbRepository dbRepository; diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/ElasticsearchService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/ElasticsearchService.java index fea07187..2c16b2b8 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/ElasticsearchService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/ElasticsearchService.java @@ -27,7 +27,6 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.apache.http.HttpHost; -import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.client.indices.CreateIndexResponse; @@ -69,6 +68,9 @@ public class ElasticsearchService { private RestHighLevelClient client; ActionListener listener; + +//ES Encrypted communication https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_encrypted_communication.html#_encrypted_communication +//Basic authentication https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html @PostConstruct private void init() { Db elasticsearch = dbService.getElasticsearch(); @@ -77,7 +79,7 @@ public class ElasticsearchService { // Initialize the Connection client = new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearchHost, 9200, "http"), new HttpHost(elasticsearchHost, 9201, "http"))); - log.info("Connect to Elasticsearch Host " + elasticsearchHost); + log.info("Connect to Elasticsearch Host {}", elasticsearchHost); listener = new ActionListener() { @Override @@ -106,7 +108,7 @@ public class ElasticsearchService { if(!exists){ CreateIndexRequest createIndexRequest = new CreateIndexRequest(topicLower); CreateIndexResponse createIndexResponse = client.indices().create(createIndexRequest, RequestOptions.DEFAULT); - log.info(createIndexResponse.index()+" : created "+createIndexResponse.isAcknowledged()); + log.info("{} : created {}", createIndexResponse.index(), createIndexResponse.isAcknowledged()); } } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PullService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PullService.java index 4433c8c4..48d167b5 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PullService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PullService.java @@ -49,10 +49,10 @@ public class PullService { private boolean isRunning = false; private ExecutorService executorService; private List consumers; - + @Autowired private ApplicationContext context; - + @Autowired private ApplicationConfiguration config; @@ -62,13 +62,13 @@ public class PullService { public boolean isRunning() { return isRunning; } - + /** * start pulling. * * @throws IOException */ - public synchronized void start() throws IOException { + public synchronized void start() { if (isRunning) { return; } @@ -80,15 +80,15 @@ public class PullService { executorService = Executors.newFixedThreadPool(numConsumers); consumers = new ArrayList<>(numConsumers); - for (int i = 0; i < numConsumers; i++) { + for (int i = 0; i < numConsumers; i++) { PullThread puller = context.getBean(PullThread.class, i); consumers.add(puller); executorService.submit(puller); } isRunning = true; - - Runtime.getRuntime().addShutdownHook(new Thread(()->shutdown())) ; + + Runtime.getRuntime().addShutdownHook(new Thread(this::shutdown)); } /** @@ -103,16 +103,16 @@ public class PullService { for (PullThread puller : consumers) { puller.shutdown(); } - + executorService.shutdown(); - + try { executorService.awaitTermination(10L, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.error("executor.awaitTermination", e); Thread.currentThread().interrupt(); } - + isRunning = false; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java index cd5113cc..7e0c7780 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java @@ -23,9 +23,6 @@ package org.onap.datalake.feeder.service; import java.io.IOException; import java.util.Optional; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - import org.onap.datalake.feeder.domain.Topic; import org.onap.datalake.feeder.repository.TopicRepository; import org.slf4j.Logger; @@ -50,14 +47,6 @@ public class TopicService { @Autowired private ElasticsearchService elasticsearchService; - @PostConstruct - private void init() { - } - - @PreDestroy - public void cleanUp() { - } - public Topic getEffectiveTopic(String topicStr) { try { return getEffectiveTopic(topicStr, false); diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/Util.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/Util.java index 89e81af1..aada44bc 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/Util.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/Util.java @@ -55,11 +55,4 @@ public class Util { return replaceDotInKey(newJson);// there maybe more to replace } } - - public static void main(String[] args) { - String a = "\"u-y.t.y-t\":\"u.gfh\",\\\"jg.h\\\":\"j_9889\""; - String b = replaceDotInKey(a); - System.out.println(a); - System.out.println(b); - } } -- cgit 1.2.3-korg