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.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.verify;
13 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_IDENTIFIER;
14 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_PRODUCER;
15 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
19 import org.junit.After;
20 import org.junit.Test;
22 public class ForeignShardThreePhaseCommitCohortTest {
25 public void basicTest() throws Exception {
26 final ForeignShardModificationContext foreignShardModificationContext =
27 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
28 doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
29 doReturn(DOM_DATA_TREE_WRITE_CURSOR)
30 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
31 foreignShardModificationContext.getCursor();
33 final ForeignShardThreePhaseCommitCohort foreignShardThreePhaseCommitCohort =
34 new ForeignShardThreePhaseCommitCohort(DOM_DATA_TREE_IDENTIFIER, foreignShardModificationContext);
36 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
37 foreignShardThreePhaseCommitCohort.preCommit();
38 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
40 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
41 foreignShardThreePhaseCommitCohort.canCommit();
42 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
44 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
45 foreignShardThreePhaseCommitCohort.commit();
46 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
48 assertEquals(null, foreignShardThreePhaseCommitCohort.abort().get());