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;
19 * Unit tests for ReplicatedLogImplEntry.
21 * @author Thomas Pantelis
23 public class ReplicatedLogImplEntryTest {
26 public void testBackwardsCompatibleDeserializationFromHelium() throws Exception {
27 String expPayloadData = "This is a test";
31 try(FileInputStream fis = new FileInputStream("src/test/resources/helium-serialized-ReplicatedLogImplEntry")) {
32 ObjectInputStream ois = new ObjectInputStream(fis);
34 ReplicatedLogImplEntry entry = (ReplicatedLogImplEntry) ois.readObject();
37 Assert.assertEquals("getIndex", expIndex, entry.getIndex());
38 Assert.assertEquals("getTerm", expTerm, entry.getTerm());
40 MockRaftActorContext.MockPayload payload = (MockRaftActorContext.MockPayload) entry.getData();
41 Assert.assertEquals("data", expPayloadData, payload.toString());
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.
49 private static void generateSerializedFile() throws IOException {
50 String expPayloadData = "This is a test";
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);