2 * Copyright (c) 2015 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.broker;
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.mdsal.common.api.CommitInfo;
13 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
14 import org.opendaylight.yangtools.yang.common.Empty;
16 public enum TestCommitCohort implements DOMStoreThreePhaseCommitCohort {
17 ALLWAYS_SUCCESS(true, true, true, true),
18 CAN_COMMIT_FAILED(false, false, false, true),
19 PRE_COMMIT_FAILED(true, false, false, true),
20 COMMIT_FAILED(true, true, false, true);
22 private final ListenableFuture<Boolean> canCommit;
23 private final ListenableFuture<Empty> preCommit;
24 private final ListenableFuture<CommitInfo> commit;
25 private final ListenableFuture<Empty> abort;
27 TestCommitCohort(final boolean canCommit, final boolean preCommit,
28 final boolean commit, final boolean abort) {
29 this.canCommit = Futures.immediateFuture(canCommit);
30 this.preCommit = immediate(canCommit, new IllegalStateException());
31 this.commit = commit ? CommitInfo.emptyFluentFuture()
32 : Futures.immediateFailedFuture(new IllegalStateException());
33 this.abort = immediate(abort, new IllegalStateException());
38 public ListenableFuture<Boolean> canCommit() {
43 public ListenableFuture<Empty> preCommit() {
48 public ListenableFuture<Empty> abort() {
53 public ListenableFuture<CommitInfo> commit() {
57 private static ListenableFuture<Empty> immediate(final boolean isSuccess, final Exception except) {
58 return isSuccess ? Futures.immediateFuture(Empty.value()) : Futures.immediateFailedFuture(except);