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