2 * Copyright (c) 2015 Brocade Communications Systems, 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;
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;
20 * Unit tests for ReplicatedLogImplEntry.
22 * @author Thomas Pantelis
25 public class ReplicatedLogImplEntryTest {
28 public void testBackwardsCompatibleDeserializationFromHelium() throws Exception {
29 String expPayloadData = "This is a test";
33 try (FileInputStream fis = new FileInputStream("src/test/resources/helium-serialized-ReplicatedLogImplEntry")) {
34 ObjectInputStream ois = new ObjectInputStream(fis);
36 SimpleReplicatedLogEntry entry = (SimpleReplicatedLogEntry) ois.readObject();
39 Assert.assertEquals("getIndex", expIndex, entry.getIndex());
40 Assert.assertEquals("getTerm", expTerm, entry.getTerm());
42 MockRaftActorContext.MockPayload payload = (MockRaftActorContext.MockPayload) entry.getData();
43 Assert.assertEquals("data", expPayloadData, payload.toString());
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.
51 @SuppressWarnings("unused")
52 private static void generateSerializedFile() throws IOException {
53 String expPayloadData = "This is a test";
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);