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.spi.shard;
10 import static org.junit.Assert.assertNull;
11 import static org.mockito.Mockito.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14 import static org.opendaylight.mdsal.dom.spi.shard.TestUtils.DOM_DATA_TREE_IDENTIFIER;
15 import static org.opendaylight.mdsal.dom.spi.shard.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
16 import static org.opendaylight.mdsal.dom.spi.shard.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
17 import static org.opendaylight.mdsal.dom.spi.shard.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
18 import static org.opendaylight.mdsal.dom.spi.shard.TestUtils.resetMocks;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
24 public class ForeignShardThreePhaseCommitCohortTest {
26 public void setUp() throws Exception {
27 doNothing().when(DOM_DATA_TREE_WRITE_CURSOR).close();
31 public void basicTest() throws Exception {
32 final ForeignShardModificationContext foreignShardModificationContext =
33 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
34 doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
35 doReturn(DOM_DATA_TREE_WRITE_CURSOR)
36 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
37 doNothing().when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).ready();
39 foreignShardModificationContext.getCursor();
40 foreignShardModificationContext.ready();
41 final ForeignShardThreePhaseCommitCohort foreignShardThreePhaseCommitCohort =
42 new ForeignShardThreePhaseCommitCohort(DOM_DATA_TREE_IDENTIFIER, foreignShardModificationContext);
44 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
45 foreignShardThreePhaseCommitCohort.preCommit();
46 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
48 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
49 foreignShardThreePhaseCommitCohort.canCommit();
50 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
52 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
53 foreignShardThreePhaseCommitCohort.commit();
54 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
56 assertNull(foreignShardThreePhaseCommitCohort.abort().get());