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.never;
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;
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class ClientBackedTransactionChainTest {
32 private ClientBackedTransactionChain chain;
35 private ClientLocalHistory history;
37 private ClientSnapshot snapshot;
39 private ClientTransaction transaction;
43 final FrontendIdentifier frontendId = FrontendIdentifier.create(
44 MemberName.forName("member"), FrontendType.forName("frontend"));
45 final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
46 final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
47 final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
49 doReturn(transactionId).when(transaction).getIdentifier();
50 doReturn(transactionId).when(snapshot).getIdentifier();
51 doReturn(snapshot).when(history).takeSnapshot();
52 doReturn(transaction).when(history).createTransaction();
54 chain = new ClientBackedTransactionChain(history, false);
58 public void testNewReadOnlyTransaction() {
59 assertNotNull(chain.newReadOnlyTransaction());
60 verify(history).takeSnapshot();
64 public void testNewReadWriteTransaction() {
65 assertNotNull(chain.newReadWriteTransaction());
66 verify(history).createTransaction();
70 public void testNewWriteOnlyTransaction() {
71 assertNotNull(chain.newWriteOnlyTransaction());
72 verify(history).createTransaction();
76 public void testClose() {
77 chain.newReadOnlyTransaction();
79 verify(snapshot).abort();
80 verify(history).close();
84 public void testSnapshotClosed() {
85 chain.snapshotClosed(snapshot);
86 // snap is removed, so cannot be aborted
88 verify(snapshot, never()).abort();
89 verify(history).close();