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 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;
24 public class LocalReadOnlyProxyTransactionTest extends LocalProxyTransactionTest<LocalReadOnlyProxyTransaction> {
26 private DataTreeSnapshot snapshot;
29 protected LocalReadOnlyProxyTransaction createTransaction(final ProxyHistory parent,
30 final TransactionIdentifier id,
31 final DataTreeSnapshot snapshot) {
32 when(snapshot.readNode(PATH_1)).thenReturn(com.google.common.base.Optional.of(DATA_1));
33 when(snapshot.readNode(PATH_3)).thenReturn(com.google.common.base.Optional.absent());
34 this.snapshot = snapshot;
35 return new LocalReadOnlyProxyTransaction(parent, id, this.snapshot);
39 public void testIsSnapshotOnly() {
40 Assert.assertTrue(transaction.isSnapshotOnly());
44 public void testReadOnlyView() {
45 Assert.assertEquals(snapshot, transaction.readOnlyView());
49 @Test(expected = UnsupportedOperationException.class)
50 public void testDirectCommit() throws Exception {
51 transaction.directCommit();
55 @Test(expected = UnsupportedOperationException.class)
56 public void testCanCommit() throws Exception {
57 transaction.canCommit(new VotingFuture<>(new Object(), 1));
61 @Test(expected = UnsupportedOperationException.class)
62 public void testPreCommit() throws Exception {
63 transaction.preCommit(new VotingFuture<>(new Object(), 1));
67 @Test(expected = UnsupportedOperationException.class)
68 public void testDoCommit() throws Exception {
69 transaction.doCommit(new VotingFuture<>(new Object(), 1));
73 @Test(expected = UnsupportedOperationException.class)
74 public void testDelete() {
75 transaction.delete(PATH_1);
79 @Test(expected = UnsupportedOperationException.class)
80 public void testMerge() {
81 transaction.merge(PATH_1, DATA_1);
85 @Test(expected = UnsupportedOperationException.class)
86 public void testWrite() {
87 transaction.write(PATH_1, DATA_1);
90 @Test(expected = UnsupportedOperationException.class)
91 public void testDoDelete() {
92 transaction.doDelete(PATH_1);
95 @Test(expected = UnsupportedOperationException.class)
96 public void testDoMerge() {
97 transaction.doMerge(PATH_1, DATA_1);
100 @Test(expected = UnsupportedOperationException.class)
101 public void testDoWrite() {
102 transaction.doWrite(PATH_1, DATA_1);
105 @Test(expected = UnsupportedOperationException.class)
106 public void testCommitRequest() {
107 transaction.commitRequest(true);
111 public void testApplyModifyTransactionRequest() throws Exception {
112 final TestProbe probe = createProbe();
113 final ModifyTransactionRequestBuilder builder =
114 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
115 builder.setSequence(0);
117 final ModifyTransactionRequest request = builder.build();
118 transaction.replayModifyTransactionRequest(request, createCallbackMock(), Ticker.systemTicker().read());
119 getTester().expectTransactionRequest(AbortLocalTransactionRequest.class);
123 public void testApplyModifyTransactionRequestNotAbort() throws Exception {
124 final TestProbe probe = createProbe();
125 final ModifyTransactionRequestBuilder builder =
126 new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
127 builder.setSequence(0);
129 final ModifyTransactionRequest request = builder.build();
130 assertOperationThrowsException(() -> transaction.replayModifyTransactionRequest(request, createCallbackMock(),
131 Ticker.systemTicker().read()), VerifyException.class);