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.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
14 import akka.actor.ActorSystem;
15 import akka.actor.ExtendedActorSystem;
16 import akka.serialization.JavaSerializer;
17 import akka.testkit.TestProbe;
18 import akka.testkit.javadsl.TestKit;
19 import org.apache.commons.lang3.SerializationUtils;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
25 * Unit tests for MessageSliceReply.
27 * @author Thomas Pantelis
29 public class MessageSliceReplyTest {
30 private final ActorSystem actorSystem = ActorSystem.create("test");
34 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) actorSystem);
38 public void tearDown() {
39 TestKit.shutdownActorSystem(actorSystem, true);
43 public void testSerialization() {
48 private void testSuccess() {
49 MessageSliceReply expected = MessageSliceReply.success(new StringIdentifier("test"), 3,
50 TestProbe.apply(actorSystem).ref());
51 MessageSliceReply cloned = SerializationUtils.clone(expected);
53 assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
54 assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
55 assertEquals("getSendTo", expected.getSendTo(), cloned.getSendTo());
56 assertFalse("getFailure present", cloned.getFailure().isPresent());
59 private void testFailure() {
60 MessageSliceReply expected = MessageSliceReply.failed(new StringIdentifier("test"),
61 new MessageSliceException("mock", true), TestProbe.apply(actorSystem).ref());
62 MessageSliceReply cloned = SerializationUtils.clone(expected);
64 assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
65 assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
66 assertEquals("getSendTo", expected.getSendTo(), cloned.getSendTo());
67 assertTrue("getFailure present", cloned.getFailure().isPresent());
68 assertEquals("getFailure message", expected.getFailure().orElseThrow().getMessage(),
69 cloned.getFailure().orElseThrow().getMessage());
70 assertEquals("getFailure isRetriable", expected.getFailure().orElseThrow().isRetriable(),
71 cloned.getFailure().orElseThrow().isRetriable());