Example usage for org.apache.commons.lang SerializationUtils clone

List of usage examples for org.apache.commons.lang SerializationUtils clone

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils clone.

Prototype

public static Object clone(Serializable object) 

Source Link

Document

Deep clone an Object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph.

Usage

From source file:org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotStateTest.java

@Test
public void testSerialization() {
    NormalizedNode<?, ?> expectedNode = ImmutableContainerNodeBuilder.create()
            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
            .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();

    ShardSnapshotState expected = new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expectedNode));
    ShardSnapshotState cloned = (ShardSnapshotState) SerializationUtils.clone(expected);

    assertNotNull("getSnapshot is null", cloned.getSnapshot());
    assertEquals("getSnapshot type", MetadataShardDataTreeSnapshot.class, cloned.getSnapshot().getClass());
    assertEquals("getRootNode", expectedNode,
            ((MetadataShardDataTreeSnapshot) cloned.getSnapshot()).getRootNode().get());
}

From source file:org.opendaylight.controller.cluster.messaging.AbortSlicingTest.java

@Test
public void testSerialization() {
    AbortSlicing expected = new AbortSlicing(new StringIdentifier("test"));
    AbortSlicing cloned = (AbortSlicing) SerializationUtils.clone(expected);
    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
}

From source file:org.opendaylight.controller.cluster.messaging.MessageSliceIdentifierTest.java

@Test
public void testSerialization() {
    MessageSliceIdentifier expected = new MessageSliceIdentifier(new StringIdentifier("test"), 123L);
    MessageSliceIdentifier cloned = (MessageSliceIdentifier) SerializationUtils.clone(expected);
    assertEquals("cloned", expected, cloned);
    assertEquals("getClientIdentifier", expected.getClientIdentifier(), cloned.getClientIdentifier());
    assertEquals("getSlicerId", expected.getSlicerId(), cloned.getSlicerId());
}

From source file:org.opendaylight.controller.cluster.messaging.MessageSliceReplyTest.java

private void testSuccess() {
    MessageSliceReply expected = MessageSliceReply.success(new StringIdentifier("test"), 3,
            TestProbe.apply(actorSystem).ref());
    MessageSliceReply cloned = (MessageSliceReply) SerializationUtils.clone(expected);

    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
    assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
    assertEquals("getSendTo", expected.getSendTo(), cloned.getSendTo());
    assertFalse("getFailure present", cloned.getFailure().isPresent());
}

From source file:org.opendaylight.controller.cluster.messaging.MessageSliceReplyTest.java

private void testFailure() {
    MessageSliceReply expected = MessageSliceReply.failed(new StringIdentifier("test"),
            new MessageSliceException("mock", true), TestProbe.apply(actorSystem).ref());
    MessageSliceReply cloned = (MessageSliceReply) SerializationUtils.clone(expected);

    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
    assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
    assertEquals("getSendTo", expected.getSendTo(), cloned.getSendTo());
    assertTrue("getFailure present", cloned.getFailure().isPresent());
    assertEquals("getFailure message", expected.getFailure().get().getMessage(),
            cloned.getFailure().get().getMessage());
    assertEquals("getFailure isRetriable", expected.getFailure().get().isRetriable(),
            cloned.getFailure().get().isRetriable());
}

From source file:org.opendaylight.controller.cluster.messaging.MessageSliceTest.java

@Test
public void testSerialization() {
    byte[] data = new byte[1000];
    for (int i = 0, j = 0; i < data.length; i++) {
        data[i] = (byte) j;
        if (++j >= 255) {
            j = 0;//from w w  w . j a va  2s . c o m
        }
    }

    MessageSlice expected = new MessageSlice(new StringIdentifier("test"), data, 2, 3, 54321,
            TestProbe.apply(actorSystem).ref());
    MessageSlice cloned = (MessageSlice) SerializationUtils.clone(expected);

    assertEquals("getIdentifier", expected.getIdentifier(), cloned.getIdentifier());
    assertEquals("getSliceIndex", expected.getSliceIndex(), cloned.getSliceIndex());
    assertEquals("getTotalSlices", expected.getTotalSlices(), cloned.getTotalSlices());
    assertEquals("getLastSliceHashCode", expected.getLastSliceHashCode(), cloned.getLastSliceHashCode());
    assertArrayEquals("getData", expected.getData(), cloned.getData());
    assertEquals("getReplyTo", expected.getReplyTo(), cloned.getReplyTo());
}

From source file:org.opendaylight.controller.cluster.raft.base.messages.DeleteEntriesTest.java

@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);// w  w  w. jav a  2 s.c om

    Assert.assertEquals("getFromIndex", 11, clone.getFromIndex());
    Assert.assertEquals("isMigrated", true, clone.isMigrated());
}

From source file:org.opendaylight.controller.cluster.raft.base.messages.TimeoutNowTest.java

@Test
public void test() {
    TimeoutNow cloned = (TimeoutNow) SerializationUtils.clone(TimeoutNow.INSTANCE);
    assertSame("Cloned instance", TimeoutNow.INSTANCE, cloned);
}

From source file:org.opendaylight.controller.cluster.raft.base.messages.UpdateElectionTermTest.java

@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);// w ww.  ja v a  2 s.com

    Assert.assertEquals("getCurrentTerm", 5, clone.getCurrentTerm());
    Assert.assertEquals("getVotedFor", "member1", clone.getVotedFor());
    Assert.assertEquals("isMigrated", true, clone.isMigrated());
}

From source file:org.opendaylight.controller.cluster.raft.behaviors.FollowerIdentifierTest.java

@Test
public void testSerialization() throws FileNotFoundException, IOException {
    FollowerIdentifier expected = new FollowerIdentifier("follower1");
    FollowerIdentifier cloned = (FollowerIdentifier) SerializationUtils.clone(expected);
    assertEquals("cloned", expected, cloned);
}