Merge "BUG 2412 - restconf @GET getModule(identifier,uri) method migration"
[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         doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
29     }
30
31     @Test
32     public void testRateLimitingUsedInReadWriteTxCreation(){
33         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
34
35         distributedDataStore.newReadWriteTransaction();
36
37         verify(actorContext, times(1)).acquireTxCreationPermit();
38     }
39
40     @Test
41     public void testRateLimitingUsedInWriteOnlyTxCreation(){
42         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
43
44         distributedDataStore.newWriteOnlyTransaction();
45
46         verify(actorContext, times(1)).acquireTxCreationPermit();
47     }
48
49
50     @Test
51     public void testRateLimitingNotUsedInReadOnlyTxCreation(){
52         DistributedDataStore distributedDataStore = new DistributedDataStore(actorContext);
53
54         distributedDataStore.newReadOnlyTransaction();
55         distributedDataStore.newReadOnlyTransaction();
56         distributedDataStore.newReadOnlyTransaction();
57
58         verify(actorContext, times(0)).acquireTxCreationPermit();
59     }
60
61 }