2 * Copyright (c) 2017 Inocybe Technologies 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.messaging;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import akka.actor.ActorSystem;
14 import akka.actor.ExtendedActorSystem;
15 import akka.serialization.JavaSerializer;
16 import akka.testkit.TestProbe;
17 import akka.testkit.javadsl.TestKit;
18 import org.apache.commons.lang3.SerializationUtils;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
24 * Unit tests for MessageSlice.
26 * @author Thomas Pantelis
28 public class MessageSliceTest {
29 private final ActorSystem actorSystem = ActorSystem.create("test");
33 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) actorSystem);
37 public void tearDown() {
38 TestKit.shutdownActorSystem(actorSystem, true);
42 public void testSerialization() {
43 byte[] data = new byte[1000];
44 for (int i = 0, j = 0; i < data.length; i++) {
51 MessageSlice expected = new MessageSlice(new StringIdentifier("test"), data, 2, 3, 54321,
52 TestProbe.apply(actorSystem).ref());
53 MessageSlice cloned = SerializationUtils.clone(expected);
55 assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
56 assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
57 assertEquals("getTotalSlices", expected.getTotalSlices(), cloned.getTotalSlices());
58 assertEquals("getLastSliceHashCode", expected.getLastSliceHashCode(), cloned.getLastSliceHashCode());
59 assertArrayEquals("getData", expected.getData(), cloned.getData());
60 assertEquals("getReplyTo", expected.getReplyTo(), cloned.getReplyTo());