Remove unused exceptions
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedTransactionChainTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.databroker;
9
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.Mockito;
15 import org.mockito.MockitoAnnotations;
16 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
19 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.MemberName;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
23 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
24 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
25
26 public class ClientBackedTransactionChainTest {
27     private ClientBackedTransactionChain chain;
28
29     @Mock
30     private ClientLocalHistory history;
31     @Mock
32     private ClientSnapshot snapshot;
33     @Mock
34     private ClientTransaction transaction;
35
36     @Before
37     public void setUp() {
38         MockitoAnnotations.initMocks(this);
39
40         final FrontendIdentifier frontendId = FrontendIdentifier.create(
41                 MemberName.forName("member"), FrontendType.forName("frontend"));
42         final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
43         final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
44         final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
45
46         Mockito.when(history.getIdentifier()).thenReturn(historyId);
47         Mockito.when(transaction.getIdentifier()).thenReturn(transactionId);
48         Mockito.when(snapshot.getIdentifier()).thenReturn(transactionId);
49         Mockito.when(history.takeSnapshot()).thenReturn(snapshot);
50         Mockito.when(history.createTransaction()).thenReturn(transaction);
51
52         chain = new ClientBackedTransactionChain(history, false);
53     }
54
55     @Test
56     public void testNewReadOnlyTransaction() {
57         Assert.assertNotNull(chain.newReadOnlyTransaction());
58         Mockito.verify(history).takeSnapshot();
59     }
60
61     @Test
62     public void testNewReadWriteTransaction() {
63         Assert.assertNotNull(chain.newReadWriteTransaction());
64         Mockito.verify(history).createTransaction();
65     }
66
67     @Test
68     public void testNewWriteOnlyTransaction() {
69         Assert.assertNotNull(chain.newWriteOnlyTransaction());
70         Mockito.verify(history).createTransaction();
71     }
72
73     @Test
74     public void testClose() {
75         chain.newReadOnlyTransaction();
76         chain.close();
77         Mockito.verify(snapshot).abort();
78         Mockito.verify(history).close();
79     }
80
81     @Test
82     public void testSnapshotClosed() {
83         chain.snapshotClosed(snapshot);
84         // snap is removed, so cannot be aborted
85         chain.close();
86         Mockito.verify(snapshot, Mockito.never()).abort();
87         Mockito.verify(history).close();
88     }
89 }