2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.distribution.engine;
23 import org.junit.Test;
24 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.concurrent.Callable;
29 import java.util.concurrent.ExecutionException;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.Future;
32 import java.util.concurrent.TimeUnit;
33 import java.util.concurrent.TimeoutException;
35 public class NotificationExecutorServiceTest {
37 private NotificationExecutorService createTestSubject() {
38 return new NotificationExecutorService();
42 public void testCreateExcecutorService() throws Exception {
43 NotificationExecutorService testSubject;
44 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
45 ExecutorService result;
48 testSubject = createTestSubject();
49 result = testSubject.createExcecutorService(distributionNotificationTopic);
50 distributionNotificationTopic.setMinThreadPoolSize(1);
51 result = testSubject.createExcecutorService(distributionNotificationTopic);
52 distributionNotificationTopic.setMaxThreadPoolSize(1);
53 result = testSubject.createExcecutorService(distributionNotificationTopic);
57 public void testShutdownAndAwaitTermination() throws Exception {
58 NotificationExecutorService testSubject;
59 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
60 long maxTimeToWait = 435435;
63 testSubject = createTestSubject();
64 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
65 pool.awaitTermination = true;
66 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
67 pool.awaitTermination = true;
68 pool.isShutdownException = true;
69 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
72 private class NotificationExecutorServiceMock implements ExecutorService {
74 private boolean awaitTermination = false;
75 private boolean isShutdownException = false;
78 public void execute(Runnable command) {
79 // TODO Auto-generated method stub
84 public void shutdown() {
85 // TODO Auto-generated method stub
90 public List<Runnable> shutdownNow() {
91 // TODO Auto-generated method stub
92 if (isShutdownException) {
94 throw new InterruptedException();
95 } catch (InterruptedException e) {
96 // TODO Auto-generated catch block
104 public boolean isShutdown() {
105 // TODO Auto-generated method stub
110 public boolean isTerminated() {
111 // TODO Auto-generated method stub
116 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
117 // TODO Auto-generated method stub
118 return awaitTermination;
122 public <T> Future<T> submit(Callable<T> task) {
123 // TODO Auto-generated method stub
128 public <T> Future<T> submit(Runnable task, T result) {
129 // TODO Auto-generated method stub
134 public Future<?> submit(Runnable task) {
135 // TODO Auto-generated method stub
140 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
141 // TODO Auto-generated method stub
146 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
147 throws InterruptedException {
148 // TODO Auto-generated method stub
153 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
154 throws InterruptedException, ExecutionException {
155 // TODO Auto-generated method stub
160 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
161 throws InterruptedException, ExecutionException, TimeoutException {
162 // TODO Auto-generated method stub