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.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;
28 * FIXME: THis test should be moved to sal-binding-broker and rewriten
29 * to use new DataBroker API
31 @SuppressWarnings("deprecation")
32 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
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);
41 public void testConcurrentCreate() throws InterruptedException, ExecutionException {
43 DataModificationTransaction fooTx = baDataService.beginTransaction();
44 DataModificationTransaction barTx = baDataService.beginTransaction();
46 fooTx.putOperationalData(FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
47 barTx.putOperationalData(BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
49 Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
50 Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
52 RpcResult<TransactionStatus> fooResult = fooFuture.get();
53 RpcResult<TransactionStatus> barResult = barFuture.get();
55 assertTrue(fooResult.isSuccessful());
56 assertTrue(barResult.isSuccessful());
58 assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
59 assertEquals(TransactionStatus.COMMITED, barResult.getResult());