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.dom.spi.store.DOMStoreThreePhaseCommitCohort;
14 public enum TestCommitCohort implements DOMStoreThreePhaseCommitCohort {
17 ALLWAYS_SUCCESS(true, true, true, true), CAN_COMMIT_FAILED(false, false, false, true), PRE_COMMIT_FAILED(true,
18 false, false, true), COMMIT_FAILED(true, true, false, true);
21 TestCommitCohort(final boolean canCommit, final boolean preCommit,
22 final boolean commit, final boolean abort) {
23 this.canCommit = Futures.immediateFuture(canCommit);
24 this.preCommit = immediate(canCommit, new IllegalStateException());
25 this.commit = immediate(commit, new IllegalStateException());
26 this.abort = immediate(abort, new IllegalStateException());
30 private final ListenableFuture<Boolean> canCommit;
31 private final ListenableFuture<Void> preCommit;
32 private final ListenableFuture<Void> commit;
33 private final ListenableFuture<Void> abort;
36 public ListenableFuture<Boolean> canCommit() {
41 public ListenableFuture<Void> preCommit() {
46 public ListenableFuture<Void> abort() {
51 public ListenableFuture<Void> commit() {
55 private static ListenableFuture<Void> immediate(final boolean isSuccess, final Exception except) {
56 return isSuccess ? Futures.<Void>immediateFuture(null) : Futures.<Void>immediateFailedFuture(except);