1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.cambria.backends.kafka;
24 import static org.junit.Assert.assertTrue;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.apache.curator.framework.CuratorFramework;
30 import org.apache.curator.framework.api.CreateBuilder;
31 import org.apache.curator.framework.api.ExistsBuilder;
32 import org.apache.curator.framework.api.GetChildrenBuilder;
33 import org.apache.curator.framework.api.ProtectACLCreateModeStatPathAndBytesable;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.MockitoAnnotations;
41 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaLiveLockAvoider2;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.core.classloader.annotations.PowerMockIgnore;
44 import org.powermock.modules.junit4.PowerMockRunner;
46 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
47 @RunWith(PowerMockRunner.class)
48 public class KafkaLiveLockAvoider2Test {
51 private CuratorFramework curatorFramework;
53 private ExistsBuilder existsBuilder;
55 private CreateBuilder createBuilder;
57 private GetChildrenBuilder childrenBuilder;
59 ProtectACLCreateModeStatPathAndBytesable<String> acl;
61 private KafkaLiveLockAvoider2 liveLockAvoider;
63 public static final String ZNODE_ROOT = "/live-lock-avoid";
64 public static final String ZNODE_LOCKS = "/locks";
65 public static final String ZNODE_UNSTICK_TASKS ="/unstick-tasks";
67 private static String locksPath = ZNODE_ROOT+ZNODE_LOCKS;
68 private static String tasksPath = ZNODE_ROOT+ZNODE_UNSTICK_TASKS;
72 public void setUp() throws Exception {
73 List<String> taskNodes= new ArrayList<String>();
74 taskNodes.add("appId");
75 MockitoAnnotations.initMocks(this);
76 PowerMockito.when(acl.forPath(locksPath)).thenReturn(locksPath);
77 PowerMockito.when(acl.forPath(tasksPath)).thenReturn(tasksPath);
78 PowerMockito.when(createBuilder.creatingParentsIfNeeded()).thenReturn(acl);
79 PowerMockito.when(curatorFramework.create()).thenReturn(createBuilder);
80 PowerMockito.when(curatorFramework.checkExists()).thenReturn(existsBuilder);
81 PowerMockito.when(childrenBuilder.forPath(tasksPath)).thenReturn(taskNodes);
82 PowerMockito.when(curatorFramework.getChildren()).thenReturn(childrenBuilder);
87 public void tearDown() throws Exception {
91 public void testUnlock(){
92 liveLockAvoider.init();
94 liveLockAvoider.unlockConsumerGroup("appId", "groupName");
95 } catch (Exception e) {
101 public void testWatcher(){
103 liveLockAvoider.startNewWatcherForServer("appId", null);
104 } catch (Exception e) {