Modernize tests and fixup checkstyle 65/111665/3
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 8 May 2024 16:45:41 +0000 (18:45 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 8 May 2024 17:55:34 +0000 (17:55 +0000)
Reformat for checkstyle compliance and modernize with JUnit5, etc.

Change-Id: I6fab572f429578e6be924f6d8bcffcc6d083d333
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
22 files changed:
atomix-storage/src/main/java/io/atomix/storage/journal/ByteBufReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentDescriptor.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSegmentReader.java
atomix-storage/src/main/java/io/atomix/storage/journal/JournalSerdes.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentEntry.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedByteBufJournal.java
atomix-storage/src/main/java/io/atomix/storage/journal/SegmentedJournal.java
atomix-storage/src/main/java/io/atomix/utils/serializer/EntrySerializer.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryInput.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoEntryOutput.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdes.java
atomix-storage/src/main/java/io/atomix/utils/serializer/KryoJournalSerdesBuilder.java
atomix-storage/src/main/java/io/atomix/utils/serializer/RegisteredType.java
atomix-storage/src/test/java/io/atomix/storage/journal/AbstractJournalTest.java
atomix-storage/src/test/java/io/atomix/storage/journal/ByteArraySerdes.java
atomix-storage/src/test/java/io/atomix/storage/journal/JournalSegmentFileTest.java
atomix-storage/src/test/java/io/atomix/storage/journal/TestEntry.java
atomix-storage/src/test/java/io/atomix/storage/journal/TestEntrySerdes.java
atomix-storage/src/test/java/io/atomix/storage/journal/index/SparseJournalIndexTest.java
atomix-storage/src/test/java/io/atomix/utils/serializer/BufferAwareByteArrayOutputStreamTest.java
atomix-storage/src/test/java/io/atomix/utils/serializer/KryoInputPoolTest.java
atomix-storage/src/test/java/io/atomix/utils/serializer/KryoOutputPoolTest.java

index 205857533dcfc3498507576755dfa91bf17ebc8c..ad447025372696eee68380772f9f739f02804431 100644 (file)
@@ -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}
index 97dbab72ef3c5ac45c9a0cc3d144ad8b64d91ddf..e64110e675919e4ce65ca164f69f2b61ee45b97f 100644 (file)
@@ -24,6 +24,7 @@ import org.eclipse.jdt.annotation.Nullable;
 
 /**
  * Stores information about a {@link JournalSegment} of the log.
+ *
  * <p>
  * 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.
+     *
      * <p>
      * Versions are monotonically increasing starting at {@code 1}.
      *
@@ -104,6 +106,7 @@ public record JournalSegmentDescriptor(
 
     /**
      * Returns the segment identifier.
+     *
      * <p>
      * 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.
+     *
      * <p>
-     * 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.
+     *
      * <p>
-     * 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.
+     *
      * <p>
      * 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.
index aa4c0da18a9e59ea5b8cef851c992a63256b6143..e925ef8bb1e020719bc83b04c12480d25bba8917 100644 (file)
@@ -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}
      */
index 9d6d6ee9927b817f56f528725692a4c2e4a28044..29b5bed7ab6ac75c570ca1187e614463e2680613 100644 (file)
@@ -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 <T>    deserialized Object type
      * @return deserialized Object
      */
-    <T> T deserialize(final ByteBuffer buffer);
+    <T> 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> T deserialize(final InputStream stream, final int bufferSize);
+    <T> 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.
+         *
          * <p>
          * When multiple classes are registered with an explicitly provided serializer, the namespace guarantees
          * all instances will be serialized with the same type ID.
index 432f9b9dec0395385c8e930c7eae3bbd51307ab2..a18bd5eecdc751daa1e93ad163160811777e605d 100644 (file)
@@ -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
      * <ul>
      *   <li>32-bit signed entry length</li>
      *   <li>32-bit unsigned CRC32 checksum</li>
-     * </li>
+     * </ul>
      */
     static final int HEADER_BYTES = Integer.BYTES + Integer.BYTES;
 
