9ede21447c5b9d28ea9a346b10882b9c86ebe44f
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / test / java / org / opendaylight / controller / cluster / raft / ReplicatedLogImplEntryTest.java
1 /*
2  * Copyright (c) 2015 Brocade Communications Systems, Inc. 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.raft;
9
10 import java.io.FileInputStream;
11 import java.io.FileOutputStream;
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import org.junit.Assert;
16 import org.junit.Test;
17
18 /**
19  * Unit tests for ReplicatedLogImplEntry.
20  *
21  * @author Thomas Pantelis
22  */
23 public class ReplicatedLogImplEntryTest {
24
25     @Test
26     public void testBackwardsCompatibleDeserializationFromHelium() throws Exception {
27         String expPayloadData = "This is a test";
28         int expIndex = 1;
29         int expTerm = 2;
30
31         try(FileInputStream fis = new FileInputStream("src/test/resources/helium-serialized-ReplicatedLogImplEntry")) {
32             ObjectInputStream ois = new ObjectInputStream(fis);
33
34             ReplicatedLogImplEntry entry = (ReplicatedLogImplEntry) ois.readObject();
35             ois.close();
36
37             Assert.assertEquals("getIndex", expIndex, entry.getIndex());
38             Assert.assertEquals("getTerm", expTerm, entry.getTerm());
39
40             MockRaftActorContext.MockPayload payload = (MockRaftActorContext.MockPayload) entry.getData();
41             Assert.assertEquals("data", expPayloadData, payload.toString());
42         }
43     }
44
45     /**
46      * Use this method to generate a file with a serialized ReplicatedLogImplEntry instance to be
47      * used in tests that verify backwards compatible de-serialization.
48      */
49     private static void generateSerializedFile() throws IOException {
50         String expPayloadData = "This is a test";
51         int expIndex = 1;
52         int expTerm = 2;
53
54         ReplicatedLogImplEntry entry = new ReplicatedLogImplEntry(expIndex, expTerm,
55                 new MockRaftActorContext.MockPayload(expPayloadData));
56         FileOutputStream fos = new FileOutputStream("src/test/resources/serialized-ReplicatedLogImplEntry");
57         ObjectOutputStream oos = new ObjectOutputStream(fos);
58         oos.writeObject(entry);
59         fos.close();
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.