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;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
14 import org.junit.Test;
15 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
16 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
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 import org.opendaylight.yangtools.yang.common.RpcResult;
26 * FIXME: THis test should be moved to sal-binding-broker and rewriten
27 * to use new DataBroker API
29 public class ConcurrentImplicitCreateTest extends AbstractDataServiceTest {
31 private static final TopLevelListKey FOO_KEY = new TopLevelListKey("foo");
32 private static final TopLevelListKey BAR_KEY = new TopLevelListKey("bar");
33 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.builder(Top.class).build();
34 private static final InstanceIdentifier<TopLevelList> FOO_PATH = TOP_PATH.child(TopLevelList.class, FOO_KEY);
35 private static final InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, BAR_KEY);
38 public void testConcurrentCreate() throws InterruptedException, ExecutionException {
40 DataModificationTransaction fooTx = baDataService.beginTransaction();
41 DataModificationTransaction barTx = baDataService.beginTransaction();
43 fooTx.putOperationalData(FOO_PATH, new TopLevelListBuilder().setKey(FOO_KEY).build());
44 barTx.putOperationalData(BAR_PATH, new TopLevelListBuilder().setKey(BAR_KEY).build());
46 Future<RpcResult<TransactionStatus>> fooFuture = fooTx.commit();
47 Future<RpcResult<TransactionStatus>> barFuture = barTx.commit();
49 RpcResult<TransactionStatus> fooResult = fooFuture.get();
50 RpcResult<TransactionStatus> barResult = barFuture.get();
52 assertTrue(fooResult.isSuccessful());
53 assertTrue(barResult.isSuccessful());
55 assertEquals(TransactionStatus.COMMITED, fooResult.getResult());
56 assertEquals(TransactionStatus.COMMITED, barResult.getResult());