bda1723fde01c59a169c8e89b1f0d472f1cb37cd
[sdc.git] /
1 package org.openecomp.sdc.be.components.distribution.engine;
2
3 import java.util.Collection;
4 import java.util.List;
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;
11
12 import org.junit.Test;
13 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
14
15 public class NotificationExecutorServiceTest {
16
17         private NotificationExecutorService createTestSubject() {
18                 return new NotificationExecutorService();
19         }
20
21         @Test
22         public void testCreateExcecutorService() throws Exception {
23                 NotificationExecutorService testSubject;
24                 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
25                 ExecutorService result;
26
27                 // default test
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);
34         }
35
36         @Test
37         public void testShutdownAndAwaitTermination() throws Exception {
38                 NotificationExecutorService testSubject;
39                 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
40                 long maxTimeToWait = 435435;
41
42                 // default test
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);
50         }
51         
52         private class NotificationExecutorServiceMock implements ExecutorService {
53                 
54                 private boolean awaitTermination = false;
55                 private boolean isShutdownException = false;
56                 
57                 @Override
58                 public void execute(Runnable command) {
59                         // TODO Auto-generated method stub
60                         
61                 }
62
63                 @Override
64                 public void shutdown() {
65                         // TODO Auto-generated method stub
66                         
67                 }
68
69                 @Override
70                 public List<Runnable> shutdownNow() {
71                         // TODO Auto-generated method stub
72                         if (isShutdownException) {
73                                 try {
74                                         throw new InterruptedException();
75                                 } catch (InterruptedException e) {
76                                         // TODO Auto-generated catch block
77                                         e.printStackTrace();
78                                 }
79                         }
80                         return null;
81                 }
82
83                 @Override
84                 public boolean isShutdown() {
85                         // TODO Auto-generated method stub
86                         return false;
87                 }
88
89                 @Override
90                 public boolean isTerminated() {
91                         // TODO Auto-generated method stub
92                         return false;
93                 }
94
95                 @Override
96                 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
97                         // TODO Auto-generated method stub
98                         return awaitTermination;
99                 }
100
101                 @Override
102                 public <T> Future<T> submit(Callable<T> task) {
103                         // TODO Auto-generated method stub
104                         return null;
105                 }
106
107                 @Override
108                 public <T> Future<T> submit(Runnable task, T result) {
109                         // TODO Auto-generated method stub
110                         return null;
111                 }
112
113                 @Override
114                 public Future<?> submit(Runnable task) {
115                         // TODO Auto-generated method stub
116                         return null;
117                 }
118
119                 @Override
120                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
121                         // TODO Auto-generated method stub
122                         return null;
123                 }
124
125                 @Override
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
129                         return null;
130                 }
131
132                 @Override
133                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
134                                 throws InterruptedException, ExecutionException {
135                         // TODO Auto-generated method stub
136                         return null;
137                 }
138
139                 @Override
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
143                         return null;
144                 }
145                 
146         }
147 }