2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.access.concepts;
10 import java.io.DataInput;
11 import java.io.IOException;
12 import javax.annotation.Nonnull;
13 import org.junit.Assert;
14 import org.opendaylight.controller.cluster.access.ABIVersion;
15 import org.opendaylight.yangtools.concepts.WritableIdentifier;
17 public class FailureEnvelopeTest extends AbstractEnvelopeTest<FailureEnvelope> {
20 protected FailureEnvelope createEnvelope() {
21 final RequestFailure<?, ?> message =
22 new MockFailure(OBJECT, new RuntimeRequestException("msg", new RuntimeException()), 42);
23 return new FailureEnvelope(message, 1L, 2L, 11L);
27 protected void doAdditionalAssertions(final FailureEnvelope envelope, final FailureEnvelope resolvedObject) {
28 Assert.assertEquals(envelope.getExecutionTimeNanos(), resolvedObject.getExecutionTimeNanos());
29 final RequestException expectedCause = envelope.getMessage().getCause();
30 final RequestException actualCause = resolvedObject.getMessage().getCause();
31 Assert.assertEquals(expectedCause.getMessage(), actualCause.getMessage());
32 Assert.assertEquals(expectedCause.isRetriable(), actualCause.isRetriable());
35 private static class MockRequestFailureProxy extends AbstractRequestFailureProxy<WritableIdentifier, MockFailure> {
37 @SuppressWarnings("checkstyle:RedundantModifier")
38 public MockRequestFailureProxy() {
42 private MockRequestFailureProxy(final MockFailure mockFailure) {
48 protected MockFailure createFailure(@Nonnull final WritableIdentifier target, final long sequence,
49 @Nonnull final RequestException failureCause) {
50 return new MockFailure(target, failureCause, sequence);
55 protected WritableIdentifier readTarget(@Nonnull final DataInput in) throws IOException {
56 return TransactionIdentifier.readFrom(in);
61 private static class MockFailure extends RequestFailure<WritableIdentifier, MockFailure> {
62 private static final long serialVersionUID = 1L;
64 MockFailure(final WritableIdentifier target, final RequestException cause, final long sequence) {
65 super(target, sequence, cause);
69 protected AbstractRequestFailureProxy<WritableIdentifier, MockFailure> externalizableProxy(
70 final ABIVersion version) {
71 return new MockRequestFailureProxy(this);
75 protected MockFailure cloneAsVersion(final ABIVersion version) {