BUG 2518 : Throttle operations in a transaction
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / TransactionChainProxyTest.java
1 /*
2  *
3  *  Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  *  This program and the accompanying materials are made available under the
6  *  terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  *  and is available at http://www.eclipse.org/legal/epl-v10.html
8  *
9  */
10
11 package org.opendaylight.controller.cluster.datastore;
12
13 import static org.mockito.Matchers.anyObject;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
21 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
24 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction;
25 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27
28 public class TransactionChainProxyTest extends AbstractActorTest{
29     ActorContext actorContext = null;
30     SchemaContext schemaContext = mock(SchemaContext.class);
31
32     @Before
33     public void setUp() {
34         actorContext = new MockActorContext(getSystem());
35         actorContext.setSchemaContext(schemaContext);
36     }
37
38     @SuppressWarnings("resource")
39     @Test
40     public void testNewReadOnlyTransaction() throws Exception {
41
42      DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadOnlyTransaction();
43          Assert.assertTrue(dst instanceof DOMStoreReadTransaction);
44
45     }
46
47     @SuppressWarnings("resource")
48     @Test
49     public void testNewReadWriteTransaction() throws Exception {
50         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newReadWriteTransaction();
51         Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction);
52
53     }
54
55     @SuppressWarnings("resource")
56     @Test
57     public void testNewWriteOnlyTransaction() throws Exception {
58         DOMStoreTransaction dst = new TransactionChainProxy(actorContext).newWriteOnlyTransaction();
59         Assert.assertTrue(dst instanceof DOMStoreWriteTransaction);
60
61     }
62
63     @Test
64     public void testClose() throws Exception {
65         ActorContext context = mock(ActorContext.class);
66
67         new TransactionChainProxy(context).close();
68
69         verify(context, times(1)).broadcast(anyObject());
70     }
71
72     @Test
73     public void testTransactionChainsHaveUniqueId(){
74         TransactionChainProxy one = new TransactionChainProxy(mock(ActorContext.class));
75         TransactionChainProxy two = new TransactionChainProxy(mock(ActorContext.class));
76
77         Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId());
78     }
79 }