aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/onap/appc/executionqueue/helper/Util.java10
-rw-r--r--appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/helper/UtilTest.java106
2 files changed, 113 insertions, 3 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/onap/appc/executionqueue/helper/Util.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/onap/appc/executionqueue/helper/Util.java
index 878794bcf..b89001403 100644
--- a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/onap/appc/executionqueue/helper/Util.java
+++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/main/java/org/onap/appc/executionqueue/helper/Util.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +27,8 @@ package org.onap.appc.executionqueue.helper;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
-
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@@ -36,6 +39,7 @@ public class Util {
private int default_threadpool_size = 10;
private String queue_size_key = "appc.dispatcher.executionqueue.backlog.size";
private String threadpool_size_key = "appc.dispatcher.executionqueue.threadpool.size";
+ private EELFLogger logger = EELFManager.getInstance().getLogger(Util.class);
private Configuration configuration;
@@ -54,7 +58,7 @@ public class Util {
try {
size = Integer.parseInt(sizeStr);
} catch (NumberFormatException e) {
-
+ logger.error("Error parsing dispatcher execution queue backlog size", e);
}
return size;
@@ -67,7 +71,7 @@ public class Util {
try {
size = Integer.parseInt(sizeStr);
} catch (NumberFormatException e) {
-
+ logger.error("Error parsing dispatcher execution queue threadpool size", e);
}
return size;
diff --git a/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/helper/UtilTest.java b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/helper/UtilTest.java
new file mode 100644
index 000000000..fdd5e3420
--- /dev/null
+++ b/appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/src/test/java/org/onap/appc/executionqueue/helper/UtilTest.java
@@ -0,0 +1,106 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.executionqueue.helper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.util.concurrent.ThreadFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+import com.att.eelf.configuration.EELFLogger;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(ConfigurationFactory.class)
+public class UtilTest {
+
+ private Configuration configuration;
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(ConfigurationFactory.class);
+ configuration = Mockito.mock(Configuration.class);
+ PowerMockito.when(ConfigurationFactory.getConfiguration()).thenReturn(configuration);
+ }
+
+ @Test
+ public void testInit() {
+ Util util = new Util();
+ util.init();
+ assertEquals(configuration, Whitebox.getInternalState(util, "configuration"));
+ }
+
+ @Test
+ public void testGetExecutionQueueSize() {
+ Mockito.when(configuration.getProperty("appc.dispatcher.executionqueue.backlog.size", String.valueOf(10))).thenReturn("1");
+ Util util = new Util();
+ Whitebox.setInternalState(util, "configuration", configuration);
+ assertEquals(1, util.getExecutionQueueSize());
+ }
+
+ @Test
+ public void testGetExecutionQueueSizeExceptionFlow() {
+ Mockito.when(configuration.getProperty("appc.dispatcher.executionqueue.backlog.size", String.valueOf(10))).thenReturn("Not A Number");
+ Util util = new Util();
+ Whitebox.setInternalState(util, "configuration", configuration);
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ Whitebox.setInternalState(util, "logger", mockLogger);
+ util.getExecutionQueueSize();
+ Mockito.verify(mockLogger).error(Mockito.contains("Error parsing dispatcher execution queue backlog size"),
+ Mockito.any(NumberFormatException.class));
+ }
+
+ @Test
+ public void testGetThreadPoolSize() {
+ Mockito.when(configuration.getProperty("appc.dispatcher.executionqueue.threadpool.size", String.valueOf(10))).thenReturn("1");
+ Util util = new Util();
+ Whitebox.setInternalState(util, "configuration", configuration);
+ assertEquals(1, util.getThreadPoolSize());
+ }
+
+ @Test
+ public void testGetThreadPoolSizeExceptionFlow() {
+ Mockito.when(configuration.getProperty("appc.dispatcher.executionqueue.threadpool.size", String.valueOf(10))).thenReturn("Not A Number");
+ Util util = new Util();
+ Whitebox.setInternalState(util, "configuration", configuration);
+ EELFLogger mockLogger = Mockito.mock(EELFLogger.class);
+ Whitebox.setInternalState(util, "logger", mockLogger);
+ util.getThreadPoolSize();
+ Mockito.verify(mockLogger).error(Mockito.contains("Error parsing dispatcher execution queue threadpool size"),
+ Mockito.any(NumberFormatException.class));
+ }
+
+ @Test
+ public void testGetThreadFactory() {
+ Util util = new Util();
+ Whitebox.setInternalState(util, "configuration", configuration);
+ assertTrue(util.getThreadFactory(true, "prefix") instanceof ThreadFactory);
+ assertTrue(util.getThreadFactory(true, "prefix").newThread(new Thread()) instanceof Thread);
+ }
+}