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.actors.dds;
10 import static org.mockito.Mockito.when;
11 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException;
13 import akka.testkit.TestProbe;
14 import com.google.common.base.Ticker;
15 import com.google.common.base.VerifyException;
16 import java.util.Optional;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
20 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
21 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder;
22 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
25 public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest<LocalReadOnlyProxyTransaction> {
27 private DataTreeSnapshot snapshot;
30 @SuppressWarnings("checkstyle:hiddenField")
31 protected LocalReadOnlyProxyTransaction createTransaction(final ProxyHistory parent,
32 final TransactionIdentifier id,
33 final DataTreeSnapshot snapshot) {
34 when(snapshot.readNode(PATH_1)).thenReturn(Optional.of(DATA_1));
35 when(snapshot.readNode(PATH_3)).thenReturn(Optional.empty());
36 this.snapshot = snapshot;
37 return new LocalReadOnlyProxyTransaction(parent, id, this.snapshot);
41 public void testIsSnapshotOnly() {
42 Assert.assertTrue(transaction.isSnapshotOnly());
46 public void testReadOnlyView() {
47 Assert.assertEquals(snapshot, transaction.readOnlyView());
51 @Test(expected = UnsupportedOperationException.class)
52 public void testDirectCommit() throws Exception {
53 transaction.directCommit();
57 @Test(expected = UnsupportedOperationException.class)
58 public void testCanCommit() throws Exception {
59 transaction.canCommit(new VotingFuture<>(new Object(), 1));
63 @Test(expected = UnsupportedOperationException.class)
64 public void testPreCommit() throws Exception {
65 transaction.preCommit(new VotingFuture<>(new Object(), 1));
69 @Test(expected = UnsupportedOperationException.class)
70 public void testDoCommit() throws Exception {
71 transaction.doCommit(new VotingFuture<>(new Object(), 1));
75 @Test(expected = UnsupportedOperationException.class)
76 public void testDelete() {
77 transaction.delete(PATH_1);
81 @Test(expected = UnsupportedOperationException.class)
82 public void testMerge() {
83 transaction.merge(PATH_1, DATA_1);
87 @Test(expected = UnsupportedOperationException.class)
88 public void testWrite() {
89 transaction.write(PATH_1, DATA_1);
92 @Test(expected = UnsupportedOperationException.class)
93 public void testDoDelete() {
94 transaction.doDelete(PATH_1);
97 @Test(expected = UnsupportedOperationException.class)
98 public void testDoMerge() {
99 transaction.doMerge(PATH_1, DATA_1);
102 @Test(expected = UnsupportedOperationException.class)
103 public void testDoWrite() {
104 transaction.doWrite(PATH_1, DATA_1);
107 @Test(expected = UnsupportedOperationException.class)
108 public void testCommitRequest() {
109 transaction.commitRequest(true);
113 public void testApplyModifyTransactionRequest() throws Exception {
114 final TestProbe probe = createProbe();
115 final ModifyTransactionRequestBuilder builder =
116 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
117 builder.setSequence(0);
119 final ModifyTransactionRequest request = builder.build();
120 transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read());
121 getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
125 public void testApplyModifyTransactionRequestNotAbort() throws Exception {
126 final TestProbe probe = createProbe();
127 final ModifyTransactionRequestBuilder builder =
128 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
129 builder.setSequence(0);
131 final ModifyTransactionRequest request = builder.build();
132 assertOperationThrowsException(() -> transaction.replayModifyTransactionRequest(request, createCallbackMock(),
133 Ticker.systemTicker().read()), VerifyException.class);