2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.databroker;
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;
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;
37 @RunWith(MockitoJUnitRunner.StrictStubs.class)
38 public class ClientBackedDataStoreTest {
40 private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
41 FrontendIdentifier.create(MemberName.forName("local"), FrontendType.forName("unknown")), 0);
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);
47 private static final TransactionIdentifier TRANSACTION_IDENTIFIER =
48 new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0), 0);
51 private DataStoreClient clientActor;
54 private ActorUtils actorUtils;
57 private ClientLocalHistory clientLocalHistory;
60 private ClientTransaction clientTransaction;
63 private ClientSnapshot clientSnapshot;
67 doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
68 doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier();
69 doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier();
71 doReturn(clientTransaction).when(clientActor).createTransaction();
72 doReturn(clientLocalHistory).when(clientActor).createLocalHistory();
73 doReturn(clientSnapshot).when(clientActor).createSnapshot();
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();
87 public void testNewReadOnlyTransaction() {
88 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
89 actorUtils, UNKNOWN_ID, clientActor)) {
90 final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction();
92 verify(clientActor, times(1)).createSnapshot();
97 public void testNewWriteOnlyTransaction() {
98 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
99 actorUtils, UNKNOWN_ID, clientActor)) {
100 final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction();
102 verify(clientActor, times(1)).createTransaction();
107 public void testNewReadWriteTransaction() {
108 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
109 actorUtils, UNKNOWN_ID, clientActor)) {
110 final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction();
112 verify(clientActor, times(1)).createTransaction();