c5dbdcecae747b7f4930b0f0f1119ec753f941e3
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / md / sal / binding / data / ConcurrentImplicitCreateTest.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.md.sal.binding.data;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12
13 import java.util.concurrent.ExecutionException;
14 import java.util.concurrent.Future;
15
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
18 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
19 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.common.RpcResult;
27
28 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
29
30     private static final NodeKey NODE_FOO_KEY = new NodeKey(new NodeId("foo"));
31     private static final NodeKey NODE_BAR_KEY = new NodeKey(new NodeId("foo"));
32     private static InstanceIdentifier<Nodes> NODES_PATH = InstanceIdentifier.builder(Nodes.class).build();
33     private static InstanceIdentifier<Node> NODE_FOO_PATH = NODES_PATH.child(Node.class, NODE_FOO_KEY);
34     private static InstanceIdentifier<Node> NODE_BAR_PATH = NODES_PATH.child(Node.class, NODE_FOO_KEY);
35
36     @Test
37     public void testConcurrentCreate() throws InterruptedException, ExecutionException {
38
39         DataModificationTransaction fooTx = baDataService.beginTransaction();
40         DataModificationTransaction barTx = baDataService.beginTransaction();
41
42         fooTx.putOperationalData(NODE_FOO_PATH, new NodeBuilder().setKey(NODE_FOO_KEY).build());
43         barTx.putOperationalData(NODE_BAR_PATH, new NodeBuilder().setKey(NODE_BAR_KEY).build());
44
45         Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
46         Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
47
48         RpcResult<TransactionStatus> fooResult = fooFuture.get();
49         RpcResult<TransactionStatus> barResult = barFuture.get();
50
51         assertTrue(fooResult.isSuccessful());
52         assertTrue(barResult.isSuccessful());
53
54         assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
55         assertEquals(TransactionStatus.COMMITED, barResult.getResult());
56
57     }
58 }

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