1d59166d82da01cc0ca2aff3d89795f3000d2cbc
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / store / AbstractSnapshotBackedTransactionChainTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.spi.store;
9
10 import static org.mockito.Mockito.doReturn;
11
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14 import org.mockito.Mock;
15 import org.mockito.junit.MockitoJUnitRunner;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
18
19 @RunWith(MockitoJUnitRunner.StrictStubs.class)
20 public class AbstractSnapshotBackedTransactionChainTest {
21     @Mock
22     public DataTreeSnapshot dataTreeSnapshot;
23     @Mock
24     public DOMStoreThreePhaseCommitCohort domStoreThreePhaseCommitCohort;
25     @Mock
26     public DataTreeModification dataTreeModification;
27     @Mock
28     public SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
29
30     @Test
31     public void basicTest() throws Exception {
32         doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
33
34         final var chain = new AbstractSnapshotBackedTransactionChain<>() {
35             @Override
36             protected Object nextTransactionIdentifier() {
37                 return new Object();
38             }
39
40             @Override
41             protected boolean getDebugTransactions() {
42                 return false;
43             }
44
45             @Override
46             protected DataTreeSnapshot takeSnapshot() {
47                 return dataTreeSnapshot;
48             }
49
50             @Override
51             protected DOMStoreThreePhaseCommitCohort createCohort(
52                     final SnapshotBackedWriteTransaction<Object> transaction, final DataTreeModification modification,
53                     final Exception operationError) {
54                 return domStoreThreePhaseCommitCohort;
55             }
56         };
57
58         chain.newReadOnlyTransaction().close();
59         chain.newWriteOnlyTransaction().close();
60         chain.newReadWriteTransaction().close();
61
62         chain.transactionReady(snapshotBackedWriteTransaction, dataTreeModification, null);
63
64         chain.transactionAborted(snapshotBackedWriteTransaction);
65         chain.close();
66
67         chain.onTransactionCommited(snapshotBackedWriteTransaction);
68         chain.onTransactionFailed(snapshotBackedWriteTransaction, null);
69     }
70 }