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.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;
19 import org.junit.After;
20 import org.junit.Test;
21 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
23 public class ShardPreCommitCoordinationTaskTest {
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).preCommit();
30 COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
32 ShardPreCommitCoordinationTask shardPreCommitCoordinationTask =
33 new ShardPreCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS);
35 shardPreCommitCoordinationTask.call();
36 verify(DOM_STORE_THREE_PHASE_COMMIT_COHORT).preCommit();
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).preCommit();
44 COHORTS.add(DOM_STORE_THREE_PHASE_COMMIT_COHORT);
45 ShardPreCommitCoordinationTask shardPreCommitCoordinationTask =
46 new ShardPreCommitCoordinationTask(DOM_DATA_TREE_IDENTIFIER, COHORTS);
47 shardPreCommitCoordinationTask.call();