2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.data;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import java.util.concurrent.ExecutionException;
14 import java.util.concurrent.Future;
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;
28 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
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 = InstanceIdentifier.builder(NODES_PATH)
34 .child(Node.class, NODE_FOO_KEY).build();
35 private static InstanceIdentifier<Node> NODE_BAR_PATH = InstanceIdentifier.builder(NODES_PATH)
36 .child(Node.class, NODE_FOO_KEY).build();
39 public void testConcurrentCreate() throws InterruptedException, ExecutionException {
41 DataModificationTransaction fooTx = baDataService.beginTransaction();
42 DataModificationTransaction barTx = baDataService.beginTransaction();
44 fooTx.putOperationalData(NODE_FOO_PATH, new NodeBuilder().setKey(NODE_FOO_KEY).build());
45 barTx.putOperationalData(NODE_BAR_PATH, new NodeBuilder().setKey(NODE_BAR_KEY).build());
47 Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
48 Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
50 RpcResult<TransactionStatus> fooResult = fooFuture.get();
51 RpcResult<TransactionStatus> barResult = barFuture.get();
53 assertTrue(fooResult.isSuccessful());
54 assertTrue(barResult.isSuccessful());
56 assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
57 assertEquals(TransactionStatus.COMMITED, barResult.getResult());