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.doNothing;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
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_DATA_TREE_SHARD_PRODUCER;
16 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION;
17 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.DOM_DATA_TREE_WRITE_CURSOR;
18 import static org.opendaylight.mdsal.dom.store.inmemory.TestUtils.resetMocks;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.mdsal.dom.spi.shard.ForeignShardModificationContext;
25 public class ForeignShardThreePhaseCommitCohortTest {
28 public void setUp() throws Exception {
29 doNothing().when(DOM_DATA_TREE_WRITE_CURSOR).close();
33 public void basicTest() throws Exception {
34 final ForeignShardModificationContext foreignShardModificationContext =
35 new ForeignShardModificationContext(DOM_DATA_TREE_IDENTIFIER, DOM_DATA_TREE_SHARD_PRODUCER);
36 doReturn(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).when(DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
37 doReturn(DOM_DATA_TREE_WRITE_CURSOR)
38 .when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(DOM_DATA_TREE_IDENTIFIER);
39 doNothing().when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).ready();
41 foreignShardModificationContext.getCursor();
42 foreignShardModificationContext.ready();
43 final ForeignShardThreePhaseCommitCohort foreignShardThreePhaseCommitCohort =
44 new ForeignShardThreePhaseCommitCohort(DOM_DATA_TREE_IDENTIFIER, foreignShardModificationContext);
46 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
47 foreignShardThreePhaseCommitCohort.preCommit();
48 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
50 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
51 foreignShardThreePhaseCommitCohort.canCommit();
52 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
54 doReturn(null).when(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
55 foreignShardThreePhaseCommitCohort.commit();
56 verify(DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
58 assertEquals(null, foreignShardThreePhaseCommitCohort.abort().get());