Bug 2682 - Switch sal-binding-dom-it to sal-test-model
[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.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.opendaylight.yangtools.yang.common.RpcResult;
26
27 /*
28  * FIXME: THis test should be moved to sal-binding-broker and rewriten
29  * to use new DataBroker API
30  */
31 @SuppressWarnings("deprecation")
32 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
33
34     private static final TopLevelListKey FOO_KEY = new TopLevelListKey("foo");
35     private static final TopLevelListKey BAR_KEY = new TopLevelListKey("bar");
36     private static InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.builder(Top.class).build();
37     private static InstanceIdentifier<TopLevelList> FOO_PATH = TOP_PATH.child(TopLevelList.class, FOO_KEY);
38     private static InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, BAR_KEY);
39
40     @Test
41     public void testConcurrentCreate() throws InterruptedException, ExecutionException {
42
43         DataModificationTransaction fooTx = baDataService.beginTransaction();
44         DataModificationTransaction barTx = baDataService.beginTransaction();
45
46         fooTx.putOperationalData(FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
47         barTx.putOperationalData(BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
48
49         Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
50         Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
51
52         RpcResult<TransactionStatus> fooResult = fooFuture.get();
53         RpcResult<TransactionStatus> barResult = barFuture.get();
54
55         assertTrue(fooResult.isSuccessful());
56         assertTrue(barResult.isSuccessful());
57
58         assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
59         assertEquals(TransactionStatus.COMMITED, barResult.getResult());
60
61     }
62 }

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