1 package org.openecomp.sdc.be.components.distribution.engine;
3 import java.util.Collection;
5 import java.util.concurrent.Callable;
6 import java.util.concurrent.ExecutionException;
7 import java.util.concurrent.ExecutorService;
8 import java.util.concurrent.Future;
9 import java.util.concurrent.TimeUnit;
10 import java.util.concurrent.TimeoutException;
12 import org.junit.Test;
13 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
15 public class NotificationExecutorServiceTest {
17 private NotificationExecutorService createTestSubject() {
18 return new NotificationExecutorService();
22 public void testCreateExcecutorService() throws Exception {
23 NotificationExecutorService testSubject;
24 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
25 ExecutorService result;
28 testSubject = createTestSubject();
29 result = testSubject.createExcecutorService(distributionNotificationTopic);
30 distributionNotificationTopic.setMinThreadPoolSize(1);
31 result = testSubject.createExcecutorService(distributionNotificationTopic);
32 distributionNotificationTopic.setMaxThreadPoolSize(1);
33 result = testSubject.createExcecutorService(distributionNotificationTopic);
37 public void testShutdownAndAwaitTermination() throws Exception {
38 NotificationExecutorService testSubject;
39 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
40 long maxTimeToWait = 435435;
43 testSubject = createTestSubject();
44 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
45 pool.awaitTermination = true;
46 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
47 pool.awaitTermination = true;
48 pool.isShutdownException = true;
49 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
52 private class NotificationExecutorServiceMock implements ExecutorService {
54 private boolean awaitTermination = false;
55 private boolean isShutdownException = false;
58 public void execute(Runnable command) {
59 // TODO Auto-generated method stub
64 public void shutdown() {
65 // TODO Auto-generated method stub
70 public List<Runnable> shutdownNow() {
71 // TODO Auto-generated method stub
72 if (isShutdownException) {
74 throw new InterruptedException();
75 } catch (InterruptedException e) {
76 // TODO Auto-generated catch block
84 public boolean isShutdown() {
85 // TODO Auto-generated method stub
90 public boolean isTerminated() {
91 // TODO Auto-generated method stub
96 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
97 // TODO Auto-generated method stub
98 return awaitTermination;
102 public <T> Future<T> submit(Callable<T> task) {
103 // TODO Auto-generated method stub
108 public <T> Future<T> submit(Runnable task, T result) {
109 // TODO Auto-generated method stub
114 public Future<?> submit(Runnable task) {
115 // TODO Auto-generated method stub
120 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
121 // TODO Auto-generated method stub
126 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
127 throws InterruptedException {
128 // TODO Auto-generated method stub
133 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
134 throws InterruptedException, ExecutionException {
135 // TODO Auto-generated method stub
140 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
141 throws InterruptedException, ExecutionException, TimeoutException {
142 // TODO Auto-generated method stub