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.broker;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.atLeastOnce;
14 import static org.mockito.Mockito.doNothing;
15 import static org.mockito.Mockito.doReturn;
16 import static org.mockito.Mockito.mock;
17 import static org.mockito.Mockito.verify;
19 import com.google.common.util.concurrent.FluentFuture;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.common.api.CommitInfo;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
24 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 public class TransactionChainReadTransactionTest {
30 public void basicTest() throws Exception {
31 final String identifier = "testIdent";
32 final DOMDataTreeReadTransaction readTransaction = mock(DOMDataTreeReadTransaction.class);
33 final ShardedDOMTransactionChainAdapter chainAdapter = mock(ShardedDOMTransactionChainAdapter.class);
34 FluentFuture<? extends CommitInfo> previousWriteTxFuture = FluentFutures.immediateNullFluentFuture();
36 TransactionChainReadTransaction transactionChainReadTransaction =
37 new TransactionChainReadTransaction(identifier, readTransaction, previousWriteTxFuture, chainAdapter);
39 assertEquals(identifier, transactionChainReadTransaction.getIdentifier());
41 doNothing().when(readTransaction).close();
42 doNothing().when(chainAdapter).closeReadTransaction();
43 transactionChainReadTransaction.close();
44 verify(readTransaction).close();
45 verify(chainAdapter).closeReadTransaction();
47 doReturn(FluentFutures.immediateNullFluentFuture()).when(readTransaction).read(any(), any());
48 assertNotNull(transactionChainReadTransaction.exists(
49 LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY));
50 transactionChainReadTransaction.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
51 verify(readTransaction, atLeastOnce()).read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
53 doReturn(FluentFutures.immediateFailedFluentFuture(
54 new NullPointerException())).when(readTransaction).read(any(), any());
55 doNothing().when(chainAdapter).transactionFailed(any(), any());
56 assertNotNull(transactionChainReadTransaction.read(
57 LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY));
58 previousWriteTxFuture = FluentFutures.immediateFailedFluentFuture(new NullPointerException());
59 transactionChainReadTransaction =
60 new TransactionChainReadTransaction(identifier, readTransaction, previousWriteTxFuture, chainAdapter);
61 assertNotNull(transactionChainReadTransaction.read(
62 LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY));