Prevent ConfigPusher from killing its thread
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / DummyFuture.java
1 package org.opendaylight.controller.sal.restconf.impl.test;
2
3 import java.util.concurrent.*;
4
5 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
6 import org.opendaylight.yangtools.yang.common.RpcResult;
7
8 public class DummyFuture implements Future<RpcResult<TransactionStatus>> {
9     
10     private final boolean cancel;
11     private final boolean isCancelled;
12     private final boolean isDone;
13     private final RpcResult<TransactionStatus> result;
14     
15     public DummyFuture() {
16         cancel = false;
17         isCancelled = false;
18         isDone = false;
19         result = null;
20     }
21     
22     private DummyFuture(Builder builder) {
23         cancel = builder.cancel;
24         isCancelled = builder.isCancelled;
25         isDone = builder.isDone;
26         result = builder.result;
27     }
28     
29     public static Builder builder() {
30         return new DummyFuture.Builder();
31     }
32
33     @Override
34     public boolean cancel(boolean mayInterruptIfRunning) {
35         return cancel;
36     }
37
38     @Override
39     public boolean isCancelled() {
40         return isCancelled;
41     }
42
43     @Override
44     public boolean isDone() {
45         return isDone;
46     }
47
48     @Override
49     public RpcResult<TransactionStatus> get() throws InterruptedException, ExecutionException {
50         return result;
51     }
52
53     @Override
54     public RpcResult<TransactionStatus> get(long timeout, TimeUnit unit) throws InterruptedException,
55             ExecutionException, TimeoutException {
56         return result;
57     }
58     
59     public static class Builder {
60         
61         private boolean cancel;
62         private boolean isCancelled;
63         private boolean isDone;
64         private RpcResult<TransactionStatus> result;
65
66         public Builder cancel(boolean cancel) {
67             this.cancel = cancel;
68             return this;
69         }
70         
71         public Builder isCancelled(boolean isCancelled) {
72             this.isCancelled = isCancelled;
73             return this;
74         }
75         
76         public Builder isDone(boolean isDone) {
77             this.isDone = isDone;
78             return this;
79         }
80         
81         public Builder rpcResult(RpcResult<TransactionStatus> result) {
82             this.result = result;
83             return this;
84         }
85         
86         public Future<RpcResult<TransactionStatus>> build() {
87             return new DummyFuture(this);
88         }
89     }
90 }