ba38cfe11d8f03170d5e2851af04c39de534c15e
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / actors / dds / LocalReadOnlyProxyTransactionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.controller.cluster.databroker.actors.dds;
9
10 import static org.mockito.Mockito.when;
11 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.assertOperationThrowsException;
12
13 import akka.testkit.TestProbe;
14 import com.google.common.base.Ticker;
15 import com.google.common.base.VerifyException;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest;
19 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest;
20 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder;
21 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
23
24 public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest<LocalReadOnlyProxyTransaction> {
25
26     private DataTreeSnapshot snapshot;
27
28     @Override
29     @SuppressWarnings("checkstyle:hiddenField")
30     protected LocalReadOnlyProxyTransaction createTransaction(final ProxyHistory parent,
31                                                               final TransactionIdentifier id,
32                                                               final DataTreeSnapshot snapshot) {
33         when(snapshot.readNode(PATH_1)).thenReturn(com.google.common.base.Optional.of(DATA_1));
34         when(snapshot.readNode(PATH_3)).thenReturn(com.google.common.base.Optional.absent());
35         this.snapshot = snapshot;
36         return new LocalReadOnlyProxyTransaction(parent, id, this.snapshot);
37     }
38
39     @Test
40     public void testIsSnapshotOnly() {
41         Assert.assertTrue(transaction.isSnapshotOnly());
42     }
43
44     @Test
45     public void testReadOnlyView() {
46         Assert.assertEquals(snapshot, transaction.readOnlyView());
47     }
48
49     @Override
50     @Test(expected = UnsupportedOperationException.class)
51     public void testDirectCommit() throws Exception {
52         transaction.directCommit();
53     }
54
55     @Override
56     @Test(expected = UnsupportedOperationException.class)
57     public void testCanCommit() throws Exception {
58         transaction.canCommit(new VotingFuture<>(new Object(), 1));
59     }
60
61     @Override
62     @Test(expected = UnsupportedOperationException.class)
63     public void testPreCommit() throws Exception {
64         transaction.preCommit(new VotingFuture<>(new Object(), 1));
65     }
66
67     @Override
68     @Test(expected = UnsupportedOperationException.class)
69     public void testDoCommit() throws Exception {
70         transaction.doCommit(new VotingFuture<>(new Object(), 1));
71     }
72
73     @Override
74     @Test(expected = UnsupportedOperationException.class)
75     public void testDelete() {
76         transaction.delete(PATH_1);
77     }
78
79     @Override
80     @Test(expected = UnsupportedOperationException.class)
81     public void testMerge() {
82         transaction.merge(PATH_1, DATA_1);
83     }
84
85     @Override
86     @Test(expected = UnsupportedOperationException.class)
87     public void testWrite() {
88         transaction.write(PATH_1, DATA_1);
89     }
90
91     @Test(expected = UnsupportedOperationException.class)
92     public void testDoDelete() {
93         transaction.doDelete(PATH_1);
94     }
95
96     @Test(expected = UnsupportedOperationException.class)
97     public void testDoMerge() {
98         transaction.doMerge(PATH_1, DATA_1);
99     }
100
101     @Test(expected = UnsupportedOperationException.class)
102     public void testDoWrite() {
103         transaction.doWrite(PATH_1, DATA_1);
104     }
105
106     @Test(expected = UnsupportedOperationException.class)
107     public void testCommitRequest() {
108         transaction.commitRequest(true);
109     }
110
111     @Test
112     public void testApplyModifyTransactionRequest() throws Exception {
113         final TestProbe probe = createProbe();
114         final ModifyTransactionRequestBuilder builder =
115                 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
116         builder.setSequence(0);
117         builder.setAbort();
118         final ModifyTransactionRequest request = builder.build();
119         transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read());
120         getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
121     }
122
123     @Test
124     public void testApplyModifyTransactionRequestNotAbort() throws Exception {
125         final TestProbe probe = createProbe();
126         final ModifyTransactionRequestBuilder builder =
127                 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
128         builder.setSequence(0);
129         builder.setReady();
130         final ModifyTransactionRequest request = builder.build();
131         assertOperationThrowsException(() -> transaction.replayModifyTransactionRequest(request, createCallbackMock(),
132             Ticker.systemTicker().read()), VerifyException.class);
133     }
134 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.