aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/NotificationExecutorServiceTest.java
blob: 35d3765091bc3271bc4e50f44f0eaa92bbe1baae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package org.openecomp.sdc.be.components.distribution.engine;

import org.junit.Test;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.*;

public class NotificationExecutorServiceTest {

	private NotificationExecutorService createTestSubject() {
		return new NotificationExecutorService();
	}

	@Test
	public void testCreateExcecutorService() throws Exception {
		NotificationExecutorService testSubject;
		DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
		ExecutorService result;

		// default test
		testSubject = createTestSubject();
		result = testSubject.createExcecutorService(distributionNotificationTopic);
		distributionNotificationTopic.setMinThreadPoolSize(1);
		result = testSubject.createExcecutorService(distributionNotificationTopic);
		distributionNotificationTopic.setMaxThreadPoolSize(1);
		result = testSubject.createExcecutorService(distributionNotificationTopic);
	}

	@Test
	public void testShutdownAndAwaitTermination() throws Exception {
		NotificationExecutorService testSubject;
		NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
		long maxTimeToWait = 435435;

		// default test
		testSubject = createTestSubject();
		testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
		pool.awaitTermination = true;
		testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
		pool.awaitTermination = true;
		pool.isShutdownException = true;
		testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
	}
	
	private class NotificationExecutorServiceMock implements ExecutorService {
		
		private boolean awaitTermination = false;
		private boolean isShutdownException = false;
		
		@Override
		public void execute(Runnable command) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void shutdown() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public List<Runnable> shutdownNow() {
			// TODO Auto-generated method stub
			if (isShutdownException) {
				try {
					throw new InterruptedException();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return null;
		}

		@Override
		public boolean isShutdown() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean isTerminated() {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
			// TODO Auto-generated method stub
			return awaitTermination;
		}

		@Override
		public <T> Future<T> submit(Callable<T> task) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> Future<T> submit(Runnable task, T result) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Future<?> submit(Runnable task) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
				throws InterruptedException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
				throws InterruptedException, ExecutionException {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
				throws InterruptedException, ExecutionException, TimeoutException {
			// TODO Auto-generated method stub
			return null;
		}
		
	}
}