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;
33 @RunWith(MockitoJUnitRunner.StrictStubs.class)
34 public class ClientBackedDataStoreTest {
36 private static final ClientIdentifier UNKNOWN_ID = ClientIdentifier.create(
37 FrontendIdentifier.create(MemberName.forName("local"), FrontendType.forName("unknown")), 0);
39 private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
40 MemberName.forName("member"), FrontendType.forName("frontend"));
41 private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
43 private static final TransactionIdentifier TRANSACTION_IDENTIFIER =
44 new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0), 0);
47 private DataStoreClient clientActor;
49 private ActorUtils actorUtils;
51 private ClientLocalHistory clientLocalHistory;
53 private ClientTransaction clientTransaction;
55 private ClientSnapshot clientSnapshot;
59 doReturn(DatastoreContext.newBuilder().build()).when(actorUtils).getDatastoreContext();
60 doReturn(TRANSACTION_IDENTIFIER).when(clientTransaction).getIdentifier();
61 doReturn(TRANSACTION_IDENTIFIER).when(clientSnapshot).getIdentifier();
63 doReturn(clientTransaction).when(clientActor).createTransaction();
64 doReturn(clientLocalHistory).when(clientActor).createLocalHistory();
65 doReturn(clientSnapshot).when(clientActor).createSnapshot();
69 public void testCreateTransactionChain() {
70 try (var clientBackedDataStore = new ClientBackedDataStore(actorUtils, UNKNOWN_ID, clientActor)) {
71 assertNotNull(clientBackedDataStore.createTransactionChain());
72 verify(clientActor, times(1)).createLocalHistory();
77 public void testNewReadOnlyTransaction() {
78 try (var clientBackedDataStore = new ClientBackedDataStore(actorUtils, UNKNOWN_ID, clientActor)) {
79 assertNotNull(clientBackedDataStore.newReadOnlyTransaction());
80 verify(clientActor, times(1)).createSnapshot();
85 public void testNewWriteOnlyTransaction() {
86 try (var clientBackedDataStore = new ClientBackedDataStore(actorUtils, UNKNOWN_ID, clientActor)) {
87 assertNotNull(clientBackedDataStore.newWriteOnlyTransaction());
88 verify(clientActor, times(1)).createTransaction();
93 public void testNewReadWriteTransaction() {
94 try (var clientBackedDataStore = new ClientBackedDataStore(actorUtils, UNKNOWN_ID, clientActor)) {
95 assertNotNull(clientBackedDataStore.newReadWriteTransaction());
96 verify(clientActor, times(1)).createTransaction();