aboutsummaryrefslogtreecommitdiffstats
path: root/jar/src/test/java/org/onap/music/unittests/TestMusicCore.java
blob: e798aaf193705240054cd4f318d07332a9aaf1b5 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
 * ============LICENSE_START==========================================
 * org.onap.music
 * ===================================================================
 *  Copyright (c) 2017 AT&T Intellectual Property
 * ===================================================================
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 * ============LICENSE_END=============================================
 * ====================================================================
 */
package org.onap.music.unittests;

import static org.junit.Assert.*;
import static org.onap.music.main.MusicCore.mDstoreHandle;
import static org.onap.music.main.MusicCore.mLockHandle;

import org.apache.zookeeper.KeeperException.NoNodeException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.music.exceptions.MusicLockingException;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.MusicLockState;
import org.onap.music.lockingservice.MusicLockingService;
import org.onap.music.lockingservice.MusicLockState.LockStatus;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;
import org.onap.music.main.ResultType;
import org.onap.music.main.ReturnType;
import org.onap.music.main.MusicCore.Condition;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;

@RunWith(MockitoJUnitRunner.class)
public class TestMusicCore {

    @Mock
    private Condition condition;

    @Mock
    private ResultSet rs;

    @Mock
    private PreparedQueryObject preparedQueryObject;
    
    @Mock
    private Session session;

    @Before
    public void setUp() {
        mLockHandle = Mockito.mock(MusicLockingService.class);

    }

    @Test
    public void testCreateLockReferenceforvalidlock() {
        Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
        String lockId = MusicCore.createLockReference("test");
        assertEquals("lock", lockId);
        Mockito.verify(mLockHandle).createLockId("/" + "test");
    }

    @Test
    public void testIsTableOrKeySpaceLock() {
        Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
        assertTrue(result);
    }

    @Test
    public void testIsTableOrKeySpaceLockwithPrimarykey() {
        Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
        assertFalse(result);
    }

    @Test
    public void testGetMusicLockState() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
        MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
        assertEquals(musicLockState, mls);
        Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
    }

    @Test
    public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
        assertEquals(lock.getResult(), ResultType.SUCCESS);
        Mockito.verify(mLockHandle).isMyTurn("id1");
    }

    @Test
    public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
        ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
        assertEquals(lock.getResult(), ResultType.FAILURE);
        Mockito.verify(mLockHandle).isMyTurn("id1");
    }

    @Test
    public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
        assertEquals(lock.getResult(), ResultType.SUCCESS);
        Mockito.verify(mLockHandle).isMyTurn("id1");
    }

    @Test
    public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
        assertEquals(lock.getResult(), ResultType.SUCCESS);
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
    }

    @Test
    public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
        assertEquals(lock.getResult(), ResultType.SUCCESS);
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
    }
    
    @Test
    public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
        Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
        ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
        assertEquals(lock.getResult(), ResultType.FAILURE);
        assertEquals(lock.getMessage(), "Lockid doesn't exist");
        Mockito.verify(mLockHandle).lockIdExists("bs1");
    }
    
    @Test
    public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
        musicLockState.setLeasePeriod(0);
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
    }
    
    @Test
    public void testAcquireLockWithLeasewithException() throws MusicLockingException {
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
    }

    @Test
    public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
    }

    @Test
    public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");

    }

    @Test
    public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
        ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
    }

    @Test
    public void testQuorumGet() throws MusicServiceException, MusicQueryException {
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        rs = Mockito.mock(ResultSet.class);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
        ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
        assertNotNull(rs1);
    }

    @Test
    public void testGetLockNameFromId() {
        String lockname = MusicCore.getLockNameFromId("lockName$id");
        assertEquals("lockName", lockname);
    }

    @Test
    public void testDestroyLockRef() throws NoNodeException {
        Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
        MusicCore.destroyLockRef("id1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
    }

    @Test
    public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
        Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
        MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
        assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
    }

    @Test
    public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
        Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
        MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
        assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
    }

    @Test
    public void testDeleteLock() throws MusicLockingException {
        Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
        MusicCore.deleteLock("id1");
        Mockito.verify(mLockHandle).deleteLock("/" + "id1");
    }

    /*
     * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
     * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
     * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
     * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
     * "consistency"); }
     */

    @Test
    public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
        ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
    }

    @Test
    public void testEventualPutPreparedQuerywithResultFalse()
                    throws MusicServiceException, MusicQueryException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
        ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
        assertEquals(expectedResult.getResult(), actualResult.getResult());
        Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
        //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
    }

    @Test
    public void testCriticalPutPreparedQuerywithValidLockId()
                    throws Exception {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        Mockito.when(condition.testCondition()).thenReturn(true);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
        ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
                        "id1", condition);
        assertEquals(expectedResult.getResult(), returnType.getResult());
        Mockito.verify(condition).testCondition();
        Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
        Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
    }

    @Test
    public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
                        "id1", condition);
        assertEquals(expectedResult.getResult(), returnType.getResult());
        Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
    }

    @Test
    public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        Mockito.when(condition.testCondition()).thenReturn(false);
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
                        "id1", condition);
        assertEquals(expectedResult.getResult(), returnType.getResult());
        Mockito.verify(condition).testCondition();
        Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
    }

    @Test
    public void testNonKeyRelatedPutPreparedQuery() throws Exception {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
        ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
        assertEquals(ResultType.SUCCESS, result);
        Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
    }

    @Test
    public void testAtomicPutPreparedQuery() throws Exception {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
        ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        Mockito.when(condition.testCondition()).thenReturn(true);
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
        ReturnType returnType =
                        MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
        assertEquals(expectedResult.getResult(), returnType.getResult());
        Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(condition).testCondition();
        Mockito.verify(mLockHandle, Mockito.atLeastOnce())
                        .getLockState("ks1" + "." + "tn1" + "." + "pk1");
        Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
    }

    @Test
    public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
        ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
        ReturnType returnType =
                        MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
        assertEquals(expectedResult.getResult(), returnType.getResult());
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
    }

    @Test
    public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        rs = Mockito.mock(ResultSet.class);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
        MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
        Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
        ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
        assertNotNull(rs1);
        Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
        Mockito.verify(mLockHandle).isMyTurn("id1");
        Mockito.verify(mLockHandle, Mockito.atLeastOnce())
                        .getLockState("ks1" + "." + "tn1" + "." + "pk1");
        Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
    }

    @Test
    public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
                    throws MusicServiceException, MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        rs = Mockito.mock(ResultSet.class);
        Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
        Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
        ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
        assertNull(rs1);
        Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
        Mockito.verify(mLockHandle).isMyTurn("id1");
    }

    @Test
    public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        rs = Mockito.mock(ResultSet.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
        ResultSet rs1 = MusicCore.get(preparedQueryObject);
        assertNotNull(rs1);
        Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);

    }

    @Test
    public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
        rs = Mockito.mock(ResultSet.class);
        session = Mockito.mock(Session.class);
        Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
        ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
        assertNotNull(rs1);
        Mockito.verify(mLockHandle, Mockito.atLeastOnce())
                        .getLockState("ks1" + "." + "tn1" + "." + "pk1");
        Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
    }

    @Test
    public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
        mDstoreHandle = Mockito.mock(MusicDataStore.class);
        preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
        MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
        Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
                        .thenReturn(musicLockState);
        ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
        assertNull(rs1);
        Mockito.verify(mLockHandle, Mockito.atLeastOnce())
                        .getLockState("ks1" + "." + "tn1" + "." + "pk1");
    }

}