Bug 8568: Convert sal-binding-dom-it tests to use DataBroker
[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 java.util.concurrent.ExecutionException;
11 import java.util.concurrent.TimeUnit;
12 import java.util.concurrent.TimeoutException;
13 import org.junit.Test;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23
24 /**
25  * FIXME: THis test should be moved to sal-binding-broker and rewriten
26  * to use new DataBroker API
27  */
28 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
29
30     private static final TopLevelListKey FOO_KEY = new TopLevelListKey("foo");
31     private static final TopLevelListKey BAR_KEY = new TopLevelListKey("bar");
32     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.builder(Top.class).build();
33     private static final InstanceIdentifier<TopLevelList> FOO_PATH = TOP_PATH.child(TopLevelList.class, FOO_KEY);
34     private static final InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, BAR_KEY);
35
36     @Test
37     public void testConcurrentCreate() throws InterruptedException, ExecutionException, TimeoutException {
38
39         DataBroker dataBroker = testContext.getDataBroker();
40         WriteTransaction fooTx = dataBroker.newWriteOnlyTransaction();
41         WriteTransaction barTx = dataBroker.newWriteOnlyTransaction();
42
43         fooTx.put(LogicalDatastoreType.OPERATIONAL, FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
44         barTx.put(LogicalDatastoreType.OPERATIONAL, BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
45
46         fooTx.submit().get(5, TimeUnit.SECONDS);
47         barTx.submit().get(5, TimeUnit.SECONDS);
48     }
49 }