2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.unittests;
25 import static org.junit.Assert.*;
27 import org.apache.curator.test.TestingServer;
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.music.exceptions.MusicLockingException;
34 import org.onap.music.exceptions.MusicServiceException;
35 import org.onap.music.lockingservice.MusicLockState;
36 import org.onap.music.lockingservice.MusicLockingService;
37 import org.onap.music.lockingservice.ZkStatelessLockService;
38 import org.onap.music.lockingservice.MusicLockState.LockStatus;
40 public class MusicLockingServiceTest {
42 static MusicLockingService mLockHandle;
43 static TestingServer zkServer;
46 public static void init() throws Exception {
48 zkServer = new TestingServer(2181,new File("/tmp/zk"));
50 } catch (Exception e) {
53 System.out.println("####" + zkServer.getPort());
55 mLockHandle = new MusicLockingService();
56 } catch (MusicServiceException e) {
64 public static void tearDownAfterClass() throws Exception {
70 public void setUp() throws Exception {}
73 public void tearDown() throws Exception {
77 public void testMusicLockingService() {
78 assertTrue(mLockHandle != null);
82 public void testGetzkLockHandle() {
83 ZkStatelessLockService lockHandle = mLockHandle.getzkLockHandle();
84 assertTrue(lockHandle != null);
88 public void testMusicLockingServiceString() {
89 // MusicLockingService mLockTest = new MusicLockingService("localhost");
90 // assertTrue(mLockTest != null);
95 public void testCreateLockaIfItDoesNotExist() {
97 mLockHandle.createLockaIfItDoesNotExist("/ks1.tb1.pk1");
98 MusicLockState mls = null;
100 // mls = mLockHandle.
101 mls = mLockHandle.getLockState("ks1.tb1.pk1");
102 } catch (MusicLockingException e) {
105 System.out.println("Lock Holder:" + mls.getLockHolder());
106 assertFalse(mls.getLeaseStartTime() > 0);
110 public void testSetLockState() {
111 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
112 mLockHandle.setLockState("ks1.tb1.pk1",musicLockState);
113 MusicLockState mls = null;
115 mls = mLockHandle.getLockState("ks1.tb1.pk1");
116 } catch (MusicLockingException e) {
119 assertEquals(musicLockState.getLockHolder(), mls.getLockHolder());
124 // public void testGetLockState() {
125 // MusicLockState mls = null;
127 // mls = mLockHandle.getLockState("ks1.tb1.pk1");
128 // } catch (MusicLockingException e) {
129 // e.printStackTrace();
131 // assertTrue(mls.getLockHolder().equals("id1"));
135 // public void testCreateLockId() {
137 // fail("Not yet implemented"); // TODO
141 // public void testIsMyTurn() {
142 // fail("Not yet implemented"); // TODO
146 // public void testUnlockAndDeleteId() {
147 // fail("Not yet implemented"); // TODO
151 // public void testDeleteLock() {
152 // fail("Not yet implemented"); // TODO
156 // public void testWhoseTurnIsIt() {
157 // fail("Not yet implemented"); // TODO
161 // public void testProcess() {
162 // fail("Not yet implemented"); // TODO
166 // public void testClose() {
167 // fail("Not yet implemented"); // TODO
171 // public void testLockIdExists() {
172 // fail("Not yet implemented"); // TODO