Make testTransactionForwardedToLeaderAfterRetry purge-aware
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / AbstractShardTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, 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.controller.cluster.datastore;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14 import static org.mockito.Matchers.any;
15 import static org.mockito.Mockito.doAnswer;
16 import static org.mockito.Mockito.doReturn;
17 import static org.mockito.Mockito.mock;
18 import static org.opendaylight.controller.cluster.datastore.DataStoreVersions.CURRENT_VERSION;
19 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulCanCommit;
20 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulCommit;
21 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulPreCommit;
22
23 import akka.actor.ActorRef;
24 import akka.actor.PoisonPill;
25 import akka.actor.Props;
26 import akka.dispatch.Dispatchers;
27 import akka.japi.Creator;
28 import akka.pattern.Patterns;
29 import akka.testkit.TestActorRef;
30 import akka.util.Timeout;
31 import com.google.common.base.Optional;
32 import com.google.common.primitives.UnsignedLong;
33 import com.google.common.util.concurrent.FutureCallback;
34 import com.google.common.util.concurrent.Uninterruptibles;
35 import java.io.IOException;
36 import java.util.Collections;
37 import java.util.HashMap;
38 import java.util.Map;
39 import java.util.Set;
40 import java.util.concurrent.CountDownLatch;
41 import java.util.concurrent.ExecutionException;
42 import java.util.concurrent.TimeUnit;
43 import java.util.concurrent.TimeoutException;
44 import java.util.concurrent.atomic.AtomicInteger;
45 import org.junit.After;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.opendaylight.controller.cluster.access.concepts.MemberName;
49 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
50 import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder;
51 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
52 import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
53 import org.opendaylight.controller.cluster.datastore.messages.ForwardedReadyTransaction;
54 import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
55 import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification;
56 import org.opendaylight.controller.cluster.datastore.modification.WriteModification;
57 import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload;
58 import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot;
59 import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState;
60 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
61 import org.opendaylight.controller.cluster.raft.TestActorFactory;
62 import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
63 import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
64 import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
65 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
66 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
67 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
68 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
69 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
70 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
71 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
72 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
73 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
74 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
75 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
76 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
77 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
78 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
79 import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
80 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
81 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
82 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
83 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
84 import scala.concurrent.Await;
85 import scala.concurrent.Future;
86 import scala.concurrent.duration.Duration;
87
88 /**
89  * Abstract base for shard unit tests.
90  *
91  * @author Thomas Pantelis
92  */
93 public abstract class AbstractShardTest extends AbstractActorTest {
94     protected static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
95
96     private static final AtomicInteger NEXT_SHARD_NUM = new AtomicInteger();
97
98     protected static final int HEARTBEAT_MILLIS = 100;
99
100     protected final ShardIdentifier shardID = ShardIdentifier.create("inventory", MemberName.forName("member-1"),
101         "config" + NEXT_SHARD_NUM.getAndIncrement());
102
103     protected final Builder dataStoreContextBuilder = DatastoreContext.newBuilder()
104             .shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000)
105             .shardHeartbeatIntervalInMillis(HEARTBEAT_MILLIS);
106
107     protected final TestActorFactory actorFactory = new TestActorFactory(getSystem());
108
109     @Before
110     public void setUp() {
111         InMemorySnapshotStore.clear();
112         InMemoryJournal.clear();
113     }
114
115     @After
116     public void tearDown() {
117         InMemorySnapshotStore.clear();
118         InMemoryJournal.clear();
119         actorFactory.close();
120     }
121
122     protected DatastoreContext newDatastoreContext() {
123         return dataStoreContextBuilder.build();
124     }
125
126     protected Props newShardProps() {
127         return newShardBuilder().props();
128     }
129
130     protected Shard.Builder newShardBuilder() {
131         return Shard.builder().id(shardID).datastoreContext(newDatastoreContext())
132             .schemaContextProvider(() -> SCHEMA_CONTEXT);
133     }
134
135     protected void testRecovery(final Set<Integer> listEntryKeys) throws Exception {
136         // Create the actor and wait for recovery complete.
137
138         final int nListEntries = listEntryKeys.size();
139
140         final CountDownLatch recoveryComplete = new CountDownLatch(1);
141
142         final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {
143             @Override
144             protected void onRecoveryComplete() {
145                 try {
146                     super.onRecoveryComplete();
147                 } finally {
148                     recoveryComplete.countDown();
149                 }
150             }
151         };
152
153         final TestActorRef<Shard> shard = TestActorRef.create(getSystem(),
154                 Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
155                 "testRecovery");
156
157         assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
158
159         // Verify data in the data store.
160
161         final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
162         assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
163         assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable",
164                 outerList.getValue() instanceof Iterable);
165         for (final Object entry: (Iterable<?>) outerList.getValue()) {
166             assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode",
167                     entry instanceof MapEntryNode);
168             final MapEntryNode mapEntry = (MapEntryNode)entry;
169             final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf =
170                     mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
171             assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
172             final Object value = idLeaf.get().getValue();
173             assertTrue("Unexpected value for leaf " + TestModel.ID_QNAME.getLocalName() + ": " + value,
174                     listEntryKeys.remove(value));
175         }
176
177         if (!listEntryKeys.isEmpty()) {
178             fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " + listEntryKeys);
179         }
180
181         assertEquals("Last log index", nListEntries,
182                 shard.underlyingActor().getShardMBean().getLastLogIndex());
183         assertEquals("Commit index", nListEntries,
184                 shard.underlyingActor().getShardMBean().getCommitIndex());
185         assertEquals("Last applied", nListEntries,
186                 shard.underlyingActor().getShardMBean().getLastApplied());
187
188         shard.tell(PoisonPill.getInstance(), ActorRef.noSender());
189     }
190
191     protected void verifyLastApplied(final TestActorRef<Shard> shard, final long expectedValue) {
192         long lastApplied = -1;
193         for (int i = 0; i < 20 * 5; i++) {
194             lastApplied = shard.underlyingActor().getShardMBean().getLastApplied();
195             if (lastApplied == expectedValue) {
196                 return;
197             }
198             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
199         }
200
201         Assert.fail(String.format("Expected last applied: %d, Actual: %d", expectedValue, lastApplied));
202     }
203
204     protected TipProducingDataTree createDelegatingMockDataTree() throws Exception {
205         TipProducingDataTree actual = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
206         final TipProducingDataTree mock = mock(TipProducingDataTree.class);
207
208         doAnswer(invocation -> {
209             actual.validate(invocation.getArgumentAt(0, DataTreeModification.class));
210             return null;
211         }).when(mock).validate(any(DataTreeModification.class));
212
213         doAnswer(invocation -> {
214             return actual.prepare(invocation.getArgumentAt(0, DataTreeModification.class));
215         }).when(mock).prepare(any(DataTreeModification.class));
216
217         doAnswer(invocation -> {
218             actual.commit(invocation.getArgumentAt(0, DataTreeCandidate.class));
219             return null;
220         }).when(mock).commit(any(DataTreeCandidate.class));
221
222         doAnswer(invocation -> {
223             actual.setSchemaContext(invocation.getArgumentAt(0, SchemaContext.class));
224             return null;
225         }).when(mock).setSchemaContext(any(SchemaContext.class));
226
227         doAnswer(invocation -> {
228             return actual.takeSnapshot();
229         }).when(mock).takeSnapshot();
230
231         doAnswer(invocation -> {
232             return actual.getRootPath();
233         }).when(mock).getRootPath();
234
235         return mock;
236     }
237
238     protected ShardDataTreeCohort mockShardDataTreeCohort() {
239         ShardDataTreeCohort cohort = mock(ShardDataTreeCohort.class);
240         DataTreeCandidate candidate = mockCandidate("candidate");
241         successfulCanCommit(cohort);
242         successfulPreCommit(cohort, candidate);
243         successfulCommit(cohort);
244         doReturn(candidate).when(cohort).getCandidate();
245         return cohort;
246     }
247
248     protected Map<TransactionIdentifier, CapturingShardDataTreeCohort> setupCohortDecorator(final Shard shard,
249             final TransactionIdentifier... transactionIDs) {
250         final Map<TransactionIdentifier, CapturingShardDataTreeCohort> cohortMap = new HashMap<>();
251         for (TransactionIdentifier id: transactionIDs) {
252             cohortMap.put(id, new CapturingShardDataTreeCohort());
253         }
254
255         shard.getCommitCoordinator().setCohortDecorator((transactionID, actual) -> {
256             CapturingShardDataTreeCohort cohort = cohortMap.get(transactionID);
257             cohort.setDelegate(actual);
258             return cohort;
259         });
260
261         return cohortMap;
262     }
263
264     protected BatchedModifications prepareBatchedModifications(final TransactionIdentifier transactionID,
265                                                                final MutableCompositeModification modification) {
266         return prepareBatchedModifications(transactionID, modification, false);
267     }
268
269     protected static BatchedModifications prepareBatchedModifications(final TransactionIdentifier transactionID,
270                                                              final MutableCompositeModification modification,
271                                                              final boolean doCommitOnReady) {
272         final BatchedModifications batchedModifications = new BatchedModifications(transactionID, CURRENT_VERSION);
273         batchedModifications.addModification(modification);
274         batchedModifications.setReady(true);
275         batchedModifications.setDoCommitOnReady(doCommitOnReady);
276         batchedModifications.setTotalMessagesSent(1);
277         return batchedModifications;
278     }
279
280     protected static BatchedModifications prepareBatchedModifications(final TransactionIdentifier transactionID,
281             final YangInstanceIdentifier path, final NormalizedNode<?, ?> data, final boolean doCommitOnReady) {
282         final MutableCompositeModification modification = new MutableCompositeModification();
283         modification.addModification(new WriteModification(path, data));
284         return prepareBatchedModifications(transactionID, modification, doCommitOnReady);
285     }
286
287     protected static ForwardedReadyTransaction prepareForwardedReadyTransaction(final TestActorRef<Shard> shard,
288             final TransactionIdentifier transactionID, final YangInstanceIdentifier path,
289             final NormalizedNode<?, ?> data, final boolean doCommitOnReady) {
290         ReadWriteShardDataTreeTransaction rwTx = shard.underlyingActor().getDataStore()
291                 .newReadWriteTransaction(transactionID);
292         rwTx.getSnapshot().write(path, data);
293         return new ForwardedReadyTransaction(transactionID, CURRENT_VERSION, rwTx, doCommitOnReady);
294     }
295
296     public static NormalizedNode<?,?> readStore(final TestActorRef<? extends Shard> shard,
297             final YangInstanceIdentifier id) throws ExecutionException, InterruptedException {
298         return shard.underlyingActor().getDataStore().readNode(id).orNull();
299     }
300
301     public static NormalizedNode<?,?> readStore(final DataTree store, final YangInstanceIdentifier id) {
302         return store.takeSnapshot().readNode(id).orNull();
303     }
304
305     public void writeToStore(final TestActorRef<Shard> shard, final YangInstanceIdentifier id,
306             final NormalizedNode<?,?> node) throws InterruptedException, ExecutionException {
307         Future<Object> future = Patterns.ask(shard, newBatchedModifications(nextTransactionId(),
308                 id, node, true, true, 1), new Timeout(5, TimeUnit.SECONDS));
309         try {
310             Await.ready(future, Duration.create(5, TimeUnit.SECONDS));
311         } catch (TimeoutException e) {
312             throw new ExecutionException(e);
313         }
314     }
315
316     public static void writeToStore(final ShardDataTree store, final YangInstanceIdentifier id,
317             final NormalizedNode<?,?> node) throws Exception {
318         BatchedModifications batched = newBatchedModifications(nextTransactionId(), id, node, true, true, 1);
319         DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
320         batched.apply(modification);
321         store.notifyListeners(store.commit(modification));
322     }
323
324     public static void writeToStore(final DataTree store, final YangInstanceIdentifier id,
325             final NormalizedNode<?,?> node) throws DataValidationFailedException {
326         final DataTreeModification transaction = store.takeSnapshot().newModification();
327
328         transaction.write(id, node);
329         transaction.ready();
330         store.validate(transaction);
331         final DataTreeCandidate candidate = store.prepare(transaction);
332         store.commit(candidate);
333     }
334
335     public void mergeToStore(final ShardDataTree store, final YangInstanceIdentifier id,
336             final NormalizedNode<?,?> node) throws Exception {
337         final BatchedModifications batched = new BatchedModifications(nextTransactionId(), CURRENT_VERSION);
338         batched.addModification(new MergeModification(id, node));
339         batched.setReady(true);
340         batched.setDoCommitOnReady(true);
341         batched.setTotalMessagesSent(1);
342
343         DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
344         batched.apply(modification);
345         store.notifyListeners(store.commit(modification));
346     }
347
348     DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
349         final DataTree testStore = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
350         testStore.setSchemaContext(SCHEMA_CONTEXT);
351
352         writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
353
354         final NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.EMPTY);
355
356         InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(
357                 new ShardSnapshotState(new PreBoronShardDataTreeSnapshot(root)),
358                 Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1, 1, null, null));
359         return testStore;
360     }
361
362     static CommitTransactionPayload payloadForModification(final DataTree source, final DataTreeModification mod,
363             final TransactionIdentifier transactionId) throws DataValidationFailedException, IOException {
364         source.validate(mod);
365         final DataTreeCandidate candidate = source.prepare(mod);
366         source.commit(candidate);
367         return CommitTransactionPayload.create(transactionId, candidate);
368     }
369
370     static BatchedModifications newBatchedModifications(final TransactionIdentifier transactionID,
371             final YangInstanceIdentifier path, final NormalizedNode<?, ?> data, final boolean ready,
372             final boolean doCommitOnReady, final int messagesSent) {
373         final BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
374         batched.addModification(new WriteModification(path, data));
375         batched.setReady(ready);
376         batched.setDoCommitOnReady(doCommitOnReady);
377         batched.setTotalMessagesSent(messagesSent);
378         return batched;
379     }
380
381     @SuppressWarnings("unchecked")
382     static void verifyOuterListEntry(final TestActorRef<Shard> shard, final Object expIDValue) throws Exception {
383         final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
384         assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
385         assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable",
386                 outerList.getValue() instanceof Iterable);
387         final Object entry = ((Iterable<Object>)outerList.getValue()).iterator().next();
388         assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode",
389                 entry instanceof MapEntryNode);
390         final MapEntryNode mapEntry = (MapEntryNode)entry;
391         final Optional<DataContainerChild<? extends PathArgument, ?>> idLeaf =
392                 mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
393         assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
394         assertEquals(TestModel.ID_QNAME.getLocalName() + " value", expIDValue, idLeaf.get().getValue());
395     }
396
397     public static DataTreeCandidateTip mockCandidate(final String name) {
398         final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
399         final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
400         doReturn(ModificationType.WRITE).when(mockCandidateNode).getModificationType();
401         doReturn(Optional.of(ImmutableNodes.containerNode(CarsModel.CARS_QNAME)))
402                 .when(mockCandidateNode).getDataAfter();
403         doReturn(CarsModel.BASE_PATH).when(mockCandidate).getRootPath();
404         doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
405         return mockCandidate;
406     }
407
408     static DataTreeCandidateTip mockUnmodifiedCandidate(final String name) {
409         final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
410         final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
411         doReturn(ModificationType.UNMODIFIED).when(mockCandidateNode).getModificationType();
412         doReturn(YangInstanceIdentifier.EMPTY).when(mockCandidate).getRootPath();
413         doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
414         return mockCandidate;
415     }
416
417     static void commitTransaction(final DataTree store, final DataTreeModification modification)
418             throws DataValidationFailedException {
419         modification.ready();
420         store.validate(modification);
421         store.commit(store.prepare(modification));
422     }
423
424     @SuppressWarnings("serial")
425     public static final class DelegatingShardCreator implements Creator<Shard> {
426         private final Creator<Shard> delegate;
427
428         DelegatingShardCreator(final Creator<Shard> delegate) {
429             this.delegate = delegate;
430         }
431
432         @Override
433         public Shard create() throws Exception {
434             return delegate.create();
435         }
436     }
437
438     public static class CapturingShardDataTreeCohort extends ShardDataTreeCohort {
439         private volatile ShardDataTreeCohort delegate;
440         private FutureCallback<Void> canCommit;
441         private FutureCallback<DataTreeCandidate> preCommit;
442         private FutureCallback<UnsignedLong> commit;
443
444         public void setDelegate(final ShardDataTreeCohort delegate) {
445             this.delegate = delegate;
446         }
447
448         public FutureCallback<Void> getCanCommit() {
449             assertNotNull("canCommit was not invoked", canCommit);
450             return canCommit;
451         }
452
453         public FutureCallback<DataTreeCandidate> getPreCommit() {
454             assertNotNull("preCommit was not invoked", preCommit);
455             return preCommit;
456         }
457
458         public FutureCallback<UnsignedLong> getCommit() {
459             assertNotNull("commit was not invoked", commit);
460             return commit;
461         }
462
463         @Override
464         public TransactionIdentifier getIdentifier() {
465             return delegate.getIdentifier();
466         }
467
468         @Override
469         DataTreeCandidateTip getCandidate() {
470             return delegate.getCandidate();
471         }
472
473         @Override
474         DataTreeModification getDataTreeModification() {
475             return delegate.getDataTreeModification();
476         }
477
478         @Override
479         public void canCommit(final FutureCallback<Void> callback) {
480             canCommit = mockFutureCallback(callback);
481             delegate.canCommit(canCommit);
482         }
483
484         @Override
485         public void preCommit(final FutureCallback<DataTreeCandidate> callback) {
486             preCommit = mockFutureCallback(callback);
487             delegate.preCommit(preCommit);
488         }
489
490         @Override
491         public void commit(final FutureCallback<UnsignedLong> callback) {
492             commit = mockFutureCallback(callback);
493             delegate.commit(commit);
494         }
495
496         @SuppressWarnings("unchecked")
497         private static <T> FutureCallback<T> mockFutureCallback(final FutureCallback<T> actual) {
498             FutureCallback<T> mock = mock(FutureCallback.class);
499             doAnswer(invocation -> {
500                 actual.onFailure(invocation.getArgumentAt(0, Throwable.class));
501                 return null;
502             }).when(mock).onFailure(any(Throwable.class));
503
504             doAnswer(invocation -> {
505                 actual.onSuccess((T) invocation.getArgumentAt(0, Throwable.class));
506                 return null;
507             }).when(mock).onSuccess((T) any(Object.class));
508
509             return mock;
510         }
511
512         @Override
513         public void abort(final FutureCallback<Void> callback) {
514             delegate.abort(callback);
515         }
516
517         @Override
518         public boolean isFailed() {
519             return delegate.isFailed();
520         }
521
522         @Override
523         public State getState() {
524             return delegate.getState();
525         }
526     }
527 }