2 * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.spi.store;
10 import static org.mockito.Mockito.doReturn;
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;
19 @RunWith(MockitoJUnitRunner.StrictStubs.class)
20 public class AbstractSnapshotBackedTransactionChainTest {
22 public DataTreeSnapshot dataTreeSnapshot;
24 public DOMStoreThreePhaseCommitCohort domStoreThreePhaseCommitCohort;
26 public DataTreeModification dataTreeModification;
28 public SnapshotBackedWriteTransaction<Object> snapshotBackedWriteTransaction;
31 public void basicTest() throws Exception {
32 doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
34 final var chain = new AbstractSnapshotBackedTransactionChain<>() {
36 protected Object nextTransactionIdentifier() {
41 protected boolean getDebugTransactions() {
46 protected DataTreeSnapshot takeSnapshot() {
47 return dataTreeSnapshot;
51 protected DOMStoreThreePhaseCommitCohort createCohort(
52 final SnapshotBackedWriteTransaction<Object> transaction, final DataTreeModification modification,
53 final Exception operationError) {
54 return domStoreThreePhaseCommitCohort;
58 chain.newReadOnlyTransaction().close();
59 chain.newWriteOnlyTransaction().close();
60 chain.newReadWriteTransaction().close();
62 chain.transactionReady(snapshotBackedWriteTransaction, dataTreeModification, null);
64 chain.transactionAborted(snapshotBackedWriteTransaction);
67 chain.onTransactionCommited(snapshotBackedWriteTransaction);
68 chain.onTransactionFailed(snapshotBackedWriteTransaction, null);