2 * Copyright (c) 2018 Red Hat, Inc. 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.raft.persisted;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import java.io.NotSerializableException;
14 import org.apache.pekko.actor.ExtendedActorSystem;
15 import org.apache.pekko.testkit.javadsl.TestKit;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.raft.MockRaftActorContext;
20 * Unit tests for SimpleReplicatedLogEntrySerializer.
22 * @author Thomas Pantelis
24 public class SimpleReplicatedLogEntrySerializerTest {
27 public void testToAndFromBinary() throws NotSerializableException {
28 SimpleReplicatedLogEntry expected = new SimpleReplicatedLogEntry(0, 1,
29 new MockRaftActorContext.MockPayload("A"));
31 final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
32 final Object deserialized;
34 final SimpleReplicatedLogEntrySerializer serializer = new SimpleReplicatedLogEntrySerializer(system);
35 final byte[] bytes = serializer.toBinary(expected);
36 deserialized = serializer.fromBinary(bytes, SimpleReplicatedLogEntry.class);
38 TestKit.shutdownActorSystem(system);
41 assertNotNull("fromBinary returned null", deserialized);
42 assertEquals("fromBinary return type", SimpleReplicatedLogEntry.class, deserialized.getClass());
44 SimpleReplicatedLogEntry actual = (SimpleReplicatedLogEntry)deserialized;
45 assertEquals("getTerm", expected.term(), actual.term());
46 assertEquals("getIndex", expected.index(), actual.index());
47 assertEquals("getData", expected.getData(), actual.getData());