2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.onap.dmaap.mr.cambria.backends.kafka;
23 import static org.junit.Assert.assertTrue;
25 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
26 import java.util.Collection;
27 import java.util.concurrent.ConcurrentHashMap;
28 import org.apache.curator.framework.CuratorFramework;
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.dmaap.dmf.mr.backends.Consumer;
37 import org.onap.dmaap.dmf.mr.backends.MetricsSet;
38 import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer;
39 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache;
40 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache.KafkaConsumerCacheException;
43 @RunWith(MockitoJUnitRunner.class)
44 public class KafkaConsumerCacheTest {
47 private ConcurrentHashMap<String, Kafka011Consumer> fConsumers;
49 private MetricsSet fMetrics;
51 private AJSCPropertiesMap ajscPropertiesMap;
53 private KafkaConsumerCache kafkaConsumerCache;
56 public void setUp() throws Exception {
60 public void tearDown() throws Exception {
64 public void testSweep() {
65 kafkaConsumerCache.sweep();
66 Collection<? extends Consumer> cachedConsumers =
67 kafkaConsumerCache.getConsumers();
68 assertTrue(cachedConsumers.isEmpty());
74 public void testStartCache() {
77 * KafkaConsumerCache kafka = null;
79 * try { kafka = new KafkaConsumerCache("123", null);
81 * } catch (NoClassDefFoundError e) { try { kafka.startCache("DMAAP",
82 * null); } catch (NullPointerException e1) { // TODO Auto-generated
83 * catch block assertTrue(true); } catch (KafkaConsumerCacheException
84 * e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
88 new CuratorFrameworkImpl();
90 KafkaConsumerCache kafka=null;
92 kafka = new KafkaConsumerCache();
94 kafka.startCache("DMAAP", null);
95 } catch (NoClassDefFoundError e) {
97 } catch (KafkaConsumerCacheException e) {
98 // TODO Auto-generated catch block
105 public void testGetCuratorFramework() {
107 CuratorFramework curator = new CuratorFrameworkImpl();
108 new MetricsSetImpl();
111 } catch (NoClassDefFoundError e) {
113 KafkaConsumerCache.getCuratorFramework(curator);
119 * @Test public void testStopCache() {
121 * KafkaConsumerCache kafka = null; new CuratorFrameworkImpl(); new
122 * MetricsSetImpl(); try { kafka = new KafkaConsumerCache("123", null);
123 * kafka.stopCache(); } catch (NoClassDefFoundError e) {
130 @Test(expected= KafkaConsumerCacheException.class)
131 public void testGetConsumerThrowNoConnectionToCache() throws KafkaConsumerCacheException{
132 KafkaConsumerCache kafka = new KafkaConsumerCache();
133 kafka.getConsumerFor("testTopic", "CG1", "23");
137 public void testGetConsumerFor() {
139 KafkaConsumerCache kafka = null;
142 kafka = new KafkaConsumerCache();
143 kafka.getConsumerFor("testTopic", "CG1", "23");
144 } catch (NoClassDefFoundError e) {
146 } catch (KafkaConsumerCacheException e) {
147 // TODO Auto-generated catch block
154 public void testPutConsumerFor() {
156 Kafka011Consumer consumer = null;
157 KafkaConsumerCache kafka = null;
160 kafka = new KafkaConsumerCache();
162 } catch (NoClassDefFoundError e) {
164 kafka.putConsumerFor("testTopic", "CG1", "23", consumer);
165 } catch (NullPointerException e1) {
166 // TODO Auto-generated catch block
168 } catch (KafkaConsumerCacheException e1) {
169 // TODO Auto-generated catch block
170 e1.printStackTrace();
177 public void testGetConsumers() {
179 KafkaConsumerCache kafka = null;
182 kafka = new KafkaConsumerCache();
184 } catch (NoClassDefFoundError e) {
186 kafka.getConsumers();
187 } catch (NullPointerException e1) {
188 // TODO Auto-generated catch block
196 public void testDropAllConsumers() {
198 KafkaConsumerCache kafka = null;
200 kafka = new KafkaConsumerCache();
202 } catch (NoClassDefFoundError e) {
204 kafka.dropAllConsumers();
205 } catch (NullPointerException e1) {
206 // TODO Auto-generated catch block
214 public void testSignalOwnership() {
216 KafkaConsumerCache kafka = null;
219 kafka = new KafkaConsumerCache();
221 kafka.signalOwnership("testTopic", "CG1", "23");
222 } catch (KafkaConsumerCacheException e) {
225 } catch (NoClassDefFoundError e) {}
231 public void testDropConsumer() {
233 KafkaConsumerCache kafka = null;
236 kafka = new KafkaConsumerCache();
237 // kafka.dropConsumer("testTopic", "CG1", "23");
238 } catch (NoClassDefFoundError e) {
240 kafka.dropConsumer("testTopic", "CG1", "23");
241 } catch (NullPointerException e1) {
242 // TODO Auto-generated catch block