66fa876277ca97a164a5b433fa3e11ecb50e69a7
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DistributedDataStoreTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import static org.mockito.Mockito.doReturn;
4 import static org.mockito.Mockito.times;
5 import static org.mockito.Mockito.verify;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.mockito.Mock;
9 import org.mockito.MockitoAnnotations;
10 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
11 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13
14 public class DistributedDataStoreTest extends AbstractActorTest {
15
16     private SchemaContext schemaContext;
17
18     @Mock
19     private ActorContext actorContext;
20
21     @Before
22     public void setUp() throws Exception {
23         MockitoAnnotations.initMocks(this);
24
25         schemaContext = TestModel.createTestContext();
26
27         doReturn(schemaContext).when(actorContext).getSchemaContext();
28     }
29
30     @Test
31     public void testRateLimitingUsedInReadWriteTxCreation(){
32         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
33
34         distributedDataStore.newReadWriteTransaction();
35
36         verify(actorContext, times(1)).acquireTxCreationPermit();
37     }
38
39     @Test
40     public void testRateLimitingUsedInWriteOnlyTxCreation(){
41         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
42
43         distributedDataStore.newWriteOnlyTransaction();
44
45         verify(actorContext, times(1)).acquireTxCreationPermit();
46     }
47
48
49     @Test
50     public void testRateLimitingNotUsedInReadOnlyTxCreation(){
51         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
52
53         distributedDataStore.newReadOnlyTransaction();
54         distributedDataStore.newReadOnlyTransaction();
55         distributedDataStore.newReadOnlyTransaction();
56
57         verify(actorContext, times(0)).acquireTxCreationPermit();
58     }
59
60 }