List of usage examples for org.apache.commons.lang SerializationUtils clone
public static Object clone(Serializable object)
Deep clone an Object
using serialization.
This is many times slower than writing clone methods by hand on all objects in your object graph.
From source file:org.opendaylight.controller.cluster.raft.client.messages.ShutdownTest.java
@Test public void test() { Shutdown cloned = (Shutdown) SerializationUtils.clone(Shutdown.INSTANCE); assertSame("Cloned instance", Shutdown.INSTANCE, cloned); }
From source file:org.opendaylight.controller.cluster.raft.messages.AppendEntriesReplyTest.java
@Test public void testSerialization() { AppendEntriesReply expected = new AppendEntriesReply("follower", 5, true, 100, 4, (short) 6); AppendEntriesReply cloned = (AppendEntriesReply) SerializationUtils.clone(expected); assertEquals("getTerm", expected.getTerm(), cloned.getTerm()); assertEquals("getFollowerId", expected.getFollowerId(), cloned.getFollowerId()); assertEquals("getLogLastTerm", expected.getLogLastTerm(), cloned.getLogLastTerm()); assertEquals("getLogLastIndex", expected.getLogLastIndex(), cloned.getLogLastIndex()); assertEquals("getPayloadVersion", expected.getPayloadVersion(), cloned.getPayloadVersion()); assertEquals("getRaftVersion", expected.getRaftVersion(), cloned.getRaftVersion()); }
From source file:org.opendaylight.controller.cluster.raft.messages.AppendEntriesTest.java
@Test public void testSerialization() { ReplicatedLogEntry entry1 = new ReplicatedLogImplEntry(1, 2, new MockPayload("payload1")); ReplicatedLogEntry entry2 = new ReplicatedLogImplEntry(3, 4, new MockPayload("payload2")); short payloadVersion = 5; AppendEntries expected = new AppendEntries(5L, "node1", 7L, 8L, Arrays.asList(entry1, entry2), 10L, -1, payloadVersion);/* ww w . ja v a 2 s . co m*/ AppendEntries cloned = (AppendEntries) SerializationUtils.clone(expected); verifyAppendEntries(expected, cloned); }
From source file:org.opendaylight.controller.cluster.raft.messages.InstallSnapshotReplyTest.java
@Test public void testSerialization() { InstallSnapshotReply expected = new InstallSnapshotReply(5L, "follower", 1, true); InstallSnapshotReply cloned = (InstallSnapshotReply) SerializationUtils.clone(expected); assertEquals("getTerm", expected.getTerm(), cloned.getTerm()); assertEquals("getFollowerId", expected.getFollowerId(), cloned.getFollowerId()); assertEquals("getChunkIndex", expected.getChunkIndex(), cloned.getChunkIndex()); assertEquals("isSuccess", expected.isSuccess(), cloned.isSuccess()); }
From source file:org.opendaylight.controller.cluster.raft.messages.InstallSnapshotTest.java
@Test public void testSerialization() { byte[] data = new byte[1000]; int j = 0;/*ww w. ja va 2s . c o m*/ for (int i = 0; i < data.length; i++) { data[i] = (byte) j; if (++j >= 255) { j = 0; } } ServerConfigurationPayload serverConfig = new ServerConfigurationPayload( Arrays.asList(new ServerInfo("leader", true), new ServerInfo("follower", false))); InstallSnapshot expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6, Optional.<Integer>of(54321), Optional.of(serverConfig)); Object serialized = expected.toSerializable(RaftVersions.CURRENT_VERSION); assertEquals("Serialized type", InstallSnapshot.class, serialized.getClass()); InstallSnapshot actual = (InstallSnapshot) SerializationUtils.clone((Serializable) serialized); verifyInstallSnapshot(expected, actual); expected = new InstallSnapshot(3L, "leaderId", 11L, 2L, data, 5, 6); actual = (InstallSnapshot) SerializationUtils .clone((Serializable) expected.toSerializable(RaftVersions.CURRENT_VERSION)); verifyInstallSnapshot(expected, actual); }
From source file:org.opendaylight.controller.cluster.raft.messages.RequestVoteReplyTest.java
@Test public void testSerialization() { RequestVoteReply expected = new RequestVoteReply(5, true); RequestVoteReply cloned = (RequestVoteReply) SerializationUtils.clone(expected); assertEquals("getTerm", expected.getTerm(), cloned.getTerm()); assertEquals("isVoteGranted", expected.isVoteGranted(), cloned.isVoteGranted()); }
From source file:org.opendaylight.controller.cluster.raft.messages.RequestVoteTest.java
@Test public void testSerialization() { RequestVote expected = new RequestVote(4, "candidateId", 3, 2); RequestVote cloned = (RequestVote) SerializationUtils.clone(expected); assertEquals("getTerm", expected.getTerm(), cloned.getTerm()); assertEquals("getCandidateId", expected.getCandidateId(), cloned.getCandidateId()); assertEquals("getLastLogIndex", expected.getLastLogIndex(), cloned.getLastLogIndex()); assertEquals("getLastLogTerm", expected.getLastLogTerm(), cloned.getLastLogTerm()); }
From source file:org.opendaylight.controller.cluster.raft.persisted.ApplyJournalEntriesTest.java
@Test public void testSerialization() { ApplyJournalEntries expected = new ApplyJournalEntries(5); ApplyJournalEntries cloned = (ApplyJournalEntries) SerializationUtils.clone(expected); assertEquals("getFromIndex", expected.getToIndex(), cloned.getToIndex()); assertEquals("isMigrated", false, cloned.isMigrated()); }
From source file:org.opendaylight.controller.cluster.raft.persisted.DeleteEntriesTest.java
@Test public void testSerialization() { DeleteEntries expected = new DeleteEntries(5); DeleteEntries cloned = (DeleteEntries) SerializationUtils.clone(expected); assertEquals("getFromIndex", expected.getFromIndex(), cloned.getFromIndex()); assertEquals("isMigrated", false, cloned.isMigrated()); }
From source file:org.opendaylight.controller.cluster.raft.persisted.EmptyStateTest.java
@Test public void testSerialization() { EmptyState cloned = (EmptyState) SerializationUtils.clone(EmptyState.INSTANCE); assertSame("cloned", EmptyState.INSTANCE, cloned); }