Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / AbstractRequestSuccessTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.access.commands;
9
10 import static java.util.Objects.requireNonNull;
11 import static org.junit.Assert.assertEquals;
12
13 import org.apache.commons.lang3.SerializationUtils;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
17 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
19 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.MemberName;
21 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
22
23 public abstract class AbstractRequestSuccessTest<T extends RequestSuccess<?, T>> {
24     private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
25             MemberName.forName("test"), FrontendType.forName("one"));
26     protected static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
27     protected static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(CLIENT_IDENTIFIER, 0);
28
29     private final @NonNull T object;
30     private final int expectedSize;
31
32     protected AbstractRequestSuccessTest(final T object, final int expectedSize) {
33         this.object = requireNonNull(object);
34         this.expectedSize = expectedSize;
35     }
36
37     @Test
38     public void serializationTest() {
39         final var bytes = SerializationUtils.serialize(object);
40         assertEquals(expectedSize, bytes.length);
41
42         @SuppressWarnings("unchecked")
43         final var deserialize = (T) SerializationUtils.deserialize(bytes);
44
45         assertEquals(object.getTarget(), deserialize.getTarget());
46         assertEquals(object.getVersion(), deserialize.getVersion());
47         assertEquals(object.getSequence(), deserialize.getSequence());
48         doAdditionalAssertions(deserialize);
49     }
50
51     protected void doAdditionalAssertions(final T deserialize) {
52         // No-op by default
53     }
54 }