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