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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.