058968c33992d27dc10e88cc0c76229dedd5d128
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / TransactionContextWrapperTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.mockito.MockitoAnnotations;
19 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
20
21 public class TransactionContextWrapperTest {
22     @Mock
23     private ActorContext actorContext;
24
25     @Mock
26     private TransactionContext transactionContext;
27
28     private TransactionContextWrapper transactionContextWrapper;
29
30     @Before
31     public void setUp() {
32         MockitoAnnotations.initMocks(this);
33         doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
34         transactionContextWrapper = new TransactionContextWrapper(MockIdentifiers.transactionIdentifier(
35             TransactionContextWrapperTest.class, "mock"), actorContext);
36     }
37
38     @Test
39     public void testExecutePriorTransactionOperations() {
40         for (int i = 0; i < 100; i++) {
41             transactionContextWrapper.maybeExecuteTransactionOperation(mock(TransactionOperation.class));
42         }
43         assertEquals(901, transactionContextWrapper.getLimiter().availablePermits());
44
45         transactionContextWrapper.executePriorTransactionOperations(transactionContext);
46
47         assertEquals(1001, transactionContextWrapper.getLimiter().availablePermits());
48     }
49 }

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