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.verify;
12 import static org.mockito.Mockito.when;
14 import org.junit.AfterClass;
15 import org.junit.Before;
16 import org.junit.BeforeClass;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
22 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
23 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
24 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
25 import org.opendaylight.controller.cluster.access.concepts.MemberName;
26 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
27 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
28 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
29 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
30 import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
31 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
32 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
33 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
34 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
35 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
36 import org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain;
37 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
38 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
40 public class ClientBackedDataStoreTest {
42 private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
43 FrontendIdentifier.create(MemberName.forName("local"), FrontendType.forName("unknown")), 0);
45 private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
46 MemberName.forName("member"), FrontendType.forName("frontend"));
47 private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
49 private static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
50 private static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(HISTORY_ID, 0);
52 private static SchemaContext SCHEMA_CONTEXT;
55 private DataStoreClient clientActor;
58 private ActorUtils actorUtils;
61 private ClientLocalHistory clientLocalHistory;
64 private ClientTransaction clientTransaction;
67 private ClientSnapshot clientSnapshot;
70 public static void beforeClass() {
71 SCHEMA_CONTEXT = TestModel.createTestContext();
75 public static void afterClass() {
76 SCHEMA_CONTEXT = null;
81 MockitoAnnotations.initMocks(this);
83 when(actorUtils.getSchemaContext()).thenReturn(SCHEMA_CONTEXT);
84 when(actorUtils.getDatastoreContext()).thenReturn(DatastoreContext.newBuilder().build());
85 when(clientTransaction.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
86 when(clientSnapshot.getIdentifier()).thenReturn(TRANSACTION_IDENTIFIER);
88 when(clientActor.getIdentifier()).thenReturn(CLIENT_IDENTIFIER);
89 when(clientActor.createTransaction()).thenReturn(clientTransaction);
90 when(clientActor.createLocalHistory()).thenReturn(clientLocalHistory);
91 when(clientActor.createSnapshot()).thenReturn(clientSnapshot);
95 public void testCreateTransactionChain() {
96 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
97 actorUtils, UNKNOWN_ID, clientActor)) {
98 final DOMStoreTransactionChain txChain = clientBackedDataStore.createTransactionChain();
99 assertNotNull(txChain);
100 verify(clientActor, Mockito.times(1)).createLocalHistory();
105 public void testNewReadOnlyTransaction() {
106 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
107 actorUtils, UNKNOWN_ID, clientActor)) {
108 final DOMStoreReadTransaction tx = clientBackedDataStore.newReadOnlyTransaction();
110 verify(clientActor, Mockito.times(1)).createSnapshot();
115 public void testNewWriteOnlyTransaction() {
116 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
117 actorUtils, UNKNOWN_ID, clientActor)) {
118 final DOMStoreWriteTransaction tx = clientBackedDataStore.newWriteOnlyTransaction();
120 verify(clientActor, Mockito.times(1)).createTransaction();
125 public void testNewReadWriteTransaction() {
126 try (ClientBackedDataStore clientBackedDataStore = new ClientBackedDataStore(
127 actorUtils, UNKNOWN_ID, clientActor)) {
128 final DOMStoreReadWriteTransaction tx = clientBackedDataStore.newReadWriteTransaction();
130 verify(clientActor, Mockito.times(1)).createTransaction();