2 * Copyright (c) 2016 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.mdsal.dom.store.inmemory;
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.doThrow;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.verify;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.COHORTS;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_STORE_THREE_PHASE_COMMIT_COHORT;
19 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.LISTENABLE_FUTURE;
20 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
27 public class ShardCommitCoordinationTaskTest {
29 final InmemoryDOMDataTreeShardWriteTransaction mockTx = mock(InmemoryDOMDataTreeShardWriteTransaction.class);
32 public void setUp() throws Exception {
33 doReturn("MockedTx").when(mockTx).toString();
34 doNothing().when(mockTx).transactionCommited(any());
38 public void basicTest() throws Exception {
39 doReturn(Void.TYPE).when(LISTENABLE_FUTURE).get();
40 doReturn(LISTENABLE_FUTURE).when(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
42 COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
44 ShardCommitCoordinationTask shardCommitCoordinationTask =
45 new ShardCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS, mockTx);
47 shardCommitCoordinationTask.call();
48 verify(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
51 @Test(expected = TransactionCommitFailedException.class)
52 public void exceptionCallTest() throws Exception {
53 doThrow(new InterruptedException()).when(LISTENABLE_FUTURE).get();
54 doReturn(LISTENABLE_FUTURE).when(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
56 COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
57 ShardCommitCoordinationTask shardCommitCoordinationTask =
58 new ShardCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS, mockTx);
59 shardCommitCoordinationTask.call();