InstallSnapshot extends AbstractRaftRPC { public <T> Object toSerializable(final short version) { return this; } @SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Stores a reference to an externally mutable byte[] " + "object but this is OK since this class is merely a DTO and does not process byte[] internally. " + "Also it would be inefficient to create a copy as the byte[] could be large.")  InstallSnapshot(final long term, final String leaderId, final long lastIncludedIndex,
            final long lastIncludedTerm, final byte[] data, final int chunkIndex, final int totalChunks,
            final OptionalInt lastChunkHashCode, final Optional<ServerConfigurationPayload> serverConfig);  InstallSnapshot(final long term, final String leaderId, final long lastIncludedIndex,
                           final long lastIncludedTerm, final byte[] data, final int chunkIndex,
                           final int totalChunks); String getLeaderId(); long getLastIncludedIndex(); long getLastIncludedTerm(); @SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "Exposes a mutable object stored in a field but " + "this is OK since this class is merely a DTO and does not process the byte[] internally. " + "Also it would be inefficient to create a return copy as the byte[] could be large.") byte[] getData(); int getChunkIndex(); int getTotalChunks(); OptionalInt getLastChunkHashCode(); Optional<ServerConfigurationPayload> getServerConfig(); Object toSerializable(final short version); @Override String toString();  }
@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; } } 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, OptionalInt.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); }