if (snapshot.getServerConfiguration() != null) {
context.updatePeerIds(snapshot.getServerConfiguration());
-
- if (isMigratedSerializable(snapshot.getServerConfiguration())) {
- hasMigratedDataRecovered = true;
- }
}
timer.stop();
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.cluster.raft;
-
-import com.google.common.base.Preconditions;
-import java.io.Serializable;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
-
-/**
- * A {@link ReplicatedLogEntry} implementation.
- *
- * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry} instead.
- */
-@Deprecated
-public class ReplicatedLogImplEntry implements ReplicatedLogEntry, Serializable {
- private static final long serialVersionUID = -9085798014576489130L;
-
- private final long index;
- private final long term;
- private final Payload payload;
- private transient boolean persistencePending = false;
-
- /**
- * Constructs an instance.
- *
- * @param index the index
- * @param term the term
- * @param payload the payload
- */
- public ReplicatedLogImplEntry(final long index, final long term, final Payload payload) {
- this.index = index;
- this.term = term;
- this.payload = Preconditions.checkNotNull(payload);
- }
-
- @Override
- public Payload getData() {
- return payload;
- }
-
- @Override
- public long getTerm() {
- return term;
- }
-
- @Override
- public long getIndex() {
- return index;
- }
-
- @Override
- public int size() {
- return getData().size();
- }
-
- private Object readResolve() {
- return org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry.createMigrated(
- index, term, payload);
- }
-
- @Override
- public boolean isPersistencePending() {
- return persistencePending;
- }
-
- @Override
- public void setPersistencePending(boolean pending) {
- persistencePending = pending;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + payload.hashCode();
- result = prime * result + (int) (index ^ index >>> 32);
- result = prime * result + (int) (term ^ term >>> 32);
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null) {
- return false;
- }
-
- if (getClass() != obj.getClass()) {
- return false;
- }
-
- ReplicatedLogImplEntry other = (ReplicatedLogImplEntry) obj;
- if (payload == null) {
- if (other.payload != null) {
- return false;
- }
- } else if (!payload.equals(other.payload)) {
- return false;
- }
-
- if (index != other.index) {
- return false;
- }
-
- if (term != other.term) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public String toString() {
- return "Entry{index=" + index + ", term=" + term + '}';
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.List;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
-import org.opendaylight.controller.cluster.raft.protobuff.client.messages.PersistentPayload;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Payload data for server configuration log entries.
- *
- * @author Thomas Pantelis
- *
- * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload} instead.
- */
-@Deprecated
-public class ServerConfigurationPayload extends Payload implements PersistentPayload, Serializable {
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = LoggerFactory.getLogger(ServerConfigurationPayload.class);
-
- private final List<ServerInfo> serverConfig;
- private transient int serializedSize = -1;
-
- public ServerConfigurationPayload(@Nonnull List<ServerInfo> serverConfig) {
- this.serverConfig = Preconditions.checkNotNull(serverConfig);
- }
-
- @Nonnull
- public List<ServerInfo> getServerConfig() {
- return serverConfig;
- }
-
- @Override
- public int size() {
- if (serializedSize < 0) {
- try {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(bos);
- out.writeObject(serverConfig);
- out.close();
-
- serializedSize = bos.toByteArray().length;
- } catch (IOException e) {
- serializedSize = 0;
- LOG.error("Error serializing", e);
- }
- }
-
- return serializedSize;
- }
-
- @Override
- public String toString() {
- return "ServerConfigurationPayload [serverConfig=" + serverConfig + "]";
- }
-
- private Object readResolve() {
- return org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload.createMigrated(
- Lists.transform(serverConfig, t -> new org.opendaylight.controller.cluster.raft.persisted.ServerInfo(
- t.getId(), t.isVoting)));
- }
-
- public static class ServerInfo implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private final String id;
- private final boolean isVoting;
-
- public ServerInfo(@Nonnull String id, boolean isVoting) {
- this.id = Preconditions.checkNotNull(id);
- this.isVoting = isVoting;
- }
-
- @Nonnull
- public String getId() {
- return id;
- }
-
- public boolean isVoting() {
- return isVoting;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Boolean.hashCode(isVoting);
- result = prime * result + id.hashCode();
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
-
- ServerInfo other = (ServerInfo) obj;
- return isVoting == other.isVoting && id.equals(other.id);
- }
-
- @Override
- public String toString() {
- return "ServerInfo [id=" + id + ", isVoting=" + isVoting + "]";
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft.base.messages;
-
-import java.io.Serializable;
-
-/**
- * This is an internal message that is stored in the akka's persistent journal. During recovery, this
- * message is used to apply recovered journal entries to the state whose indexes range from the context's
- * current lastApplied index to "toIndex" contained in the message. This message is sent internally from a
- * behavior to the RaftActor to persist.
- *
- * @author Thomas Pantelis
- *
- * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries} instead.
- */
-@Deprecated
-public class ApplyJournalEntries implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private final long toIndex;
-
- public ApplyJournalEntries(long toIndex) {
- this.toIndex = toIndex;
- }
-
- public long getToIndex() {
- return toIndex;
- }
-
- private Object readResolve() {
- return org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntries.createMigrated(toIndex);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("ApplyJournalEntries [toIndex=").append(toIndex).append("]");
- return builder.toString();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft.base.messages;
-
-import java.io.Serializable;
-
-/**
- * Internal message that is stored in the akka's persistent journal to delete journal entries.
- *
- * @author Thomas Pantelis
- *
- * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.DeleteEntries} instead.
- */
-@Deprecated
-public class DeleteEntries implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private final long fromIndex;
-
- public DeleteEntries(long fromIndex) {
- this.fromIndex = fromIndex;
- }
-
- public long getFromIndex() {
- return fromIndex;
- }
-
- private Object readResolve() {
- return org.opendaylight.controller.cluster.raft.persisted.DeleteEntries.createMigrated(fromIndex);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("DeleteEntries [fromIndex=").append(fromIndex).append("]");
- return builder.toString();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft.base.messages;
-
-import java.io.Serializable;
-
-/**
- * Message class to persist election term information.
- *
- * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm} instead.
- */
-@Deprecated
-public class UpdateElectionTerm implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private final long currentTerm;
- private final String votedFor;
-
- public UpdateElectionTerm(long currentTerm, String votedFor) {
- this.currentTerm = currentTerm;
- this.votedFor = votedFor;
- }
-
- public long getCurrentTerm() {
- return currentTerm;
- }
-
- public String getVotedFor() {
- return votedFor;
- }
-
- private Object readResolve() {
- return org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm.createMigrated(
- currentTerm, votedFor);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("UpdateElectionTerm [currentTerm=").append(currentTerm).append(", votedFor=").append(votedFor)
- .append("]");
- return builder.toString();
- }
-}
*
* @author Thomas Pantelis
*/
-public class ApplyJournalEntries implements Serializable, MigratedSerializable {
+public class ApplyJournalEntries implements Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
private final long toIndex;
- private final boolean migrated;
-
- private ApplyJournalEntries(final long toIndex, final boolean migrated) {
- this.toIndex = toIndex;
- this.migrated = migrated;
- }
public ApplyJournalEntries(final long toIndex) {
- this(toIndex, false);
+ this.toIndex = toIndex;
}
public long getToIndex() {
return toIndex;
}
- @Override
- public boolean isMigrated() {
- return migrated;
- }
-
- @Override
- public Object writeReplace() {
+ private Object writeReplace() {
return new Proxy(this);
}
- @Deprecated
- public static ApplyJournalEntries createMigrated(final long fromIndex) {
- return new ApplyJournalEntries(fromIndex, true);
- }
-
@Override
public String toString() {
return "ApplyJournalEntries [toIndex=" + toIndex + "]";
*
* @author Thomas Pantelis
*/
-public class DeleteEntries implements Serializable, MigratedSerializable {
+public class DeleteEntries implements Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
private final long fromIndex;
- private final boolean migrated;
-
- private DeleteEntries(final long fromIndex, final boolean migrated) {
- this.fromIndex = fromIndex;
- this.migrated = migrated;
- }
public DeleteEntries(final long fromIndex) {
- this(fromIndex, false);
+ this.fromIndex = fromIndex;
}
public long getFromIndex() {
return fromIndex;
}
- @Override
- public boolean isMigrated() {
- return migrated;
- }
-
- @Override
- public Object writeReplace() {
+ private Object writeReplace() {
return new Proxy(this);
}
- @Deprecated
- public static DeleteEntries createMigrated(final long fromIndex) {
- return new DeleteEntries(fromIndex, true);
- }
-
@Override
public String toString() {
return "DeleteEntries [fromIndex=" + fromIndex + "]";
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
*
* @author Thomas Pantelis
*/
-public final class ServerConfigurationPayload extends Payload implements PersistentPayload, MigratedSerializable {
+public final class ServerConfigurationPayload extends Payload implements PersistentPayload, Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
+ "implements writeReplace to delegate serialization to a Proxy class and thus instances of this class "
+ "aren't serialized. FindBugs does not recognize this.")
private final List<ServerInfo> serverConfig;
- private final boolean migrated;
private int serializedSize = -1;
- private ServerConfigurationPayload(@Nonnull final List<ServerInfo> serverConfig, boolean migrated) {
- this.serverConfig = ImmutableList.copyOf(serverConfig);
- this.migrated = migrated;
- }
-
public ServerConfigurationPayload(@Nonnull final List<ServerInfo> serverConfig) {
- this(serverConfig, false);
- }
-
- @Deprecated
- public static ServerConfigurationPayload createMigrated(@Nonnull final List<ServerInfo> serverConfig) {
- return new ServerConfigurationPayload(serverConfig, true);
- }
-
- @Deprecated
- @Override
- public boolean isMigrated() {
- return migrated;
+ this.serverConfig = ImmutableList.copyOf(serverConfig);
}
@Nonnull
return "ServerConfigurationPayload [serverConfig=" + serverConfig + "]";
}
- @Override
- public Object writeReplace() {
+ private Object writeReplace() {
return new Proxy(this);
}
}
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
+import java.io.Serializable;
import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
*
* @author Thomas Pantelis
*/
-public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, MigratedSerializable {
+public final class SimpleReplicatedLogEntry implements ReplicatedLogEntry, Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
private final long term;
private final Payload payload;
private boolean persistencePending;
- private final boolean migrated;
-
- private SimpleReplicatedLogEntry(long index, long term, Payload payload, boolean migrated) {
- this.index = index;
- this.term = term;
- this.payload = Preconditions.checkNotNull(payload);
- this.migrated = migrated;
- }
/**
* Constructs an instance.
* @param term the term
* @param payload the payload
*/
- public SimpleReplicatedLogEntry(final long index, final long term, final Payload payload) {
- this(index, term, payload, false);
- }
-
- @Deprecated
- public static ReplicatedLogEntry createMigrated(final long index, final long term, final Payload payload) {
- return new SimpleReplicatedLogEntry(index, term, payload, true);
+ public SimpleReplicatedLogEntry(long index, long term, Payload payload) {
+ this.index = index;
+ this.term = term;
+ this.payload = Preconditions.checkNotNull(payload);
}
@Override
persistencePending = pending;
}
- @Override
- public boolean isMigrated() {
- return migrated;
- }
-
- @Override
- public Object writeReplace() {
+ private Object writeReplace() {
return new Proxy(this);
}
/**
* Message class to persist election term information.
*/
-public class UpdateElectionTerm implements Serializable, MigratedSerializable {
+public class UpdateElectionTerm implements Serializable {
private static final class Proxy implements Externalizable {
private static final long serialVersionUID = 1L;
private final long currentTerm;
private final String votedFor;
- private final boolean migrated;
- private UpdateElectionTerm(final long currentTerm, final String votedFor, final boolean migrated) {
+ public UpdateElectionTerm(final long currentTerm, final String votedFor) {
this.currentTerm = currentTerm;
this.votedFor = votedFor;
- this.migrated = migrated;
- }
-
- public UpdateElectionTerm(final long currentTerm, final String votedFor) {
- this(currentTerm, votedFor, false);
}
public long getCurrentTerm() {
return votedFor;
}
- @Override
- public boolean isMigrated() {
- return migrated;
- }
-
- @Override
- public Object writeReplace() {
+ private Object writeReplace() {
return new Proxy(this);
}
- @Deprecated
- public static UpdateElectionTerm createMigrated(final long currentTerm, final String votedFor) {
- return new UpdateElectionTerm(currentTerm, votedFor, true);
- }
-
@Override
public String toString() {
return "UpdateElectionTerm [currentTerm=" + currentTerm + ", votedFor=" + votedFor + "]";
import akka.actor.ActorRef;
import akka.dispatch.Dispatchers;
-import akka.testkit.JavaTestKit;
import akka.testkit.TestActorRef;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
InMemorySnapshotStore.clear();
}
- @Test
- public void testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceEnabled() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceEnabled starting");
- doTestSnapshotAfterStartupWithMigratedServerConfigPayload(true);
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceEnabled ending");
- }
-
- @Test
- public void testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceDisabled() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceDisabled starting");
-
- TestActorRef<MockRaftActor> actor = doTestSnapshotAfterStartupWithMigratedServerConfigPayload(false);
- MockRaftActor mockRaftActor = actor.underlyingActor();
- String id = mockRaftActor.persistenceId();
- ConfigParams config = mockRaftActor.getRaftActorContext().getConfigParams();
-
- factory.killActor(actor, new JavaTestKit(getSystem()));
-
- actor = factory.createTestActor(MockRaftActor.builder().id(id).config(config)
- .persistent(Optional.of(false)).props().withDispatcher(Dispatchers.DefaultDispatcherId()), id);
- mockRaftActor = actor.underlyingActor();
- mockRaftActor.waitForRecoveryComplete();
-
- assertEquals("electionTerm", 1,
- mockRaftActor.getRaftActorContext().getTermInformation().getCurrentTerm());
- assertEquals("votedFor", id,
- mockRaftActor.getRaftActorContext().getTermInformation().getVotedFor());
-
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedServerConfigPayloadAndPersistenceDisabled ending");
- }
-
- @Test
- public void testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceEnabled() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceEnabled starting");
-
- String persistenceId = factory.generateActorId("test-actor-");
-
- org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm updateElectionTerm =
- new org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm(5, persistenceId);
-
- InMemoryJournal.addEntry(persistenceId, 1, updateElectionTerm);
-
- doTestSnapshotAfterStartupWithMigratedMessage(persistenceId, true, snapshot -> {
- assertEquals("getElectionVotedFor", persistenceId, snapshot.getElectionVotedFor());
- assertEquals("getElectionTerm", 5, snapshot.getElectionTerm());
- }, ByteState.empty());
-
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceEnabled ending");
- }
-
- @Test
- public void testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceDisabled() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceDisabled starting");
-
- String persistenceId = factory.generateActorId("test-actor-");
-
- org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm updateElectionTerm =
- new org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTerm(5, persistenceId);
-
- InMemoryJournal.addEntry(persistenceId, 1, updateElectionTerm);
-
- doTestSnapshotAfterStartupWithMigratedMessage(persistenceId, false, snapshot -> {
- assertEquals("getElectionVotedFor", persistenceId, snapshot.getElectionVotedFor());
- assertEquals("getElectionTerm", 5, snapshot.getElectionTerm());
- }, ByteState.empty());
-
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedUpdateElectionTermAndPersistenceDisabled ending");
- }
-
- @Test
- public void testSnapshotAfterStartupWithMigratedApplyJournalEntries() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedApplyJournalEntries starting");
-
- String persistenceId = factory.generateActorId("test-actor-");
-
- InMemoryJournal.addEntry(persistenceId, 1, new UpdateElectionTerm(1, persistenceId));
- InMemoryJournal.addEntry(persistenceId, 2, new SimpleReplicatedLogEntry(0, 1,
- new MockRaftActorContext.MockPayload("A")));
- InMemoryJournal.addEntry(persistenceId, 3,
- new org.opendaylight.controller.cluster.raft.base.messages.ApplyJournalEntries(0));
-
-
- doTestSnapshotAfterStartupWithMigratedMessage(persistenceId, true, snapshot -> {
- assertEquals("getLastAppliedIndex", 0, snapshot.getLastAppliedIndex());
- assertEquals("getLastAppliedTerm", 1, snapshot.getLastAppliedTerm());
- assertEquals("getLastIndex", 0, snapshot.getLastIndex());
- assertEquals("getLastTerm", 1, snapshot.getLastTerm());
- }, ByteState.empty());
-
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedApplyJournalEntries ending");
- }
-
@Test
public void testNoSnapshotAfterStartupWithNoMigratedMessages() {
TEST_LOG.info("testNoSnapshotAfterStartupWithNoMigratedMessages starting");
TEST_LOG.info("testNoSnapshotAfterStartupWithNoMigratedMessages ending");
}
- @Test
- public void testSnapshotAfterStartupWithMigratedReplicatedLogEntry() {
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedReplicatedLogEntry starting");
-
- String persistenceId = factory.generateActorId("test-actor-");
-
- InMemoryJournal.addEntry(persistenceId, 1, new UpdateElectionTerm(1, persistenceId));
- MockRaftActorContext.MockPayload expPayload = new MockRaftActorContext.MockPayload("A");
- InMemoryJournal.addEntry(persistenceId, 2, new org.opendaylight.controller.cluster.raft.ReplicatedLogImplEntry(
- 0, 1, expPayload));
-
- doTestSnapshotAfterStartupWithMigratedMessage(persistenceId, true, snapshot -> {
- assertEquals("Unapplied entries size", 1, snapshot.getUnAppliedEntries().size());
- assertEquals("Unapplied entry term", 1, snapshot.getUnAppliedEntries().get(0).getTerm());
- assertEquals("Unapplied entry index", 0, snapshot.getUnAppliedEntries().get(0).getIndex());
- assertEquals("Unapplied entry data", expPayload, snapshot.getUnAppliedEntries().get(0).getData());
- }, ByteState.empty());
-
- TEST_LOG.info("testSnapshotAfterStartupWithMigratedReplicatedLogEntry ending");
- }
-
- private TestActorRef<MockRaftActor> doTestSnapshotAfterStartupWithMigratedServerConfigPayload(boolean persistent) {
- String persistenceId = factory.generateActorId("test-actor-");
-
- org.opendaylight.controller.cluster.raft.ServerConfigurationPayload persistedServerConfig =
- new org.opendaylight.controller.cluster.raft.ServerConfigurationPayload(Arrays.asList(
- new org.opendaylight.controller.cluster.raft.ServerConfigurationPayload.ServerInfo(
- persistenceId, true),
- new org.opendaylight.controller.cluster.raft.ServerConfigurationPayload.ServerInfo(
- "downNode", true)));
-
- ServerConfigurationPayload expectedServerConfig = new ServerConfigurationPayload(Arrays.asList(
- new ServerInfo(persistenceId, true), new ServerInfo("downNode", true)));
-
- InMemoryJournal.addEntry(persistenceId, 1, new UpdateElectionTerm(1, persistenceId));
- InMemoryJournal.addEntry(persistenceId, 3, new SimpleReplicatedLogEntry(0, 1, persistedServerConfig));
-
- TestActorRef<MockRaftActor> actor = doTestSnapshotAfterStartupWithMigratedMessage(persistenceId,
- persistent, snapshot -> {
- assertEquals("getElectionVotedFor", persistenceId, snapshot.getElectionVotedFor());
- assertEquals("getElectionTerm", 1, snapshot.getElectionTerm());
- assertEquals("getServerConfiguration", new HashSet<>(expectedServerConfig.getServerConfig()),
- new HashSet<>(snapshot.getServerConfiguration().getServerConfig()));
- }, ByteState.empty());
-
- return actor;
- }
-
@Test
public void testSnapshotAfterStartupWithMigratedSnapshot() throws Exception {
TEST_LOG.info("testSnapshotAfterStartupWithMigratedSnapshot starting");
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
-
-/**
- * Unit tests for ReplicatedLogImplEntry.
- *
- * @author Thomas Pantelis
- */
-@Deprecated
-public class ReplicatedLogImplEntryTest {
-
- @Test
- public void testBackwardsCompatibleDeserializationFromHelium() throws Exception {
- String expPayloadData = "This is a test";
- int expIndex = 1;
- int expTerm = 2;
-
- try (FileInputStream fis = new FileInputStream("src/test/resources/helium-serialized-ReplicatedLogImplEntry")) {
- ObjectInputStream ois = new ObjectInputStream(fis);
-
- SimpleReplicatedLogEntry entry = (SimpleReplicatedLogEntry) ois.readObject();
- ois.close();
-
- Assert.assertEquals("getIndex", expIndex, entry.getIndex());
- Assert.assertEquals("getTerm", expTerm, entry.getTerm());
-
- MockRaftActorContext.MockPayload payload = (MockRaftActorContext.MockPayload) entry.getData();
- Assert.assertEquals("data", expPayloadData, payload.toString());
- }
- }
-
- /**
- * Use this method to generate a file with a serialized ReplicatedLogImplEntry instance to be
- * used in tests that verify backwards compatible de-serialization.
- */
- @SuppressWarnings("unused")
- private static void generateSerializedFile() throws IOException {
- String expPayloadData = "This is a test";
- int expIndex = 1;
- int expTerm = 2;
-
- ReplicatedLogImplEntry entry = new ReplicatedLogImplEntry(expIndex, expTerm,
- new MockRaftActorContext.MockPayload(expPayloadData));
- FileOutputStream fos = new FileOutputStream("src/test/resources/serialized-ReplicatedLogImplEntry");
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(entry);
- fos.close();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Arrays;
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Test;
-
-/**
- * Unit tests for ServerConfigurationPayload.
- *
- * @author Thomas Pantelis
- */
-@Deprecated
-public class ServerConfigurationPayloadTest {
-
- @Test
- public void testSerialization() {
- ServerConfigurationPayload expected = new ServerConfigurationPayload(Arrays.asList(
- new ServerConfigurationPayload.ServerInfo("1", true),
- new ServerConfigurationPayload.ServerInfo("2", false)));
- org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload cloned =
- (org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload)
- SerializationUtils.clone(expected);
-
- assertEquals("getServerConfig", ImmutableSet.of(
- new org.opendaylight.controller.cluster.raft.persisted.ServerInfo("1", true),
- new org.opendaylight.controller.cluster.raft.persisted.ServerInfo("2", false)),
- ImmutableSet.copyOf(cloned.getServerConfig()));
- assertEquals("isMigrated", true, cloned.isMigrated());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.raft.MockRaftActorContext.MockPayload;
-
-/**
- * Unit tests for Snapshot.
- *
- * @author Thomas Pantelis
- */
-@Deprecated
-public class SnapshotTest {
-
- @Test
- public void testBackwardsCompatibleDeserializationFromLithium() throws Exception {
- Snapshot expSnapshot = newLithiumSnapshot();
- try (FileInputStream fis = new FileInputStream("src/test/resources/lithium-serialized-Snapshot")) {
- ObjectInputStream ois = new ObjectInputStream(fis);
-
- Snapshot snapshot = (Snapshot) ois.readObject();
- ois.close();
-
- assertEquals("lastIndex", expSnapshot.getLastIndex(), snapshot.getLastIndex());
- assertEquals("lastTerm", expSnapshot.getLastTerm(), snapshot.getLastTerm());
- assertEquals("lastAppliedIndex", expSnapshot.getLastAppliedIndex(), snapshot.getLastAppliedIndex());
- assertEquals("lastAppliedTerm", expSnapshot.getLastAppliedTerm(), snapshot.getLastAppliedTerm());
- assertEquals("unAppliedEntries size", expSnapshot.getUnAppliedEntries().size(),
- snapshot.getUnAppliedEntries().size());
- assertArrayEquals("state", expSnapshot.getState(), snapshot.getState());
- assertEquals("electionTerm", 0, snapshot.getElectionTerm());
- assertEquals("electionVotedFor", null, snapshot.getElectionVotedFor());
- }
- }
-
- private static Snapshot newLithiumSnapshot() {
- byte[] state = {1, 2, 3, 4, 5};
- List<ReplicatedLogEntry> entries = new ArrayList<>();
- entries.add(new org.opendaylight.controller.cluster.raft.ReplicatedLogImplEntry(
- 6, 2, new MockPayload("payload")));
- long lastIndex = 6;
- long lastTerm = 2;
- long lastAppliedIndex = 5;
- long lastAppliedTerm = 1;
-
- return Snapshot.create(state, entries, lastIndex, lastTerm, lastAppliedIndex, lastAppliedTerm);
- }
-
- /**
- * Use this method to generate a file with a serialized Snapshot instance to be
- * used in tests that verify backwards compatible de-serialization.
- */
- @SuppressWarnings("unused")
- private static void generateSerializedFile(Snapshot snapshot, String fileName) throws IOException {
- FileOutputStream fos = new FileOutputStream("src/test/resources/" + fileName);
- ObjectOutputStream oos = new ObjectOutputStream(fos);
- oos.writeObject(snapshot);
- fos.close();
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft.base.messages;
-
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Unit tests for DeleteEntries.
- *
- * @author Thomas Pantelis
- */
-@Deprecated
-public class DeleteEntriesTest {
-
- @Test
- public void testSerialization() {
- DeleteEntries deleteEntries = new DeleteEntries(11);
- org.opendaylight.controller.cluster.raft.persisted.DeleteEntries clone =
- (org.opendaylight.controller.cluster.raft.persisted.DeleteEntries)
- SerializationUtils.clone(deleteEntries);
-
- Assert.assertEquals("getFromIndex", 11, clone.getFromIndex());
- Assert.assertEquals("isMigrated", true, clone.isMigrated());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.cluster.raft.base.messages;
-
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Unit tests for UpdateElectionTerm.
- *
- * @author Thomas Pantelis
- */
-@Deprecated
-public class UpdateElectionTermTest {
-
- @Test
- public void testSerialization() {
- UpdateElectionTerm expected = new UpdateElectionTerm(5, "member1");
- org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm clone =
- (org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm)
- SerializationUtils.clone(expected);
-
- Assert.assertEquals("getCurrentTerm", 5, clone.getCurrentTerm());
- Assert.assertEquals("getVotedFor", "member1", clone.getVotedFor());
- Assert.assertEquals("isMigrated", true, clone.isMigrated());
- }
-}
ApplyJournalEntries cloned = (ApplyJournalEntries) SerializationUtils.clone(expected);
assertEquals("getFromIndex", expected.getToIndex(), cloned.getToIndex());
- assertEquals("isMigrated", false, cloned.isMigrated());
}
}
DeleteEntries cloned = (DeleteEntries) SerializationUtils.clone(expected);
assertEquals("getFromIndex", expected.getFromIndex(), cloned.getFromIndex());
- assertEquals("isMigrated", false, cloned.isMigrated());
}
}
ServerConfigurationPayload cloned = (ServerConfigurationPayload) SerializationUtils.clone(expected);
assertEquals("getServerConfig", expected.getServerConfig(), cloned.getServerConfig());
- assertEquals("isMigrated", false, cloned.isMigrated());
}
@Test
assertEquals("getTerm", expected.getTerm(), cloned.getTerm());
assertEquals("getIndex", expected.getIndex(), cloned.getIndex());
assertEquals("getData", expected.getData(), cloned.getData());
- assertEquals("isMigrated", false, cloned.isMigrated());
}
}
assertEquals("getCurrentTerm", expected.getCurrentTerm(), cloned.getCurrentTerm());
assertEquals("getVotedFor", expected.getVotedFor(), cloned.getVotedFor());
- assertEquals("isMigrated", false, cloned.isMigrated());
}
}
import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
import org.opendaylight.controller.cluster.raft.RaftState;
-import org.opendaylight.controller.cluster.raft.ReplicatedLogImplEntry;
import org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload;
import org.opendaylight.controller.cluster.raft.persisted.ServerInfo;
+import org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry;
import org.opendaylight.controller.cluster.raft.persisted.UpdateElectionTerm;
import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
String shardID = ShardIdentifier.create(shard, MemberName.forName(member),
type + datastoreTypeSuffix).toString();
InMemoryJournal.addEntry(shardID, 1, new UpdateElectionTerm(1, null));
- InMemoryJournal.addEntry(shardID, 2, new ReplicatedLogImplEntry(0, 1,
+ InMemoryJournal.addEntry(shardID, 2, new SimpleReplicatedLogEntry(0, 1,
new ServerConfigurationPayload(newServerInfo)));
}
}