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.*;
30 public class NotificationExecutorServiceTest {
32 private NotificationExecutorService createTestSubject() {
33 return new NotificationExecutorService();
37 public void testCreateExcecutorService() throws Exception {
38 NotificationExecutorService testSubject;
39 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
40 ExecutorService result;
43 testSubject = createTestSubject();
44 result = testSubject.createExcecutorService(distributionNotificationTopic);
45 distributionNotificationTopic.setMinThreadPoolSize(1);
46 result = testSubject.createExcecutorService(distributionNotificationTopic);
47 distributionNotificationTopic.setMaxThreadPoolSize(1);
48 result = testSubject.createExcecutorService(distributionNotificationTopic);
52 public void testShutdownAndAwaitTermination() throws Exception {
53 NotificationExecutorService testSubject;
54 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
55 long maxTimeToWait = 435435;
58 testSubject = createTestSubject();
59 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
60 pool.awaitTermination = true;
61 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
62 pool.awaitTermination = true;
63 pool.isShutdownException = true;
64 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
67 private class NotificationExecutorServiceMock implements ExecutorService {
69 private boolean awaitTermination = false;
70 private boolean isShutdownException = false;
73 public void execute(Runnable command) {
74 // TODO Auto-generated method stub
79 public void shutdown() {
80 // TODO Auto-generated method stub
85 public List<Runnable> shutdownNow() {
86 // TODO Auto-generated method stub
87 if (isShutdownException) {
89 throw new InterruptedException();
90 } catch (InterruptedException e) {
91 // TODO Auto-generated catch block
99 public boolean isShutdown() {
100 // TODO Auto-generated method stub
105 public boolean isTerminated() {
106 // TODO Auto-generated method stub
111 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
112 // TODO Auto-generated method stub
113 return awaitTermination;
117 public <T> Future<T> submit(Callable<T> task) {
118 // TODO Auto-generated method stub
123 public <T> Future<T> submit(Runnable task, T result) {
124 // TODO Auto-generated method stub
129 public Future<?> submit(Runnable task) {
130 // TODO Auto-generated method stub
135 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
136 // TODO Auto-generated method stub
141 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
142 throws InterruptedException {
143 // TODO Auto-generated method stub
148 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
149 throws InterruptedException, ExecutionException {
150 // TODO Auto-generated method stub
155 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
156 throws InterruptedException, ExecutionException, TimeoutException {
157 // TODO Auto-generated method stub