2 * Copyright (c) 2014 Brocade Communications 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.cluster.datastore;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertSame;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
15 import static org.mockito.Mockito.doAnswer;
16 import static org.mockito.Mockito.doReturn;
17 import static org.mockito.Mockito.inOrder;
18 import static org.mockito.Mockito.mock;
19 import static org.mockito.Mockito.never;
20 import static org.mockito.Mockito.times;
21 import static org.mockito.Mockito.verify;
22 import com.google.common.collect.ImmutableMap;
23 import com.google.common.util.concurrent.CheckedFuture;
24 import com.google.common.util.concurrent.FutureCallback;
25 import com.google.common.util.concurrent.Futures;
26 import com.google.common.util.concurrent.ListenableFuture;
27 import com.google.common.util.concurrent.MoreExecutors;
28 import com.google.common.util.concurrent.SettableFuture;
29 import com.google.common.util.concurrent.Uninterruptibles;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collection;
33 import java.util.List;
34 import java.util.concurrent.CountDownLatch;
35 import java.util.concurrent.ExecutionException;
36 import java.util.concurrent.SynchronousQueue;
37 import java.util.concurrent.ThreadPoolExecutor;
38 import java.util.concurrent.TimeUnit;
39 import java.util.concurrent.TimeoutException;
40 import java.util.concurrent.atomic.AtomicReference;
41 import org.junit.After;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.mockito.InOrder;
45 import org.mockito.invocation.InvocationOnMock;
46 import org.mockito.stubbing.Answer;
47 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
48 import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException;
49 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
50 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
51 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
52 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
53 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
54 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
55 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
56 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
57 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
58 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
59 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
60 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
61 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
62 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
63 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
64 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
67 * Unit tests for DOMConcurrentDataCommitCoordinator.
69 * @author Thomas Pantelis
71 public class ConcurrentDOMDataBrokerTest {
73 private final DOMDataWriteTransaction transaction = mock(DOMDataWriteTransaction.class);
74 private final DOMStoreThreePhaseCommitCohort mockCohort1 = mock(DOMStoreThreePhaseCommitCohort.class);
75 private final DOMStoreThreePhaseCommitCohort mockCohort2 = mock(DOMStoreThreePhaseCommitCohort.class);
76 private final ThreadPoolExecutor futureExecutor =
77 new ThreadPoolExecutor(0, 1, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
78 private ConcurrentDOMDataBroker coordinator;
82 doReturn("tx").when(transaction).getIdentifier();
84 DOMStore store = new InMemoryDOMDataStore("OPER",
85 MoreExecutors.newDirectExecutorService());
87 coordinator = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, store), futureExecutor);
91 public void tearDown() {
92 futureExecutor.shutdownNow();
96 public void testSuccessfulSubmitAsync() throws Throwable {
97 testSuccessfulSubmit(true);
101 public void testSuccessfulSubmitSync() throws Throwable {
102 testSuccessfulSubmit(false);
105 private void testSuccessfulSubmit(final boolean doAsync) throws Throwable {
106 final CountDownLatch asyncCanCommitContinue = new CountDownLatch(1);
107 Answer<ListenableFuture<Boolean>> asyncCanCommit = new Answer<ListenableFuture<Boolean>>() {
109 public ListenableFuture<Boolean> answer(final InvocationOnMock invocation) {
110 final SettableFuture<Boolean> future = SettableFuture.create();
115 Uninterruptibles.awaitUninterruptibly(asyncCanCommitContinue,
116 10, TimeUnit.SECONDS);
128 doAnswer(asyncCanCommit).when(mockCohort1).canCommit();
129 doReturn(Futures.immediateFuture(null)).when(mockCohort1).preCommit();
130 doReturn(Futures.immediateFuture(null)).when(mockCohort1).commit();
132 doReturn(Futures.immediateFuture(true)).when(mockCohort2).canCommit();
133 doReturn(Futures.immediateFuture(null)).when(mockCohort2).preCommit();
134 doReturn(Futures.immediateFuture(null)).when(mockCohort2).commit();
136 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
137 transaction, Arrays.asList(mockCohort1, mockCohort2));
139 final CountDownLatch doneLatch = new CountDownLatch(1);
140 final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
141 Futures.addCallback(future, new FutureCallback<Void>() {
143 public void onSuccess(final Void result) {
144 doneLatch.countDown();
148 public void onFailure(final Throwable t) {
150 doneLatch.countDown();
154 asyncCanCommitContinue.countDown();
156 assertEquals("Submit complete", true, doneLatch.await(5, TimeUnit.SECONDS));
158 if(caughtEx.get() != null) {
159 throw caughtEx.get();
162 assertEquals("Task count", doAsync ? 1 : 0, futureExecutor.getTaskCount());
164 InOrder inOrder = inOrder(mockCohort1, mockCohort2);
165 inOrder.verify(mockCohort1).canCommit();
166 inOrder.verify(mockCohort2).canCommit();
167 inOrder.verify(mockCohort1).preCommit();
168 inOrder.verify(mockCohort2).preCommit();
169 inOrder.verify(mockCohort1).commit();
170 inOrder.verify(mockCohort2).commit();
174 public void testSubmitWithNegativeCanCommitResponse() throws Exception {
175 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
176 doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
178 doReturn(Futures.immediateFuture(false)).when(mockCohort2).canCommit();
179 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
181 DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
182 doReturn(Futures.immediateFuture(false)).when(mockCohort3).canCommit();
183 doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
185 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
186 transaction, Arrays.asList(mockCohort1, mockCohort2, mockCohort3));
188 assertFailure(future, null, mockCohort1, mockCohort2, mockCohort3);
191 private static void assertFailure(final CheckedFuture<Void, TransactionCommitFailedException> future,
192 final Exception expCause, final DOMStoreThreePhaseCommitCohort... mockCohorts)
195 future.checkedGet(5, TimeUnit.SECONDS);
196 fail("Expected TransactionCommitFailedException");
197 } catch (TransactionCommitFailedException e) {
198 if(expCause != null) {
199 assertSame("Expected cause", expCause.getClass(), e.getCause().getClass());
202 InOrder inOrder = inOrder((Object[])mockCohorts);
203 for(DOMStoreThreePhaseCommitCohort c: mockCohorts) {
204 inOrder.verify(c).abort();
206 } catch (TimeoutException e) {
212 public void testSubmitWithCanCommitException() throws Exception {
213 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
214 doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
216 IllegalStateException cause = new IllegalStateException("mock");
217 doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).canCommit();
218 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
220 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
221 transaction, Arrays.asList(mockCohort1, mockCohort2));
223 assertFailure(future, cause, mockCohort1, mockCohort2);
227 public void testSubmitWithCanCommitDataStoreUnavailableException() throws Exception {
228 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
229 doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
230 NoShardLeaderException rootCause = new NoShardLeaderException("mock");
231 DataStoreUnavailableException cause = new DataStoreUnavailableException(rootCause.getMessage(), rootCause);
232 doReturn(Futures.immediateFailedFuture(rootCause)).when(mockCohort2).canCommit();
233 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
235 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
236 transaction, Arrays.asList(mockCohort1, mockCohort2));
238 assertFailure(future, cause, mockCohort1, mockCohort2);
242 public void testSubmitWithPreCommitException() throws Exception {
243 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
244 doReturn(Futures.immediateFuture(null)).when(mockCohort1).preCommit();
245 doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
247 doReturn(Futures.immediateFuture(true)).when(mockCohort2).canCommit();
248 IllegalStateException cause = new IllegalStateException("mock");
249 doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).preCommit();
250 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
252 DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
253 doReturn(Futures.immediateFuture(true)).when(mockCohort3).canCommit();
254 doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2"))).
255 when(mockCohort3).preCommit();
256 doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
258 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
259 transaction, Arrays.asList(mockCohort1, mockCohort2, mockCohort3));
261 assertFailure(future, cause, mockCohort1, mockCohort2, mockCohort3);
265 public void testSubmitWithCommitException() throws Exception {
266 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
267 doReturn(Futures.immediateFuture(null)).when(mockCohort1).preCommit();
268 doReturn(Futures.immediateFuture(null)).when(mockCohort1).commit();
269 doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
271 doReturn(Futures.immediateFuture(true)).when(mockCohort2).canCommit();
272 doReturn(Futures.immediateFuture(null)).when(mockCohort2).preCommit();
273 IllegalStateException cause = new IllegalStateException("mock");
274 doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).commit();
275 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
277 DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
278 doReturn(Futures.immediateFuture(true)).when(mockCohort3).canCommit();
279 doReturn(Futures.immediateFuture(null)).when(mockCohort3).preCommit();
280 doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2"))).
281 when(mockCohort3).commit();
282 doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
284 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
285 transaction, Arrays.asList(mockCohort1, mockCohort2, mockCohort3));
287 assertFailure(future, cause, mockCohort1, mockCohort2, mockCohort3);
291 public void testSubmitWithAbortException() throws Exception {
292 doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
293 doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock abort error"))).
294 when(mockCohort1).abort();
296 IllegalStateException cause = new IllegalStateException("mock canCommit error");
297 doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).canCommit();
298 doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
300 CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
301 transaction, Arrays.asList(mockCohort1, mockCohort2));
303 assertFailure(future, cause, mockCohort1, mockCohort2);
307 public void testCreateReadWriteTransaction(){
308 DOMStore domStore = mock(DOMStore.class);
309 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
310 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
312 dataBroker.newReadWriteTransaction();
314 verify(domStore, never()).newReadWriteTransaction();
319 public void testCreateWriteOnlyTransaction(){
320 DOMStore domStore = mock(DOMStore.class);
321 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
322 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
324 dataBroker.newWriteOnlyTransaction();
326 verify(domStore, never()).newWriteOnlyTransaction();
331 public void testCreateReadOnlyTransaction(){
332 DOMStore domStore = mock(DOMStore.class);
333 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
334 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
336 dataBroker.newReadOnlyTransaction();
338 verify(domStore, never()).newReadOnlyTransaction();
343 public void testLazySubTransactionCreationForReadWriteTransactions(){
344 DOMStore configDomStore = mock(DOMStore.class);
345 DOMStore operationalDomStore = mock(DOMStore.class);
346 DOMStoreReadWriteTransaction storeTxn = mock(DOMStoreReadWriteTransaction.class);
348 doReturn(storeTxn).when(operationalDomStore).newReadWriteTransaction();
349 doReturn(storeTxn).when(configDomStore).newReadWriteTransaction();
351 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
352 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
353 configDomStore), futureExecutor)) {
354 DOMDataReadWriteTransaction dataTxn = dataBroker.newReadWriteTransaction();
356 dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
357 dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
358 dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build());
360 verify(configDomStore, never()).newReadWriteTransaction();
361 verify(operationalDomStore, times(1)).newReadWriteTransaction();
363 dataTxn.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
365 verify(configDomStore, times(1)).newReadWriteTransaction();
366 verify(operationalDomStore, times(1)).newReadWriteTransaction();
372 public void testLazySubTransactionCreationForWriteOnlyTransactions(){
373 DOMStore configDomStore = mock(DOMStore.class);
374 DOMStore operationalDomStore = mock(DOMStore.class);
375 DOMStoreWriteTransaction storeTxn = mock(DOMStoreWriteTransaction.class);
377 doReturn(storeTxn).when(operationalDomStore).newWriteOnlyTransaction();
378 doReturn(storeTxn).when(configDomStore).newWriteOnlyTransaction();
380 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
381 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
382 configDomStore), futureExecutor)) {
383 DOMDataWriteTransaction dataTxn = dataBroker.newWriteOnlyTransaction();
385 dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
386 dataTxn.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
388 verify(configDomStore, never()).newWriteOnlyTransaction();
389 verify(operationalDomStore, times(1)).newWriteOnlyTransaction();
391 dataTxn.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
393 verify(configDomStore, times(1)).newWriteOnlyTransaction();
394 verify(operationalDomStore, times(1)).newWriteOnlyTransaction();
399 public void testLazySubTransactionCreationForReadOnlyTransactions(){
400 DOMStore configDomStore = mock(DOMStore.class);
401 DOMStore operationalDomStore = mock(DOMStore.class);
402 DOMStoreReadTransaction storeTxn = mock(DOMStoreReadTransaction.class);
404 doReturn(storeTxn).when(operationalDomStore).newReadOnlyTransaction();
405 doReturn(storeTxn).when(configDomStore).newReadOnlyTransaction();
407 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
408 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
409 configDomStore), futureExecutor)) {
410 DOMDataReadOnlyTransaction dataTxn = dataBroker.newReadOnlyTransaction();
412 dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build());
413 dataTxn.read(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build());
415 verify(configDomStore, never()).newReadOnlyTransaction();
416 verify(operationalDomStore, times(1)).newReadOnlyTransaction();
418 dataTxn.read(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.builder().build());
420 verify(configDomStore, times(1)).newReadOnlyTransaction();
421 verify(operationalDomStore, times(1)).newReadOnlyTransaction();
426 public void testSubmitWithOnlyOneSubTransaction() throws InterruptedException {
427 DOMStore configDomStore = mock(DOMStore.class);
428 DOMStore operationalDomStore = mock(DOMStore.class);
429 DOMStoreReadWriteTransaction mockStoreReadWriteTransaction = mock(DOMStoreReadWriteTransaction.class);
430 DOMStoreThreePhaseCommitCohort mockCohort = mock(DOMStoreThreePhaseCommitCohort.class);
432 doReturn(mockStoreReadWriteTransaction).when(operationalDomStore).newReadWriteTransaction();
433 doReturn(mockCohort).when(mockStoreReadWriteTransaction).ready();
434 doReturn(Futures.immediateFuture(false)).when(mockCohort).canCommit();
435 doReturn(Futures.immediateFuture(null)).when(mockCohort).abort();
437 final CountDownLatch latch = new CountDownLatch(1);
438 final List<DOMStoreThreePhaseCommitCohort> commitCohorts = new ArrayList<>();
440 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
441 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
442 configDomStore), futureExecutor) {
444 public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
445 commitCohorts.addAll(cohorts);
447 return super.submit(transaction, cohorts);
450 DOMDataReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
452 domDataReadWriteTransaction.delete(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build());
454 domDataReadWriteTransaction.submit();
456 latch.await(10, TimeUnit.SECONDS);
458 assertTrue(commitCohorts.size() == 1);
463 public void testSubmitWithOnlyTwoSubTransactions() throws InterruptedException {
464 DOMStore configDomStore = mock(DOMStore.class);
465 DOMStore operationalDomStore = mock(DOMStore.class);
466 DOMStoreReadWriteTransaction operationalTransaction = mock(DOMStoreReadWriteTransaction.class);
467 DOMStoreReadWriteTransaction configTransaction = mock(DOMStoreReadWriteTransaction.class);
468 DOMStoreThreePhaseCommitCohort mockCohortOperational = mock(DOMStoreThreePhaseCommitCohort.class);
469 DOMStoreThreePhaseCommitCohort mockCohortConfig = mock(DOMStoreThreePhaseCommitCohort.class);
471 doReturn(operationalTransaction).when(operationalDomStore).newReadWriteTransaction();
472 doReturn(configTransaction).when(configDomStore).newReadWriteTransaction();
474 doReturn(mockCohortOperational).when(operationalTransaction).ready();
475 doReturn(Futures.immediateFuture(false)).when(mockCohortOperational).canCommit();
476 doReturn(Futures.immediateFuture(null)).when(mockCohortOperational).abort();
478 doReturn(mockCohortConfig).when(configTransaction).ready();
479 doReturn(Futures.immediateFuture(false)).when(mockCohortConfig).canCommit();
480 doReturn(Futures.immediateFuture(null)).when(mockCohortConfig).abort();
482 final CountDownLatch latch = new CountDownLatch(1);
483 final List<DOMStoreThreePhaseCommitCohort> commitCohorts = new ArrayList<>();
485 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
486 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
487 configDomStore), futureExecutor) {
489 public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
490 commitCohorts.addAll(cohorts);
492 return super.submit(transaction, cohorts);
495 DOMDataReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
497 domDataReadWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
498 domDataReadWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
500 domDataReadWriteTransaction.submit();
502 latch.await(10, TimeUnit.SECONDS);
504 assertTrue(commitCohorts.size() == 2);
509 public void testCreateTransactionChain(){
510 DOMStore domStore = mock(DOMStore.class);
511 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
512 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
515 dataBroker.createTransactionChain(mock(TransactionChainListener.class));
517 verify(domStore, times(2)).createTransactionChain();
523 public void testCreateTransactionOnChain(){
524 DOMStore domStore = mock(DOMStore.class);
525 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
526 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
529 DOMStoreReadWriteTransaction operationalTransaction = mock(DOMStoreReadWriteTransaction.class);
530 DOMStoreTransactionChain mockChain = mock(DOMStoreTransactionChain.class);
532 doReturn(mockChain).when(domStore).createTransactionChain();
533 doReturn(operationalTransaction).when(mockChain).newWriteOnlyTransaction();
535 DOMTransactionChain transactionChain = dataBroker.createTransactionChain(mock(TransactionChainListener.class));
537 DOMDataWriteTransaction domDataWriteTransaction = transactionChain.newWriteOnlyTransaction();
539 verify(mockChain, never()).newWriteOnlyTransaction();
541 domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().build(), mock(NormalizedNode.class));
546 public void testEmptyTransactionSubmitSucceeds() throws ExecutionException, InterruptedException {
547 DOMStore domStore = mock(DOMStore.class);
548 try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
549 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
552 CheckedFuture<Void, TransactionCommitFailedException> submit1 = dataBroker.newWriteOnlyTransaction().submit();
554 assertNotNull(submit1);
558 CheckedFuture<Void, TransactionCommitFailedException> submit2 = dataBroker.newReadWriteTransaction().submit();
560 assertNotNull(submit2);