Bump to odlparent-9.0.0/yangtools-7.0.1-SNAPSHOT
[mdsal.git] / binding / mdsal-binding-test-utils / src / main / java / org / opendaylight / mdsal / binding / testutils / DataBrokerFailures.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.testutils;
9
10 import org.opendaylight.mdsal.binding.api.ReadTransaction;
11 import org.opendaylight.mdsal.binding.api.WriteTransaction;
12 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
13 import org.opendaylight.mdsal.common.api.ReadFailedException;
14 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16
17 /**
18  * Configures a DataBroker to simulate failures, useful for tests.
19  *
20  * @author Michael Vorburger.ch
21  */
22 public interface DataBrokerFailures {
23
24     /**
25      * Fails all future reads.
26      *
27      * @param exception a {@link ReadFailedException} to throw from a
28      *        {@link ReadTransaction#read(LogicalDatastoreType, InstanceIdentifier)} call.
29      */
30     void failReads(ReadFailedException exception);
31
32     /**
33      * Fails N future reads.
34      *
35      * @param howManyTimes how many times to throw the passed exception, until it resets.
36      *
37      * @param exception a {@link ReadFailedException} to throw from a
38      *        {@link ReadTransaction#read(LogicalDatastoreType, InstanceIdentifier)} call.
39      */
40     void failReads(int howManyTimes, ReadFailedException exception);
41
42     /**
43      * Fails all future Transaction commits.
44      *
45      * @param exception an Exception to throw from a {@link WriteTransaction#commit()} method.
46      */
47     void failCommits(TransactionCommitFailedException exception);
48
49     /**
50      * Fails N future Transaction commits.
51      *
52      * @param howManyTimes
53      *               how many times to throw the passed exception, until it resets
54      *
55      * @param exception an Exception to throw from a {@link WriteTransaction#commit()} method.
56      */
57     void failCommits(int howManyTimes, TransactionCommitFailedException exception);
58
59     /**
60      * To simulate scenarios where even though the transaction throws a
61      * TransactionCommitFailedException (caused by
62      * akka.pattern.AskTimeoutException) it eventually succeeds. These timeouts
63      * are typically seen in scaled cluster environments under load. The new
64      * tell-based protocol, which will soon be enabled by default (c/61002),
65      * adds internal retries for transactions, making the application not to
66      * handle such scenarios.
67      */
68     void failButCommitAnyway();
69
70     /**
71      * Resets any earlier {@link #failReads(ReadFailedException)} or {@link #failReads(int, ReadFailedException)}.
72      */
73     void unfailReads();
74
75     /**
76      * Resets any earlier {@link #failCommits(TransactionCommitFailedException)} or
77      * {@link #failCommits(int, TransactionCommitFailedException)}.
78      */
79     void unfailCommits();
80 }