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 org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.Mockito;
15 import org.mockito.MockitoAnnotations;
16 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
19 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.MemberName;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
23 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
24 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
26 public class ClientBackedTransactionChainTest {
27 private ClientBackedTransactionChain chain;
30 private ClientLocalHistory history;
32 private ClientSnapshot snapshot;
34 private ClientTransaction transaction;
37 public void setUp() throws Exception {
38 MockitoAnnotations.initMocks(this);
40 final FrontendIdentifier frontendId = FrontendIdentifier.create(
41 MemberName.forName("member"), FrontendType.forName("frontend"));
42 final ClientIdentifier clientId = ClientIdentifier.create(frontendId, 0);
43 final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(clientId, 0);
44 final TransactionIdentifier transactionId = new TransactionIdentifier(historyId, 0);
46 Mockito.when(history.getIdentifier()).thenReturn(historyId);
47 Mockito.when(transaction.getIdentifier()).thenReturn(transactionId);
48 Mockito.when(snapshot.getIdentifier()).thenReturn(transactionId);
49 Mockito.when(history.takeSnapshot()).thenReturn(snapshot);
50 Mockito.when(history.createTransaction()).thenReturn(transaction);
52 chain = new ClientBackedTransactionChain(history, false);
56 public void testNewReadOnlyTransaction() throws Exception {
57 Assert.assertNotNull(chain.newReadOnlyTransaction());
58 Mockito.verify(history).takeSnapshot();
62 public void testNewReadWriteTransaction() throws Exception {
63 Assert.assertNotNull(chain.newReadWriteTransaction());
64 Mockito.verify(history).createTransaction();
68 public void testNewWriteOnlyTransaction() throws Exception {
69 Assert.assertNotNull(chain.newWriteOnlyTransaction());
70 Mockito.verify(history).createTransaction();
74 public void testClose() throws Exception {
75 chain.newReadOnlyTransaction();
77 Mockito.verify(snapshot).abort();
78 Mockito.verify(history).close();
82 public void testSnapshotClosed() throws Exception {
83 chain.snapshotClosed(snapshot);
84 // snap is removed, so cannot be aborted
86 Mockito.verify(snapshot, Mockito.never()).abort();
87 Mockito.verify(history).close();