Change ReplicatedLogImplEntry to Externalizable proxy pattern
[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 import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
18
19 /**
20  * Unit tests for ReplicatedLogImplEntry.
21  *
22  * @author Thomas Pantelis
23  */
24 @Deprecated
25 public class ReplicatedLogImplEntryTest {
26
27     @Test
28     public void testBackwardsCompatibleDeserializationFromHelium() throws Exception {
29         String expPayloadData = "This is a test";
30         int expIndex = 1;
31         int expTerm = 2;
32
33         try (FileInputStream fis = new FileInputStream("src/test/resources/helium-serialized-ReplicatedLogImplEntry")) {
34             ObjectInputStream ois = new ObjectInputStream(fis);
35
36             SimpleReplicatedLogEntry entry = (SimpleReplicatedLogEntry) ois.readObject();
37             ois.close();
38
39             Assert.assertEquals("getIndex", expIndex, entry.getIndex());
40             Assert.assertEquals("getTerm", expTerm, entry.getTerm());
41
42             MockRaftActorContext.MockPayload payload = (MockRaftActorContext.MockPayload) entry.getData();
43             Assert.assertEquals("data", expPayloadData, payload.toString());
44         }
45     }
46
47     /**
48      * Use this method to generate a file with a serialized ReplicatedLogImplEntry instance to be
49      * used in tests that verify backwards compatible de-serialization.
50      */
51     @SuppressWarnings("unused")
52     private static void generateSerializedFile() throws IOException {
53         String expPayloadData = "This is a test";
54         int expIndex = 1;
55         int expTerm = 2;
56
57         ReplicatedLogImplEntry entry = new ReplicatedLogImplEntry(expIndex, expTerm,
58                 new MockRaftActorContext.MockPayload(expPayloadData));
59         FileOutputStream fos = new FileOutputStream("src/test/resources/serialized-ReplicatedLogImplEntry");
60         ObjectOutputStream oos = new ObjectOutputStream(fos);
61         oos.writeObject(entry);
62         fos.close();
63     }
64 }

©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.