24a2047b53eb25dd8071f5691a9c11233d2c96c8
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / ShardCommitCoordinationTaskTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.store.inmemory;
9
10 import static org.mockito.Mockito.doReturn;
11 import static org.mockito.Mockito.doThrow;
12 import static org.mockito.Mockito.verify;
13 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.COHORTS;
14 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
15 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_STORE_THREE_PHASE_COMMIT_COHORT;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.LISTENABLE_FUTURE;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
18
19 import org.junit.After;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
22
23 public class ShardCommitCoordinationTaskTest {
24
25     @Test
26     public void basicTest() throws Exception {
27         doReturn(Void.TYPE).when(LISTENABLE_FUTURE).get();
28         doReturn(LISTENABLE_FUTURE).when(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
29
30         COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
31
32         ShardCommitCoordinationTask shardCommitCoordinationTask =
33                 new ShardCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS);
34
35         shardCommitCoordinationTask.call();
36         verify(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
37     }
38
39     @Test(expected = TransactionCommitFailedException.class)
40     public void exceptionCallTest() throws Exception {
41         doThrow(new InterruptedException()).when(LISTENABLE_FUTURE).get();
42         doReturn(LISTENABLE_FUTURE).when(DOM_STORE_THREE_PHASE_COMMIT_COHORT).commit();
43
44         COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
45         ShardCommitCoordinationTask shardCommitCoordinationTask =
46                 new ShardCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS);
47         shardCommitCoordinationTask.call();
48     }
49
50     @After
51     public void reset() {
52         resetMocks();
53     }
54 }