index 4698a5fd60bfb548f5f25f9335ca8eab87141e70..0d42181851f5c4d7e587e64180e65ba97f35baed 100644 (file)
@@ -392,6 +392,7 @@ public final class SegmentedByteBufJournal implements ByteBufJournal {
 
     /**
      * Compacts the journal up to the given index.
+     *
      * <p>
      * 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.
+         *
          * <p>
          * 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.
+         *
          * <p>
          * 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.
+         *
          * <p>
          * 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.
index f6c976742c52573b58e07d0a26e1167ebd50eeac..35b0cb87bc47dd6f58f127bd07155d1c3a33c27d 100644 (file)
@@ -72,6 +72,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
     /**
      * Compacts the journal up to the given index.
+     *
      * <p>
      * The semantics of compaction are not specified by this interface.
      *
@@ -111,6 +112,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
         /**
          * Sets the journal storage level.
+         *
          * <p>
          * The storage level indicates how individual entries will be persisted in the journal.
          *
@@ -124,6 +126,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
         /**
          * Sets the journal storage directory.
+         *
          * <p>
          * The journal will write segment files into the provided directory.
          *
@@ -138,6 +141,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
         /**
          * Sets the journal storage directory.
+         *
          * <p>
          * The journal will write segment files into the provided directory.
          *
@@ -146,7 +150,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
          * @throws NullPointerException If the {@code directory} is {@code null}
          */
         public Builder<E> withDirectory(final File directory) {
-             byteJournalBuilder.withDirectory(directory);
+            byteJournalBuilder.withDirectory(directory);
             return this;
         }
 
@@ -157,7 +161,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
          * @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<E> withNamespace(final JournalSerdes namespace) {
             return withMapper(requireNonNull(namespace, "namespace cannot be null").toMapper());
         }
@@ -175,10 +179,12 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
         /**
          * Sets the maximum segment size in bytes.
+         *
          * <p>
          * 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.
+         *
          * <p>
          * By default, the maximum segment size is 32M.
          *
@@ -218,6 +224,7 @@ public final class SegmentedJournal<E> implements Journal<E> {
 
         /**
          * Sets the journal index density.
+         *
          * <p>
          * 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<E> implements Journal<E> {
 
         /**
          * Enables flushing buffers to disk when entries are committed to a segment.
+         *
          * <p>
          * 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<E> implements Journal<E> {
 
         /**
          * Enables flushing buffers to disk when entries are committed to a segment.
+         *
          * <p>
          * 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.
index f8355244b1657897900716fa9adaf23766d8a35c..accd9943d3e4026395bf710fabd585cdd6d67066 100644 (file)
@@ -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<T> extends Serializer<T> {
     // Note: uses identity to create things in Kryo, hence we want an instance for every serdes we wrap
     private final JavaSerializer javaSerializer = new JavaSerializer();
index 1c0e500928e8cf5e07be5e326bf541b2b2cb97e2..e1dea856cb7a5592c1728e6b2b01a0e689422881 100644 (file)
@@ -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;
index 5e9133290683062d8ad151a51833ca431a30f3f7..d4724b986b2f956c991c86adb9342bcc416e0f34 100644 (file)
@@ -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;
index 7742f981c64830852f2fcc221bcb7b8d6b00aa92..e8ddcdeb8718c2a66c588bb806651460de959b0d 100644 (file)
@@ -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());
             }
         }
     }
index 0caf7eaca6a3780830572f3f84b6b8160456b2f3..779da00278adf5bc3b4d09f82f4f796f401d6822 100644 (file)
@@ -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<RegisteredType> 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
+}
index 79cccbe4e367086deac8751509d78e49a185a0e8..1d6cf8054779b5bfc757e531df1758e705be7857 100644 (file)
@@ -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);
index 6118f600cd04291385aa58967e2c0bfad4fd86fe..05a758a366c4ce72ad1160ec1e6177f516febfc4 100644 (file)
@@ -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<TestEntry> journal = createJournal()) {
-            JournalWriter<TestEntry> writer = journal.writer();
-            JournalReader<TestEntry> 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<TestEntry> journal = createJournal()) {
             JournalWriter<TestEntry> writer = journal.writer();
             JournalReader<TestEntry> 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());
         }
     }
 
index c8789b829fabb69ed6c3c40f1d95f0cc877cc61c..8569099d447702df2bd0b11217c1918d8b605820 100644 (file)
@@ -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<byte[]> {
     @Override
     public byte[] read(final EntryInput input) throws IOException {
index 114ae094b50f8f870071d9b28395559552e62529..312a9f6c3231e2cf5ca007a85c65bd7d75b36f01 100644 (file)
  */
 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));
+    }
 }
index 76cf828d02e6d251819193f5113bf9f4ff3dc28a..93e4d38fe18cd5ae76dd16dc61348e3eb91600b1 100644 (file)
@@ -25,35 +25,32 @@ import java.util.Arrays;
  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
  */
 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();
+    }
 }
index 8ef4183261f2e05a3942687c44874883d78d6fa1..0549c354383f381b0e8fba1a5b2dc368396631a7 100644 (file)
@@ -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<TestEntry> {
     private static final ByteArraySerdes BA_SERIALIZER = new ByteArraySerdes();
 
index 204fdb86a3f16cbf0447507e193de2ea336d7e41..c7002e90606f03b8541d7924f95972f523075cf6 100644 (file)
@@ -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));
index a47d37831ea12d179f12a9a4c6af74ea40b7d237..1c5e9cf609f15e6e65dab5a12d0064fbfaafebe9 100644 (file)
  */
 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());
+    }
 }
index 82a9629af560d8db1a55d1c1af82850b6dc5ab54..7b84ba3bbd514da6047c08535e5a2e6d394e2c9c 100644 (file)
  */
 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]);
+    }
 }
index 04d55d6fbdc09fe282c645aa03e2a5c9b4c02588..caa57cd6e220e7b9495211599e82a31ca6fbc318 100644 (file)
  */
 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]);
+    }
 }