Merge "Improve code coverage for MdsalHelper"
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
index 4d920e6..072a6f4 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/CachedDataSource.java
@@ -123,7 +123,7 @@
connection = null;
}
- monitor.deregisterReguest(testObject);
+ monitor.deregisterRequest(testObject);
}
}
@@ -153,7 +153,7 @@
connection = null;
}
- monitor.deregisterReguest(testObject);
+ monitor.deregisterRequest(testObject);
}
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
index 014dab3..e7a94e6 100755
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceManager.java
@@ -884,7 +884,7 @@
CachedDataSource first = snapshot.getFirst();
CachedDataSource last = snapshot.getLast();
- int delta = first.getMonitor().getPorcessedConnectionsCount() - last.getMonitor().getPorcessedConnectionsCount();
+ int delta = first.getMonitor().getProcessedConnectionsCount() - last.getMonitor().getProcessedConnectionsCount();
if(delta < 0) {
flipper.set(false);
} else if(delta > 0) {
@@ -921,7 +921,7 @@
CachedDataSource first = snapshot.getFirst();
CachedDataSource last = snapshot.getLast();
- int delta = first.getMonitor().getPorcessedConnectionsCount() - last.getMonitor().getPorcessedConnectionsCount();
+ int delta = first.getMonitor().getProcessedConnectionsCount() - last.getMonitor().getProcessedConnectionsCount();
if(delta < 0) {
flipper.set(false);
} else if(delta > 0) {
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/DBConfigFactory.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/DBConfigFactory.java
index 3caa776..c350357 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/DBConfigFactory.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/factory/DBConfigFactory.java
@@ -24,7 +24,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
-
import org.onap.ccsdk.sli.core.dblib.config.BaseDBConfiguration;
import org.onap.ccsdk.sli.core.dblib.config.DbConfigPool;
import org.onap.ccsdk.sli.core.dblib.config.JDBCConfiguration;
@@ -39,61 +38,66 @@
*/
public class DBConfigFactory {
- public static DbConfigPool createConfig(Properties resource) {
- return getConfigparams(resource);
- }
+ public static DbConfigPool createConfig(Properties resource) {
+ return getConfigparams(resource);
+ }
- static DbConfigPool getConfigparams(Properties properties){
- DbConfigPool xmlConfig = new DbConfigPool(properties);
- ArrayList<Properties> propertySets = new ArrayList<Properties>();
+ static DbConfigPool getConfigparams(Properties properties) {
+ DbConfigPool xmlConfig = new DbConfigPool(properties);
+ ArrayList<Properties> propertySets = new ArrayList<Properties>();
- if("JDBC".equalsIgnoreCase(xmlConfig.getType())) {
- String hosts = properties.getProperty(BaseDBConfiguration.DATABASE_HOSTS);
- if(hosts == null || hosts.isEmpty()) {
- propertySets.add(properties);
- } else {
- String[] newhost = hosts.split(",");
- for(int i=0; i< newhost.length; i++) {
- Properties localset = new Properties();
- localset.putAll(properties);
- String url = localset.getProperty(BaseDBConfiguration.DATABASE_URL);
- if(url.contains("DBHOST"))
- url = url.replace("DBHOST", newhost[i]);
- if(url.contains("dbhost"))
- url = url.replace("dbhost", newhost[i]);
- localset.setProperty(BaseDBConfiguration.DATABASE_URL, url);
- localset.setProperty(BaseDBConfiguration.CONNECTION_NAME, newhost[i]);
- propertySets.add(localset);
- }
- }
- } else {
- propertySets.add(properties);
- }
- try {
- Iterator<Properties> it = propertySets.iterator();
- while(it.hasNext()) {
- BaseDBConfiguration config = parse(it.next());
- xmlConfig.addConfiguration(config);
- }
+ if ("JDBC".equalsIgnoreCase(xmlConfig.getType())) {
+ String hosts = properties.getProperty(BaseDBConfiguration.DATABASE_HOSTS);
+ if (hosts == null || hosts.isEmpty()) {
+ propertySets.add(properties);
+ } else {
+ setPropertyWhenHostsNonEmpty(hosts, properties, propertySets);
+ }
+ } else {
+ propertySets.add(properties);
+ }
+ try {
+ Iterator<Properties> it = propertySets.iterator();
+ while (it.hasNext()) {
+ BaseDBConfiguration config = parse(it.next());
+ xmlConfig.addConfiguration(config);
+ }
+ } catch (Exception e) {
+ LoggerFactory.getLogger(DBConfigFactory.class).warn("", e);
+ }
- } catch (Exception e) {
- LoggerFactory.getLogger(DBConfigFactory.class).warn("",e);
- }
+ return xmlConfig;
+ }
- return xmlConfig;
- }
+ private static void setPropertyWhenHostsNonEmpty(String hosts, Properties properties, ArrayList<Properties>
+ propertySets) {
+ String[] newhost = hosts.split(",");
+ for (String aNewhost : newhost) {
+ Properties localSet = new Properties();
+ localSet.putAll(properties);
+ String url = localSet.getProperty(BaseDBConfiguration.DATABASE_URL);
+ if (url.contains("DBHOST")) {
+ url = url.replace("DBHOST", aNewhost);
+ }
+ if (url.contains("dbhost")) {
+ url = url.replace("dbhost", aNewhost);
+ }
+ localSet.setProperty(BaseDBConfiguration.DATABASE_URL, url);
+ localSet.setProperty(BaseDBConfiguration.CONNECTION_NAME, aNewhost);
+ propertySets.add(localSet);
+ }
+ }
- public static BaseDBConfiguration parse(Properties props) throws Exception {
+ public static BaseDBConfiguration parse(Properties props) throws Exception {
- String type = props.getProperty(BaseDBConfiguration.DATABASE_TYPE);
+ String type = props.getProperty(BaseDBConfiguration.DATABASE_TYPE);
- BaseDBConfiguration config = null;
+ BaseDBConfiguration config = null;
- if("JDBC".equalsIgnoreCase(type)) {
- config = new JDBCConfiguration(props);
- }
+ if ("JDBC".equalsIgnoreCase(type)) {
+ config = new JDBCConfiguration(props);
+ }
- return config;
-
- }
+ return config;
+ }
}
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitor.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitor.java
index bcd4360..95172ad 100644
--- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitor.java
+++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitor.java
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Objects;
import java.util.Observable;
import java.util.Observer;
import java.util.SortedSet;
@@ -30,208 +31,190 @@
import java.util.TimerTask;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;
-
import org.onap.ccsdk.sli.core.dblib.DBResourceObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SQLExecutionMonitor extends Observable
-{
- private static Logger LOGGER = LoggerFactory.getLogger(SQLExecutionMonitor.class);
-
- final static long MILISECOND = 1000000L;
- final static long SECOND = 1000L*MILISECOND;
-
- private final Timer timer;
- // collection
- private final SortedSet<TestObject> innerSet;
- private SQLExecutionMonitorObserver parent = null;
- private final AtomicLong completionCounter;
- private boolean activeState = false;
- private final long interval;
- private final long initialDelay;
- private final long EXPECTED_TIME_TO_COMPLETE;
- private final long UNPROCESSED_FAILOVER_THRESHOLD;
+public class SQLExecutionMonitor extends Observable {
- private final class MonitoringTask extends TimerTask
- {
-
- public void run()
- {
- try {
- TestObject testObj = new TestObject();
- testObj.setStartTime(testObj.getStartTime() - EXPECTED_TIME_TO_COMPLETE);
+ private static final Logger LOGGER = LoggerFactory.getLogger(SQLExecutionMonitor.class);
- // take a snapshot of the current task list
- TestObject[] array = innerSet.toArray(new TestObject[0]);
- SortedSet<TestObject> copyCurrent = new TreeSet<TestObject>(Arrays.asList(array));
- // get the list of the tasks that are older than the specified
- // interval.
- SortedSet<TestObject> unprocessed = copyCurrent.headSet(testObj);
+ static final long MILISECOND = 1000000L;
+ static final long SECOND = 1000L * MILISECOND;
- long succesfulCount = completionCounter.get();
- int unprocessedCount = unprocessed.size();
-
- if (!unprocessed.isEmpty() && unprocessedCount > UNPROCESSED_FAILOVER_THRESHOLD && succesfulCount == 0)
- {
- // switch the Connection Pool to passive
- setChanged();
- notifyObservers("Open JDBC requests=" + unprocessedCount+" in "+SQLExecutionMonitor.this.parent.getDbConnectionName());
- }
- } catch (Exception exc) {
- LOGGER.error("", exc);
- } finally {
- completionCounter.set(0L);
- }
- }
- }
+ private final Timer timer;
+ // collection
+ private final SortedSet<TestObject> innerSet;
+ private SQLExecutionMonitorObserver parent = null;
+ private final AtomicLong completionCounter;
+ private boolean activeState = false;
+ private final long interval;
+ private final long initialDelay;
+ private final long EXPECTED_TIME_TO_COMPLETE;
+ private final long UNPROCESSED_FAILOVER_THRESHOLD;
- public static class TestObject implements Comparable<TestObject>, Serializable
- {
+ private final class MonitoringTask extends TimerTask {
- private static final long serialVersionUID = 1L;
- private long starttime;
- private long randId;
+ public void run() {
+ try {
+ TestObject testObj = new TestObject();
+ testObj.setStartTime(testObj.getStartTime() - EXPECTED_TIME_TO_COMPLETE);
- public TestObject()
- {
- starttime = System.nanoTime();
- }
+ // take a snapshot of the current task list
+ TestObject[] array = innerSet.toArray(new TestObject[0]);
+ SortedSet<TestObject> copyCurrent = new TreeSet<>(Arrays.asList(array));
+ // get the list of the tasks that are older than the specified
+ // interval.
+ SortedSet<TestObject> unprocessed = copyCurrent.headSet(testObj);
- public long getStartTime()
- {
- return starttime;
- }
+ long successfulCount = completionCounter.get();
+ int unprocessedCount = unprocessed.size();
- public void setStartTime(long newTime)
- {
- starttime = newTime;
- }
+ if (!unprocessed.isEmpty() && unprocessedCount > UNPROCESSED_FAILOVER_THRESHOLD
+ && successfulCount == 0) {
+ // switch the Connection Pool to passive
+ setChanged();
+ notifyObservers("Open JDBC requests=" + unprocessedCount + " in " + SQLExecutionMonitor.this.parent
+ .getDbConnectionName());
+ }
+ } catch (Exception exc) {
+ LOGGER.error("", exc);
+ } finally {
+ completionCounter.set(0L);
+ }
+ }
+ }
- public int compareTo(TestObject o)
- {
- if( this == o)
- return 0;
- if(this.starttime > o.getStartTime())
- return 1;
- if(this.starttime < o.getStartTime())
- return -1;
+ public static class TestObject implements Comparable<TestObject>, Serializable {
- if(this.hashCode() > o.hashCode())
- return 1;
- if(this.hashCode() < o.hashCode())
- return -1;
+ private static final long serialVersionUID = 1L;
+ private long startTime;
+ private long randId;
- return 0;
- }
+ public TestObject() {
+ startTime = System.nanoTime();
+ }
- public String toString()
- {
- return Long.toString(starttime)+"#"+ this.hashCode();
- }
-
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
+ public long getStartTime() {
+ return startTime;
+ }
- return (obj instanceof TestObject
- && starttime == ((TestObject) obj).getStartTime()
- && hashCode() == ((TestObject) obj).hashCode());
- }
- }
+ public void setStartTime(long newTime) {
+ startTime = newTime;
+ }
- public SQLExecutionMonitor(SQLExecutionMonitorObserver parent)
- {
- this.parent = parent;
- completionCounter = new AtomicLong(0L);
- interval = parent.getInterval();
- initialDelay = parent.getInitialDelay();
- this.UNPROCESSED_FAILOVER_THRESHOLD = parent.getUnprocessedFailoverThreshold();
- this.EXPECTED_TIME_TO_COMPLETE = parent.getExpectedCompletionTime()*MILISECOND;
-
- innerSet = Collections.synchronizedSortedSet(new TreeSet<TestObject>());
- timer = new Timer();
- }
-
- public void cleanup()
- {
- timer.cancel();
- }
-
- // registerRequest
- public TestObject registerRequest()
- {
- if(activeState)
- {
- TestObject test = new TestObject();
- if(innerSet.add(test))
- return test;
- }
- return null;
- }
+ public int compareTo(TestObject o) {
+ if (this == o) {
+ return 0;
+ }
+ if (this.startTime > o.getStartTime()) {
+ return 1;
+ }
+ if (this.startTime < o.getStartTime()) {
+ return -1;
+ }
- // deregisterSuccessfulReguest
- public boolean deregisterReguest(TestObject test)
- {
- if(test == null)
- return false;
- // remove from the collection
- if(innerSet.remove(test) && activeState)
- {
- completionCounter.incrementAndGet();
- return true;
- }
- return false;
- }
+ if (this.hashCode() > o.hashCode()) {
+ return 1;
+ }
+ if (this.hashCode() < o.hashCode()) {
+ return -1;
+ }
- public void terminate() {
- timer.cancel();
- }
+ return 0;
+ }
- /**
- * @return the parent
- */
- public final Object getParent() {
- return parent;
- }
-
- public void addObserver(Observer observer)
- {
- if(observer instanceof DBResourceObserver)
- {
- DBResourceObserver dbObserver = (DBResourceObserver)observer;
- if(dbObserver.isMonitorDbResponse())
- {
- if(countObservers() == 0)
- {
- TimerTask remindTask = new MonitoringTask();
- timer.schedule(remindTask, initialDelay, interval);
- activeState = true;
- }
- }
- }
- super.addObserver(observer);
- }
-
- public void deleteObserver(Observer observer)
- {
- super.deleteObserver(observer);
- if(observer instanceof DBResourceObserver)
- {
- DBResourceObserver dbObserver = (DBResourceObserver)observer;
- if(dbObserver.isMonitorDbResponse())
- {
- if(countObservers() == 0)
- {
- timer.cancel();
- activeState = false;
- }
- }
- }
- }
-
- public final int getPorcessedConnectionsCount() {
- return innerSet.size();
- }
+ public String toString() {
+ return Long.toString(startTime) + "#" + this.hashCode();
+ }
+
+ public int hashCode() {
+ return Objects.hash(startTime, randId);
+ }
+
+ public boolean equals(Object obj) {
+ return this == obj || (obj instanceof TestObject && startTime == ((TestObject) obj).getStartTime()
+ && hashCode() == obj.hashCode());
+ }
+ }
+
+ public SQLExecutionMonitor(SQLExecutionMonitorObserver parent) {
+ this.parent = parent;
+ completionCounter = new AtomicLong(0L);
+ interval = parent.getInterval();
+ initialDelay = parent.getInitialDelay();
+ this.UNPROCESSED_FAILOVER_THRESHOLD = parent.getUnprocessedFailoverThreshold();
+ this.EXPECTED_TIME_TO_COMPLETE = parent.getExpectedCompletionTime() * MILISECOND;
+
+ innerSet = Collections.synchronizedSortedSet(new TreeSet<TestObject>());
+ timer = new Timer();
+ }
+
+ public void cleanup() {
+ timer.cancel();
+ }
+
+ // registerRequest
+ public TestObject registerRequest() {
+ if (activeState) {
+ TestObject test = new TestObject();
+ if (innerSet.add(test)) {
+ return test;
+ }
+ }
+ return null;
+ }
+
+ // deregisterSuccessfulRequest
+ public boolean deregisterRequest(TestObject test) {
+ if (test == null) {
+ return false;
+ }
+ // remove from the collection
+ if (innerSet.remove(test) && activeState) {
+ completionCounter.incrementAndGet();
+ return true;
+ }
+ return false;
+ }
+
+ public void terminate() {
+ timer.cancel();
+ }
+
+ /**
+ * @return the parent
+ */
+ public final Object getParent() {
+ return parent;
+ }
+
+ @Override
+ public void addObserver(Observer observer) {
+ if (observer instanceof DBResourceObserver) {
+ DBResourceObserver dbObserver = (DBResourceObserver) observer;
+ if (dbObserver.isMonitorDbResponse() && countObservers() == 0) {
+ TimerTask remindTask = new MonitoringTask();
+ timer.schedule(remindTask, initialDelay, interval);
+ activeState = true;
+ }
+ }
+ super.addObserver(observer);
+ }
+
+ @Override
+ public void deleteObserver(Observer observer) {
+ super.deleteObserver(observer);
+ if (observer instanceof DBResourceObserver) {
+ DBResourceObserver dbObserver = (DBResourceObserver) observer;
+ if (dbObserver.isMonitorDbResponse() && countObservers() == 0) {
+ timer.cancel();
+ activeState = false;
+ }
+ }
+ }
+
+ public final int getProcessedConnectionsCount() {
+ return innerSet.size();
+ }
}
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java
index 160107f..45f6835 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicNode.java
@@ -87,28 +87,28 @@
public String getNodeName()
{
- return(nodeName);
+ return nodeName;
}
public String getNodeType()
{
- return(nodeType);
+ return nodeType;
}
public SvcLogicGraph getGraph()
{
- return(graph);
+ return graph;
}
public int getNumOutcomes()
{
if (outcomes == null)
{
- return(0);
+ return 0;
}
else
{
- return(outcomes.size());
+ return outcomes.size();
}
}
@@ -116,11 +116,11 @@
{
if (attributes.containsKey(name))
{
- return(attributes.get(name));
+ return attributes.get(name);
}
else
{
- return(null);
+ return null;
}
}
@@ -151,7 +151,7 @@
try
{
SvcLogicExpression parmValue;
- if ((value == null) || (value.length() == 0))
+ if (value == null || value.length() == 0)
{
parmValue = new SvcLogicAtom("STRING", "");
}
@@ -187,11 +187,11 @@
{
if (parameters.containsKey(name))
{
- return(parameters.get(name));
+ return parameters.get(name);
}
else
{
- return(null);
+ return null;
}
}
@@ -245,7 +245,7 @@
return null;
}
- return(outcomes.entrySet());
+ return outcomes.entrySet();
}
@@ -256,7 +256,7 @@
return null;
}
- return(parameters.entrySet());
+ return parameters.entrySet();
}
@@ -346,8 +346,8 @@
pstr.print("'`");
}
- if (((parameters == null) || (parameters.isEmpty())) &&
- ((outcomes == null) || outcomes.isEmpty()))
+ if ((parameters == null || parameters.isEmpty()) &&
+ (outcomes == null || outcomes.isEmpty()))
{
pstr.print("/>\n");
pstr.flush();
@@ -424,12 +424,12 @@
}
if (outcomes == null)
{
- return(null);
+ return null;
}
if (outcomes.containsKey(value))
{
- return(outcomes.get(value));
+ return outcomes.get(value);
}
else
{
@@ -443,11 +443,11 @@
if (outcomes.containsKey("Other"))
{
- return(outcomes.get("Other"));
+ return outcomes.get("Other");
}
else
{
- return(null);
+ return null;
}
}
}