1 package org.openecomp.sdc.be.components.distribution.engine;
4 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
6 import java.util.Collection;
8 import java.util.concurrent.*;
10 public class NotificationExecutorServiceTest {
12 private NotificationExecutorService createTestSubject() {
13 return new NotificationExecutorService();
17 public void testCreateExcecutorService() throws Exception {
18 NotificationExecutorService testSubject;
19 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
20 ExecutorService result;
23 testSubject = createTestSubject();
24 result = testSubject.createExcecutorService(distributionNotificationTopic);
25 distributionNotificationTopic.setMinThreadPoolSize(1);
26 result = testSubject.createExcecutorService(distributionNotificationTopic);
27 distributionNotificationTopic.setMaxThreadPoolSize(1);
28 result = testSubject.createExcecutorService(distributionNotificationTopic);
32 public void testShutdownAndAwaitTermination() throws Exception {
33 NotificationExecutorService testSubject;
34 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
35 long maxTimeToWait = 435435;
38 testSubject = createTestSubject();
39 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
40 pool.awaitTermination = true;
41 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
42 pool.awaitTermination = true;
43 pool.isShutdownException = true;
44 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
47 private class NotificationExecutorServiceMock implements ExecutorService {
49 private boolean awaitTermination = false;
50 private boolean isShutdownException = false;
53 public void execute(Runnable command) {
54 // TODO Auto-generated method stub
59 public void shutdown() {
60 // TODO Auto-generated method stub
65 public List<Runnable> shutdownNow() {
66 // TODO Auto-generated method stub
67 if (isShutdownException) {
69 throw new InterruptedException();
70 } catch (InterruptedException e) {
71 // TODO Auto-generated catch block
79 public boolean isShutdown() {
80 // TODO Auto-generated method stub
85 public boolean isTerminated() {
86 // TODO Auto-generated method stub
91 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
92 // TODO Auto-generated method stub
93 return awaitTermination;
97 public <T> Future<T> submit(Callable<T> task) {
98 // TODO Auto-generated method stub
103 public <T> Future<T> submit(Runnable task, T result) {
104 // TODO Auto-generated method stub
109 public Future<?> submit(Runnable task) {
110 // TODO Auto-generated method stub
115 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
116 // TODO Auto-generated method stub
121 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
122 throws InterruptedException {
123 // TODO Auto-generated method stub
128 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
129 throws InterruptedException, ExecutionException {
130 // TODO Auto-generated method stub
135 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
136 throws InterruptedException, ExecutionException, TimeoutException {
137 // TODO Auto-generated method stub