CDS: Change operationTimeout units to millis
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / LocalTransactionContextTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import static org.mockito.Mockito.doReturn;
4 import static org.mockito.Mockito.mock;
5 import static org.mockito.Mockito.verify;
6 import akka.dispatch.ExecutionContexts;
7 import com.google.common.base.Optional;
8 import com.google.common.util.concurrent.Futures;
9 import com.google.common.util.concurrent.MoreExecutors;
10 import com.google.common.util.concurrent.SettableFuture;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.MockitoAnnotations;
15 import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
16 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 public class LocalTransactionContextTest {
24
25     @Mock
26     OperationLimiter limiter;
27
28     @Mock
29     TransactionIdentifier identifier;
30
31     @Mock
32     DOMStoreReadWriteTransaction readWriteTransaction;
33
34     LocalTransactionContext localTransactionContext;
35
36     @Before
37     public void setUp() {
38         MockitoAnnotations.initMocks(this);
39         localTransactionContext = new LocalTransactionContext(readWriteTransaction, limiter.getIdentifier()) {
40             @Override
41             protected DOMStoreWriteTransaction getWriteDelegate() {
42                 return readWriteTransaction;
43             }
44
45             @Override
46             protected DOMStoreReadTransaction getReadDelegate() {
47                 return readWriteTransaction;
48             }
49         };
50     }
51
52     @Test
53     public void testWrite() {
54         YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
55         NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
56         localTransactionContext.writeData(yangInstanceIdentifier, normalizedNode);
57         verify(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
58     }
59
60     @Test
61     public void testMerge() {
62         YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
63         NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
64         localTransactionContext.mergeData(yangInstanceIdentifier, normalizedNode);
65         verify(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);
66     }
67
68     @Test
69     public void testDelete() {
70         YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
71         localTransactionContext.deleteData(yangInstanceIdentifier);
72         verify(readWriteTransaction).delete(yangInstanceIdentifier);
73     }
74
75
76     @Test
77     public void testRead() {
78         YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
79         NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
80         doReturn(Futures.immediateCheckedFuture(Optional.of(normalizedNode))).when(readWriteTransaction).read(yangInstanceIdentifier);
81         localTransactionContext.readData(yangInstanceIdentifier, SettableFuture.<Optional<NormalizedNode<?,?>>>create());
82         verify(readWriteTransaction).read(yangInstanceIdentifier);
83     }
84
85     @Test
86     public void testExists() {
87         YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().build();
88         doReturn(Futures.immediateCheckedFuture(true)).when(readWriteTransaction).exists(yangInstanceIdentifier);
89         localTransactionContext.dataExists(yangInstanceIdentifier, SettableFuture.<Boolean> create());
90         verify(readWriteTransaction).exists(yangInstanceIdentifier);
91     }
92
93     @Test
94     public void testReady() {
95         final LocalThreePhaseCommitCohort mockCohort = mock(LocalThreePhaseCommitCohort.class);
96         final ActorContext mockContext = mock(ActorContext.class);
97         doReturn(mockContext).when(mockCohort).getActorContext();
98         doReturn(ExecutionContexts.fromExecutor(MoreExecutors.directExecutor())).when(mockContext).getClientDispatcher();
99         doReturn(akka.dispatch.Futures.successful(null)).when(mockCohort).initiateCoordinatedCommit();
100         doReturn(mockCohort).when(readWriteTransaction).ready();
101         localTransactionContext.readyTransaction();
102         verify(readWriteTransaction).ready();
103     }
104
105
106 }

©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.