use of org.opendaylight.mdsal.dom.api.DOMTransactionChainListener in project controller by opendaylight.
the class AbstractDistributedDataStoreIntegrationTest method testCreateChainedTransactionsInQuickSuccession.
@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
final DOMTransactionChainListener listener = Mockito.mock(DOMTransactionChainListener.class);
DOMTransactionChain txChain = broker.createTransactionChain(listener);
final List<ListenableFuture<?>> futures = new ArrayList<>();
final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
futures.add(writeTx.commit());
int numCars = 100;
for (int i = 0; i < numCars; i++) {
final DOMDataTreeReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i), CarsModel.newCarEntry("car" + i, Uint64.valueOf(20000)));
futures.add(rwTx.commit());
}
for (final ListenableFuture<?> f : futures) {
f.get(5, TimeUnit.SECONDS);
}
final Optional<NormalizedNode> optional = txChain.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
assertTrue("isPresent", optional.isPresent());
assertEquals("# cars", numCars, ((Collection<?>) optional.get().body()).size());
txChain.close();
broker.close();
}
}
Aggregations