From: Robert Varga Date: Wed, 8 May 2024 16:45:41 +0000 (+0200) Subject: Modernize tests and fixup checkstyle X-Git-Tag: v9.0.3~20 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=102d7b2e1fb75d755a81bcff3cd7a965cb9c9cc3;p=controller.git Modernize tests and fixup checkstyle Reformat for checkstyle compliance and modernize with JUnit5, etc. Change-Id: I6fab572f429578e6be924f6d8bcffcc6d083d333 Signed-off-by: Robert Varga --- diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java index 205857533d..ad44702537 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java @@ -56,7 +56,7 @@ public interface ByteBufReader extends AutoCloseable { long nextIndex(); /** - * Try to move to the next binary data block + * Try to move to the next binary data block. * * @param entryMapper callback to be invoked on binary data * @return processed binary data, or {@code null} diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java index 97dbab72ef..e64110e675 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java @@ -24,6 +24,7 @@ import org.eclipse.jdt.annotation.Nullable; /** * Stores information about a {@link JournalSegment} of the log. + * *

* The segment descriptor manages metadata related to a single segment of the log. Descriptors are stored within the * first {@code 64} bytes of each segment in the following order: @@ -93,6 +94,7 @@ public record JournalSegmentDescriptor( /** * Returns the segment version. + * *

* Versions are monotonically increasing starting at {@code 1}. * @@ -104,6 +106,7 @@ public record JournalSegmentDescriptor( /** * Returns the segment identifier. + * *

* The segment ID is a monotonically increasing number within each log. Segments with in-sequence identifiers should * contain in-sequence indexes. @@ -116,9 +119,10 @@ public record JournalSegmentDescriptor( /** * Returns the segment index. + * *

- * The index indicates the index at which the first entry should be written to the segment. Indexes are monotonically - * increasing thereafter. + * The index indicates the index at which the first entry should be written to the segment. Indexes are + * monotonically increasing thereafter. * * @return The segment index. */ @@ -146,10 +150,11 @@ public record JournalSegmentDescriptor( /** * Returns last time the segment was updated. + * *

- * When the segment is first constructed, the {@code updated} time is {@code 0}. Once all entries in the segment have - * been committed, the {@code updated} time should be set to the current time. Log compaction should not result in a - * change to {@code updated}. + * When the segment is first constructed, the {@code updated} time is {@code 0}. Once all entries in the segment + * have been committed, the {@code updated} time should be set to the current time. Log compaction should not result + * in a change to {@code updated}. * * @return The last time the segment was updated in terms of milliseconds since the epoch. */ @@ -158,7 +163,7 @@ public record JournalSegmentDescriptor( } /** - * Returns this segment as an array of bytes + * Returns this segment as an array of bytes. * * @return bytes */ @@ -177,6 +182,7 @@ public record JournalSegmentDescriptor( /** * Returns a descriptor builder. + * *

* The descriptor builder will write segment metadata to a {@code 48} byte in-memory buffer. * @@ -260,7 +266,7 @@ public record JournalSegmentDescriptor( } /** - * Sets updated timestamp; + * Sets updated timestamp. * * @param updated Epoch milliseconds * @return The segment descriptor builder. diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java index aa4c0da18a..e925ef8bb1 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java @@ -70,7 +70,7 @@ final class JournalSegmentReader { } /** - * Reads the next binary data block + * Reads the next binary data block. * * @return The binary data, or {@code null} */ diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java index 9d6d6ee992..29b5bed7ab 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java @@ -31,7 +31,7 @@ import java.nio.ByteBuffer; * * @deprecated due to dependency on outdated Kryo library, {@link ByteBufMapper} to be used instead. */ -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") public interface JournalSerdes { /** * Serializes given object to byte array. @@ -91,7 +91,7 @@ public interface JournalSerdes { * @param deserialized Object type * @return deserialized Object */ - T deserialize(final ByteBuffer buffer); + T deserialize(ByteBuffer buffer); /** * Deserializes given InputStream to an Object. @@ -110,7 +110,7 @@ public interface JournalSerdes { * @param bufferSize size of the buffer in front of the stream * @return deserialized Object */ - T deserialize(final InputStream stream, final int bufferSize); + T deserialize(InputStream stream, int bufferSize); /** * Returns a {@link ByteBufMapper} backed by this object. @@ -161,6 +161,7 @@ public interface JournalSerdes { /** * Registers serializer for the given set of classes. + * *

* When multiple classes are registered with an explicitly provided serializer, the namespace guarantees * all instances will be serialized with the same type ID. diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentEntry.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentEntry.java index 432f9b9dec..a18bd5eecd 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentEntry.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentEntry.java @@ -27,11 +27,11 @@ import org.eclipse.jdt.annotation.NonNull; */ record SegmentEntry(int checksum, @NonNull ByteBuffer bytes) { /** - * The size of the header, comprising of: + * The size of the header. It is comprised of *

*/ static final int HEADER_BYTES = Integer.BYTES + Integer.BYTES; diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java index 4698a5fd60..0d42181851 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java @@ -392,6 +392,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal { /** * Compacts the journal up to the given index. + * *

* The semantics of compaction are not specified by this interface. * @@ -507,7 +508,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal { } /** - * Sets the journal directory + * Sets the journal directory. * * @param directory The log directory. * @return The builder instance @@ -548,6 +549,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal { /** * Sets the journal index density. + * *

* The index density is the frequency at which the position of entries written to the journal will be * recorded in an in-memory index for faster seeking. @@ -564,6 +566,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal { /** * Enables flushing buffers to disk when entries are committed to a segment. + * *

* When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time * an entry is committed in a given segment. @@ -576,6 +579,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal { /** * Sets whether to flush buffers to disk when entries are committed to a segment. + * *

* When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time * an entry is committed in a given segment. diff --git a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java index f6c976742c..35b0cb87bc 100644 --- a/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java +++ b/atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java @@ -72,6 +72,7 @@ public final class SegmentedJournal implements Journal { /** * Compacts the journal up to the given index. + * *

* The semantics of compaction are not specified by this interface. * @@ -111,6 +112,7 @@ public final class SegmentedJournal implements Journal { /** * Sets the journal storage level. + * *

* The storage level indicates how individual entries will be persisted in the journal. * @@ -124,6 +126,7 @@ public final class SegmentedJournal implements Journal { /** * Sets the journal storage directory. + * *

* The journal will write segment files into the provided directory. * @@ -138,6 +141,7 @@ public final class SegmentedJournal implements Journal { /** * Sets the journal storage directory. + * *

* The journal will write segment files into the provided directory. * @@ -146,7 +150,7 @@ public final class SegmentedJournal implements Journal { * @throws NullPointerException If the {@code directory} is {@code null} */ public Builder withDirectory(final File directory) { - byteJournalBuilder.withDirectory(directory); + byteJournalBuilder.withDirectory(directory); return this; } @@ -157,7 +161,7 @@ public final class SegmentedJournal implements Journal { * @return The journal builder. * @deprecated due to serialization refactoring, use {@link Builder#withMapper(ByteBufMapper)} instead */ - @Deprecated(forRemoval = true, since="9.0.3") + @Deprecated(forRemoval = true, since = "9.0.3") public Builder withNamespace(final JournalSerdes namespace) { return withMapper(requireNonNull(namespace, "namespace cannot be null").toMapper()); } @@ -175,10 +179,12 @@ public final class SegmentedJournal implements Journal { /** * Sets the maximum segment size in bytes. + * *

* The maximum segment size dictates when journal should roll over to new segments. As entries are written * to a journal segment, once the size of the segment surpasses the configured maximum segment size, the * journal will create a new segment and append new entries to that segment. + * *

* By default, the maximum segment size is 32M. * @@ -218,6 +224,7 @@ public final class SegmentedJournal implements Journal { /** * Sets the journal index density. + * *

* The index density is the frequency at which the position of entries written to the journal will be recorded * in an in-memory index for faster seeking. @@ -233,6 +240,7 @@ public final class SegmentedJournal implements Journal { /** * Enables flushing buffers to disk when entries are committed to a segment. + * *

* When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time an * entry is committed in a given segment. @@ -245,6 +253,7 @@ public final class SegmentedJournal implements Journal { /** * Enables flushing buffers to disk when entries are committed to a segment. + * *

* When flush-on-commit is enabled, log entry buffers will be automatically flushed to disk each time an * entry is committed in a given segment. diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/EntrySerializer.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/EntrySerializer.java index f8355244b1..accd9943d3 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/EntrySerializer.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/EntrySerializer.java @@ -27,7 +27,7 @@ import com.google.common.base.MoreObjects; import io.atomix.storage.journal.JournalSerdes.EntrySerdes; import java.io.IOException; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class EntrySerializer extends Serializer { // Note: uses identity to create things in Kryo, hence we want an instance for every serdes we wrap private final JavaSerializer javaSerializer = new JavaSerializer(); diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryInput.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryInput.java index 1c0e500928..e1dea856cb 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryInput.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryInput.java @@ -24,7 +24,7 @@ import com.esotericsoftware.kryo.serializers.JavaSerializer; import io.atomix.storage.journal.JournalSerdes.EntryInput; import java.io.IOException; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class KryoEntryInput implements EntryInput { private final Kryo kryo; private final Input input; diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryOutput.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryOutput.java index 5e91332906..d4724b986b 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryOutput.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryOutput.java @@ -24,7 +24,7 @@ import com.esotericsoftware.kryo.serializers.JavaSerializer; import io.atomix.storage.journal.JournalSerdes.EntryOutput; import java.io.IOException; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class KryoEntryOutput implements EntryOutput { private final Kryo kryo; private final Output output; diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdes.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdes.java index 7742f981c6..e8ddcdeb87 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdes.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdes.java @@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory; /** * Pool of Kryo instances, with classes pre-registered. */ -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class KryoJournalSerdes implements JournalSerdes, KryoFactory, KryoPool { /** * Default buffer size used for serialization. @@ -227,20 +227,20 @@ final class KryoJournalSerdes implements JournalSerdes, KryoFactory, KryoPool { } for (Class type : types) { - Registration r = null; + Registration reg = null; if (serializer == null) { - r = kryo.register(type, id); + reg = kryo.register(type, id); } else if (type.isInterface()) { kryo.addDefaultSerializer(type, serializer); } else { - r = kryo.register(type, serializer, id); + reg = kryo.register(type, serializer, id); } - if (r != null) { - if (r.getId() != id) { + if (reg != null) { + if (reg.getId() != id) { LOGGER.debug("{}: {} already registered as {}. Skipping {}.", - friendlyName, r.getType(), r.getId(), id); + friendlyName, reg.getType(), reg.getId(), id); } - LOGGER.trace("{} registered as {}", r.getType(), r.getId()); + LOGGER.trace("{} registered as {}", reg.getType(), reg.getId()); } } } diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdesBuilder.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdesBuilder.java index 0caf7eaca6..779da00278 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdesBuilder.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdesBuilder.java @@ -25,7 +25,7 @@ import io.atomix.storage.journal.JournalSerdes.EntrySerdes; import java.util.ArrayList; import java.util.List; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") public final class KryoJournalSerdesBuilder implements Builder { private final List types = new ArrayList<>(); private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); @@ -52,4 +52,4 @@ public final class KryoJournalSerdesBuilder implements Builder { checkState(!types.isEmpty(), "No serializers registered"); return new KryoJournalSerdes(types, classLoader, friendlyName); } -} \ No newline at end of file +} diff --git a/atomix-storage/src/main/java/io/atomix/utils/serializer/RegisteredType.java b/atomix-storage/src/main/java/io/atomix/utils/serializer/RegisteredType.java index 79cccbe4e3..1d6cf80547 100644 --- a/atomix-storage/src/main/java/io/atomix/utils/serializer/RegisteredType.java +++ b/atomix-storage/src/main/java/io/atomix/utils/serializer/RegisteredType.java @@ -17,7 +17,7 @@ package io.atomix.utils.serializer; import static java.util.Objects.requireNonNull; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") record RegisteredType(EntrySerializer serializer, Class[] types) { RegisteredType { requireNonNull(serializer); diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java index 6118f600cd..05a758a366 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java @@ -45,7 +45,7 @@ import org.junit.runners.Parameterized; */ @RunWith(Parameterized.class) public abstract class AbstractJournalTest { - @Deprecated(forRemoval = true, since="9.0.3") + @Deprecated(forRemoval = true, since = "9.0.3") private static final JournalSerdes NAMESPACE = JournalSerdes.builder() .register(new TestEntrySerdes(), TestEntry.class) .register(new ByteArraySerdes(), byte[].class) @@ -101,9 +101,9 @@ public abstract class AbstractJournalTest { @Test public void testWriteRead() throws Exception { - try (Journal journal = createJournal()) { - JournalWriter writer = journal.writer(); - JournalReader reader = journal.openReader(1); + try (var journal = createJournal()) { + var writer = journal.writer(); + var reader = journal.openReader(1); // Append a couple entries. assertEquals(1, writer.getNextIndex()); @@ -219,30 +219,30 @@ public abstract class AbstractJournalTest { @Test public void testTruncateRead() throws Exception { - int i = 10; + final int cnt = 10; try (Journal journal = createJournal()) { JournalWriter writer = journal.writer(); JournalReader reader = journal.openReader(1); - for (int j = 1; j <= i; j++) { - assertEquals(j, writer.append(new TestEntry(32)).index()); + for (int i = 1; i <= cnt; i++) { + assertEquals(i, writer.append(new TestEntry(32)).index()); } - for (int j = 1; j <= i - 2; j++) { - assertEquals(j, assertNext(reader).index()); + for (int i = 1; i <= cnt - 2; i++) { + assertEquals(i, assertNext(reader).index()); } - writer.reset(i - 1); + writer.reset(cnt - 1); assertNoNext(reader); - assertEquals(i - 1, writer.append(new TestEntry(32)).index()); - assertEquals(i, writer.append(new TestEntry(32)).index()); + assertEquals(cnt - 1, writer.append(new TestEntry(32)).index()); + assertEquals(cnt, writer.append(new TestEntry(32)).index()); var entry = assertNext(reader); - assertEquals(i - 1, entry.index()); + assertEquals(cnt - 1, entry.index()); entry = assertNext(reader); assertNotNull(entry); - assertEquals(i, entry.index()); + assertEquals(cnt, entry.index()); } } diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java b/atomix-storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java index c8789b829f..8569099d44 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java @@ -20,7 +20,7 @@ import io.atomix.storage.journal.JournalSerdes.EntryOutput; import io.atomix.storage.journal.JournalSerdes.EntrySerdes; import java.io.IOException; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class ByteArraySerdes implements EntrySerdes { @Override public byte[] read(final EntryInput input) throws IOException { diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/JournalSegmentFileTest.java b/atomix-storage/src/test/java/io/atomix/storage/journal/JournalSegmentFileTest.java index 114ae094b5..312a9f6c32 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/JournalSegmentFileTest.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/JournalSegmentFileTest.java @@ -15,29 +15,26 @@ */ package io.atomix.storage.journal; -import java.io.File; - -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import java.io.File; +import org.junit.jupiter.api.Test; /** * Journal segment file test. */ -public class JournalSegmentFileTest { - - @Test - public void testIsSegmentFile() throws Exception { - assertTrue(JournalSegmentFile.isSegmentFile("foo", "foo-1.log")); - assertFalse(JournalSegmentFile.isSegmentFile("foo", "bar-1.log")); - assertTrue(JournalSegmentFile.isSegmentFile("foo", "foo-1-1.log")); - } - - @Test - public void testCreateSegmentFile() throws Exception { - File file = JournalSegmentFile.createSegmentFile("foo", new File(System.getProperty("user.dir")), 1); - assertTrue(JournalSegmentFile.isSegmentFile("foo", file)); - } +class JournalSegmentFileTest { + @Test + void testIsSegmentFile() { + assertTrue(JournalSegmentFile.isSegmentFile("foo", "foo-1.log")); + assertFalse(JournalSegmentFile.isSegmentFile("foo", "bar-1.log")); + assertTrue(JournalSegmentFile.isSegmentFile("foo", "foo-1-1.log")); + } + @Test + void testCreateSegmentFile() { + final var file = JournalSegmentFile.createSegmentFile("foo", new File(System.getProperty("user.dir")), 1); + assertTrue(JournalSegmentFile.isSegmentFile("foo", file)); + } } diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntry.java b/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntry.java index 76cf828d02..93e4d38fe1 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntry.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntry.java @@ -25,35 +25,32 @@ import java.util.Arrays; * @author Jordan Halterman */ public class TestEntry { - private final byte[] bytes; - - public TestEntry(int size) { - this(new byte[size]); - } - - public TestEntry(byte[] bytes) { - this.bytes = bytes; - } - - public byte[] bytes() { - return bytes; - } - - @Override - public boolean equals(Object obj) { - return this == obj || obj instanceof TestEntry testEntry && Arrays.equals(bytes, testEntry.bytes); - } - - @Override - public int hashCode() { - return Arrays.hashCode(bytes); - } - - @Override - public String toString() { - return toStringHelper(this) - .add("length", bytes.length) - .add("hash", Arrays.hashCode(bytes)) - .toString(); - } + private final byte[] bytes; + + public TestEntry(final int size) { + this(new byte[size]); + } + + public TestEntry(final byte[] bytes) { + this.bytes = bytes; + } + + public byte[] bytes() { + return bytes; + } + + @Override + public boolean equals(final Object obj) { + return this == obj || obj instanceof TestEntry other && Arrays.equals(bytes, other.bytes); + } + + @Override + public int hashCode() { + return Arrays.hashCode(bytes); + } + + @Override + public String toString() { + return toStringHelper(this).add("length", bytes.length).add("hash", Arrays.hashCode(bytes)).toString(); + } } diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntrySerdes.java b/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntrySerdes.java index 8ef4183261..0549c35438 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntrySerdes.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/TestEntrySerdes.java @@ -20,7 +20,7 @@ import io.atomix.storage.journal.JournalSerdes.EntryOutput; import io.atomix.storage.journal.JournalSerdes.EntrySerdes; import java.io.IOException; -@Deprecated(forRemoval = true, since="9.0.3") +@Deprecated(forRemoval = true, since = "9.0.3") final class TestEntrySerdes implements EntrySerdes { private static final ByteArraySerdes BA_SERIALIZER = new ByteArraySerdes(); diff --git a/atomix-storage/src/test/java/io/atomix/storage/journal/index/SparseJournalIndexTest.java b/atomix-storage/src/test/java/io/atomix/storage/journal/index/SparseJournalIndexTest.java index 204fdb86a3..c7002e9060 100644 --- a/atomix-storage/src/test/java/io/atomix/storage/journal/index/SparseJournalIndexTest.java +++ b/atomix-storage/src/test/java/io/atomix/storage/journal/index/SparseJournalIndexTest.java @@ -55,8 +55,8 @@ class SparseJournalIndexTest { assertNull(sparseIndex.lookup(8)); } - @Test - void secondTest() { + @Test + void secondTest() { assertNull(sparseIndex.lookup(100)); assertIndex(101, 2); assertNull(sparseIndex.lookup(1)); diff --git a/atomix-storage/src/test/java/io/atomix/utils/serializer/BufferAwareByteArrayOutputStreamTest.java b/atomix-storage/src/test/java/io/atomix/utils/serializer/BufferAwareByteArrayOutputStreamTest.java index a47d37831e..1c5e9cf609 100644 --- a/atomix-storage/src/test/java/io/atomix/utils/serializer/BufferAwareByteArrayOutputStreamTest.java +++ b/atomix-storage/src/test/java/io/atomix/utils/serializer/BufferAwareByteArrayOutputStreamTest.java @@ -15,21 +15,20 @@ */ package io.atomix.utils.serializer; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -public class BufferAwareByteArrayOutputStreamTest { - - @Test - public void testBufferSize() throws Exception { - BufferAwareByteArrayOutputStream outputStream = new BufferAwareByteArrayOutputStream(8); - assertEquals(8, outputStream.getBufferSize()); - outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}); - assertEquals(8, outputStream.getBufferSize()); - outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}); - assertEquals(16, outputStream.getBufferSize()); - outputStream.reset(); - assertEquals(16, outputStream.getBufferSize()); - } +class BufferAwareByteArrayOutputStreamTest { + @Test + void testBufferSize() throws Exception { + final var outputStream = new BufferAwareByteArrayOutputStream(8); + assertEquals(8, outputStream.getBufferSize()); + outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}); + assertEquals(8, outputStream.getBufferSize()); + outputStream.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}); + assertEquals(16, outputStream.getBufferSize()); + outputStream.reset(); + assertEquals(16, outputStream.getBufferSize()); + } } diff --git a/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoInputPoolTest.java b/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoInputPoolTest.java index 82a9629af5..7b84ba3bbd 100644 --- a/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoInputPoolTest.java +++ b/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoInputPoolTest.java @@ -15,55 +15,49 @@ */ package io.atomix.utils.serializer; -import com.esotericsoftware.kryo.io.Input; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; -public class KryoInputPoolTest { - - private KryoInputPool kryoInputPool; +import com.esotericsoftware.kryo.io.Input; +import org.junit.jupiter.api.Test; - @Before - public void setUp() throws Exception { - kryoInputPool = new KryoInputPool(); - } +class KryoInputPoolTest { + private final KryoInputPool kryoInputPool = new KryoInputPool(); - @Test - public void discardOutput() { - final Input[] result = new Input[2]; - kryoInputPool.run(input -> { - result[0] = input; - return null; - }, KryoInputPool.MAX_POOLED_BUFFER_SIZE + 1); - kryoInputPool.run(input -> { - result[1] = input; - return null; - }, 0); - assertTrue(result[0] != result[1]); - } + @Test + void discardOutput() { + final var result = new Input[2]; + kryoInputPool.run(input -> { + result[0] = input; + return null; + }, KryoInputPool.MAX_POOLED_BUFFER_SIZE + 1); + kryoInputPool.run(input -> { + result[1] = input; + return null; + }, 0); + assertNotSame(result[0], result[1]); + } - @Test - public void recycleOutput() { - final Input[] result = new Input[2]; - kryoInputPool.run(input -> { - assertEquals(0, input.position()); - byte[] payload = new byte[]{1, 2, 3, 4}; - input.setBuffer(payload); - assertArrayEquals(payload, input.readBytes(4)); - result[0] = input; - return null; - }, 0); - assertNull(result[0].getInputStream()); - assertEquals(0, result[0].position()); - kryoInputPool.run(input -> { - result[1] = input; - return null; - }, 0); - assertTrue(result[0] == result[1]); - } + @Test + void recycleOutput() { + final var result = new Input[2]; + kryoInputPool.run(input -> { + assertEquals(0, input.position()); + byte[] payload = new byte[]{1, 2, 3, 4}; + input.setBuffer(payload); + assertArrayEquals(payload, input.readBytes(4)); + result[0] = input; + return null; + }, 0); + assertNull(result[0].getInputStream()); + assertEquals(0, result[0].position()); + kryoInputPool.run(input -> { + result[1] = input; + return null; + }, 0); + assertSame(result[0], result[1]); + } } diff --git a/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoOutputPoolTest.java b/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoOutputPoolTest.java index 04d55d6fbd..caa57cd6e2 100644 --- a/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoOutputPoolTest.java +++ b/atomix-storage/src/test/java/io/atomix/utils/serializer/KryoOutputPoolTest.java @@ -15,52 +15,46 @@ */ package io.atomix.utils.serializer; -import com.esotericsoftware.kryo.io.Output; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; -public class KryoOutputPoolTest { - - private KryoOutputPool kryoOutputPool; +import com.esotericsoftware.kryo.io.Output; +import org.junit.jupiter.api.Test; - @Before - public void setUp() throws Exception { - kryoOutputPool = new KryoOutputPool(); - } +class KryoOutputPoolTest { + private final KryoOutputPool kryoOutputPool = new KryoOutputPool(); - @Test - public void discardOutput() { - final Output[] result = new Output[2]; - kryoOutputPool.run(output -> { - result[0] = output; - return null; - }, KryoOutputPool.MAX_POOLED_BUFFER_SIZE + 1); - kryoOutputPool.run(output -> { - result[1] = output; - return null; - }, 0); - assertTrue(result[0] != result[1]); - } + @Test + void discardOutput() { + final var result = new Output[2]; + kryoOutputPool.run(output -> { + result[0] = output; + return null; + }, KryoOutputPool.MAX_POOLED_BUFFER_SIZE + 1); + kryoOutputPool.run(output -> { + result[1] = output; + return null; + }, 0); + assertNotSame(result[0], result[1]); + } - @Test - public void recycleOutput() { - final ByteArrayOutput[] result = new ByteArrayOutput[2]; - kryoOutputPool.run(output -> { - output.writeInt(1); - assertEquals(Integer.BYTES, output.position()); - result[0] = output; - return null; - }, 0); - assertEquals(0, result[0].position()); - assertEquals(0, result[0].getByteArrayOutputStream().size()); - kryoOutputPool.run(output -> { - assertEquals(0, output.position()); - result[1] = output; - return null; - }, 0); - assertTrue(result[0] == result[1]); - } + @Test + void recycleOutput() { + final var result = new ByteArrayOutput[2]; + kryoOutputPool.run(output -> { + output.writeInt(1); + assertEquals(Integer.BYTES, output.position()); + result[0] = output; + return null; + }, 0); + assertEquals(0, result[0].position()); + assertEquals(0, result[0].getByteArrayOutputStream().size()); + kryoOutputPool.run(output -> { + assertEquals(0, output.position()); + result[1] = output; + return null; + }, 0); + assertSame(result[0], result[1]); + } }