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.modules.junit4.PowerMockRunner;
46 @RunWith(PowerMockRunner.class)
47 public class KafkaLiveLockAvoider2Test {
50 private CuratorFramework curatorFramework;
52 private ExistsBuilder existsBuilder;
54 private CreateBuilder createBuilder;
56 private GetChildrenBuilder childrenBuilder;
58 ProtectACLCreateModeStatPathAndBytesable<String> acl;
60 private KafkaLiveLockAvoider2 liveLockAvoider;
62 public static final String ZNODE_ROOT = "/live-lock-avoid";
63 public static final String ZNODE_LOCKS = "/locks";
64 public static final String ZNODE_UNSTICK_TASKS ="/unstick-tasks";
66 private static String locksPath = ZNODE_ROOT+ZNODE_LOCKS;
67 private static String tasksPath = ZNODE_ROOT+ZNODE_UNSTICK_TASKS;
71 public void setUp() throws Exception {
72 List<String> taskNodes= new ArrayList<String>();
73 taskNodes.add("appId");
74 MockitoAnnotations.initMocks(this);
75 PowerMockito.when(acl.forPath(locksPath)).thenReturn(locksPath);
76 PowerMockito.when(acl.forPath(tasksPath)).thenReturn(tasksPath);
77 PowerMockito.when(createBuilder.creatingParentsIfNeeded()).thenReturn(acl);
78 PowerMockito.when(curatorFramework.create()).thenReturn(createBuilder);
79 PowerMockito.when(curatorFramework.checkExists()).thenReturn(existsBuilder);
80 PowerMockito.when(childrenBuilder.forPath(tasksPath)).thenReturn(taskNodes);
81 PowerMockito.when(curatorFramework.getChildren()).thenReturn(childrenBuilder);
86 public void tearDown() throws Exception {
90 public void testUnlock(){
91 liveLockAvoider.init();
93 liveLockAvoider.unlockConsumerGroup("appId", "groupName");
94 } catch (Exception e) {
100 public void testWatcher(){
102 liveLockAvoider.startNewWatcherForServer("appId", null);
103 } catch (Exception e) {