Remove JournalWriter.getLastEntry()
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedDataStoreTest.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 static org.junit.Assert.assertNotNull;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.Mock;
19 import org.mockito.junit.MockitoJUnitRunner;
20 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
22 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
23 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
24 import org.opendaylight.controller.cluster.access.concepts.MemberName;
25 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
26 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
27 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
28 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
29 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
30 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
31 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
32 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
33 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
34 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
35 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
36
37 @RunWith(MockitoJUnitRunner.StrictStubs.class)
38 public class ClientBackedDataStoreTest {
39
40     private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
41             FrontendIdentifier.create(MemberName.forName("local"), FrontendType.forName("unknown")), 0);
42
43     private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
44             MemberName.forName("member"), FrontendType.forName("frontend"));
45     private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
46
47     private static final TransactionIdentifier TRANSACTION_IDENTIFIER =
48         new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0), 0);
49
50     @Mock
51     private DataStoreClient clientActor;
52
53     @Mock
54     private ActorUtils actorUtils;
55
56     @Mock
57     private ClientLocalHistory clientLocalHistory;
58
59     @Mock
60     private ClientTransaction clientTransaction;
61
62     @Mock
63     private ClientSnapshot clientSnapshot;
64
65     @Before
66     public void setUp() {
67         doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
68         doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier();
69         doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier();
70
71         doReturn(clientTransaction).when(clientActor).createTransaction();
72         doReturn(clientLocalHistory).when(clientActor).createLocalHistory();
73         doReturn(clientSnapshot).when(clientActor).createSnapshot();
74     }
75
76     @Test
77     public void testCreateTransactionChain() {
78         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
79                 actorUtils, UNKNOWN_ID, clientActor)) {
80             final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
81             assertNotNull(txChain);
82             verify(clientActor, times(1)).createLocalHistory();
83         }
84     }
85
86     @Test
87     public void testNewReadOnlyTransaction() {
88         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
89                 actorUtils, UNKNOWN_ID, clientActor)) {
90             final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction();
91             assertNotNull(tx);
92             verify(clientActor, times(1)).createSnapshot();
93         }
94     }
95
96     @Test
97     public void testNewWriteOnlyTransaction() {
98         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
99                 actorUtils, UNKNOWN_ID, clientActor)) {
100             final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction();
101             assertNotNull(tx);
102             verify(clientActor, times(1)).createTransaction();
103         }
104     }
105
106     @Test
107     public void testNewReadWriteTransaction() {
108         try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
109                 actorUtils, UNKNOWN_ID, clientActor)) {
110             final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction();
111             assertNotNull(tx);
112             verify(clientActor, times(1)).createTransaction();
113         }
114     }
115 }