spuru9 commented on code in PR #29113:
URL: https://github.com/apache/flink/pull/29113#discussion_r4721004102


##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogMetricGroupTest.java:
##########
@@ -81,69 +80,71 @@ public class ChangelogMetricGroupTest {
     private Gauge<Long> lastIncSizeOfNonMaterializationGauge;
 
     @Test
-    public void testCompletedMaterialization() throws Exception {
+    void testCompletedMaterialization() throws Exception {
         setup(snapshotResult -> snapshotResult);
 
         // The materialization will be skipped if no data updated.
-        assertEquals(-1L, 
lastDurationOfMaterializationGauge.getValue().longValue());
+        
assertThat(lastDurationOfMaterializationGauge.getValue()).isEqualTo(-1L);
         periodicMaterializationManager.triggerMaterialization();
         runSnapshot(1L);
-        assertEquals(1L, startedMaterializationCounter.getCount());
-        assertEquals(1L, completedMaterializationCounter.getCount());
-        assertNotEquals(-1L, 
lastDurationOfMaterializationGauge.getValue().longValue());
-        assertEquals(0L, 
lastFullSizeOfMaterializationGauge.getValue().longValue());
-        assertEquals(0L, 
lastIncSizeOfMaterializationGauge.getValue().longValue());
-        assertEquals(0L, 
lastFullSizeOfNonMaterializationGauge.getValue().longValue());
-        assertEquals(0L, 
lastIncSizeOfNonMaterializationGauge.getValue().longValue());
+        assertThat(startedMaterializationCounter.getCount()).isEqualTo(1L);
+        assertThat(completedMaterializationCounter.getCount()).isEqualTo(1L);

Review Comment:
   nit: Could you use `isZero()` / `isOne()` / `isNotZero()` instead of 
comparing to `0L` / `1L`? Applies to all the counter and gauge checks in both 
tests.
   
   ```suggestion
           assertThat(startedMaterializationCounter.getCount()).isOne();
           assertThat(completedMaterializationCounter.getCount()).isOne();
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogListStateTest.java:
##########
@@ -94,15 +92,15 @@ private <T> void testIterator(
 
         Iterator iterator = iteratorSupplier.apply(state);
         for (T el : elements) {
-            assertTrue(iterator.hasNext());
-            assertEquals(el, iterator.next());
+            assertThat(iterator.hasNext()).isTrue();
+            assertThat(iterator.next()).isEqualTo(el);
             iterator.remove();
         }
 
-        assertFalse(iterator.hasNext());
-        assertTrue(state.getInternal().isEmpty());
+        assertThat(iterator.hasNext()).isFalse();
+        assertThat(state.getInternal().isEmpty()).isTrue();

Review Comment:
   nit: AssertJ has iterator and list assertions for this. Same loop in 
`ChangelogMapStateTest` and `ChangelogPqStateTest`, where `state.isEmpty()` has 
to stay as is.
   
   ```suggestion
               assertThat(iterator).hasNext();
               assertThat(iterator.next()).isEqualTo(el);
               iterator.remove();
           }
   
           assertThat(iterator).isExhausted();
           assertThat(state.getInternal()).isEmpty();
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogStateDiscardTest.java:
##########
@@ -337,15 +337,15 @@ private static List<UploadResult> uploadResult(
     }
 
     private static void assertRetained(List<TestingStreamStateHandle> 
toRetain) {
-        assertTrue(
-                "Some state handles were discarded: \n" + toRetain,
-                
toRetain.stream().noneMatch(TestingStreamStateHandle::isDisposed));
+        
assertThat(toRetain.stream().noneMatch(TestingStreamStateHandle::isDisposed))
+                .as("Some state handles were discarded: \n" + toRetain)
+                .isTrue();
     }
 
     private static void assertDiscarded(List<TestingStreamStateHandle> 
toDiscard) {
-        assertTrue(
-                "Not all state handles were discarded: \n" + toDiscard,
-                
toDiscard.stream().allMatch(TestingStreamStateHandle::isDisposed));
+        
assertThat(toDiscard.stream().allMatch(TestingStreamStateHandle::isDisposed))
+                .as("Not all state handles were discarded: \n" + toDiscard)
+                .isTrue();
     }

Review Comment:
   nit: `noneMatch` / `allMatch` on the list already print the failing 
elements, so we don't need to concatenate the list into the message.
   
   ```suggestion
       private static void assertRetained(List<TestingStreamStateHandle> 
toRetain) {
           assertThat(toRetain)
                   .as("Some state handles were discarded")
                   .noneMatch(TestingStreamStateHandle::isDisposed);
       }
   
       private static void assertDiscarded(List<TestingStreamStateHandle> 
toDiscard) {
           assertThat(toDiscard)
                   .as("Not all state handles were discarded")
                   .allMatch(TestingStreamStateHandle::isDisposed);
       }
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogDelegateStateTest.java:
##########
@@ -121,15 +123,15 @@ private void testDelegatingState(StateDescriptor 
descriptor, Class<?> stateClass
                     changelogBackend.getPartitionedState(
                             VoidNamespace.INSTANCE, 
VoidNamespaceSerializer.INSTANCE, descriptor);
 
-            assertSame(state.getClass(), stateClass);
-            assertSame(
-                    ((AbstractChangelogState<?, ?, ?, ?>) 
state).getDelegatedState().getClass(),
-                    delegatedBackend
-                            .getPartitionedState(
-                                    VoidNamespace.INSTANCE,
-                                    VoidNamespaceSerializer.INSTANCE,
-                                    descriptor)
-                            .getClass());
+            assertThat(state.getClass()).isSameAs(stateClass);
+            assertThat(((AbstractChangelogState<?, ?, ?, ?>) 
state).getDelegatedState().getClass())
+                    .isSameAs(
+                            delegatedBackend
+                                    .getPartitionedState(
+                                            VoidNamespace.INSTANCE,
+                                            VoidNamespaceSerializer.INSTANCE,
+                                            descriptor)
+                                    .getClass());

Review Comment:
   nit: `isExactlyInstanceOf` reads better than `getClass()` plus `isSameAs`.
   
   ```suggestion
               assertThat(state).isExactlyInstanceOf(stateClass);
               assertThat(((AbstractChangelogState<?, ?, ?, ?>) 
state).getDelegatedState())
                       .isExactlyInstanceOf(
                               delegatedBackend
                                       .getPartitionedState(
                                               VoidNamespace.INSTANCE,
                                               VoidNamespaceSerializer.INSTANCE,
                                               descriptor)
                                       .getClass());
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogStateBackendLoadingTest.java:
##########
@@ -228,11 +237,10 @@ private void assertDelegateStateBackend(
             Class<?> delegatedStateBackendClass,
             CheckpointStorage storage,
             Class<?> storageClass) {
-        assertTrue(backend instanceof ChangelogStateBackend);
-        assertSame(
-                ((DelegatingStateBackend) 
backend).getDelegatedStateBackend().getClass(),
-                delegatedStateBackendClass);
-        assertSame(storage.getClass(), storageClass);
+        assertThat(backend).isInstanceOf(ChangelogStateBackend.class);
+        assertThat(((DelegatingStateBackend) 
backend).getDelegatedStateBackend().getClass())
+                .isSameAs(delegatedStateBackendClass);
+        assertThat(storage.getClass()).isSameAs(storageClass);

Review Comment:
   nit: Same here.
   
   ```suggestion
           assertThat(((DelegatingStateBackend) 
backend).getDelegatedStateBackend())
                   .isExactlyInstanceOf(delegatedStateBackendClass);
           assertThat(storage).isExactlyInstanceOf(storageClass);
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogStateBackendLoadingTest.java:
##########
@@ -90,13 +89,16 @@ public void testApplicationDefinedHasPrecedence() throws 
Exception {
 
         assertDelegateStateBackend(
                 backend, MockStateBackend.class, storage, 
MockStateBackend.class);
-        assertTrue(
-                ((MockStateBackend) (((ChangelogStateBackend) 
backend).getDelegatedStateBackend()))
-                        .isConfigUpdated());
+        assertThat(
+                        ((MockStateBackend)
+                                        (((ChangelogStateBackend) backend)
+                                                .getDelegatedStateBackend()))
+                                .isConfigUpdated())
+                .isTrue();

Review Comment:
   nit: Spotless made this cast hard to read. Could we use 
`isInstanceOfSatisfying` here and in the next test?
   
   ```suggestion
           assertThat(((ChangelogStateBackend) 
backend).getDelegatedStateBackend())
                   .isInstanceOfSatisfying(
                           MockStateBackend.class, b -> 
assertThat(b.isConfigUpdated()).isTrue());
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogStateBackendLoadingTest.java:
##########
@@ -125,49 +130,53 @@ public void testApplicationEnableChangelogStateBackend() 
throws Exception {
     }
 
     @Test
-    public void testApplicationDisableChangelogStateBackend() throws Exception 
{
+    void testApplicationDisableChangelogStateBackend() throws Exception {
         final StateBackend backend =
                 StateBackendLoader.fromApplicationOrConfigOrDefault(
                         null, config(false), config(true), cl, null);
 
-        assertTrue(backend instanceof HashMapStateBackend);
+        assertThat(backend).isInstanceOf(HashMapStateBackend.class);
     }
 
     @Test
-    public void testLoadingChangelogForRecovery() throws Exception {
+    void testLoadingChangelogForRecovery() throws Exception {
         final StateBackend backend =
                 StateBackendLoader.loadStateBackendFromKeyedStateHandles(
                         new MockStateBackend(),
                         cl,
                         Collections.singletonList(
                                 
ChangelogTestUtils.createChangelogStateBackendHandle()));
 
-        assertTrue(backend instanceof DeactivatedChangelogStateBackend);
+        
assertThat(backend).isInstanceOf(DeactivatedChangelogStateBackend.class);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testRecursiveDelegation() throws Exception {
-        final StateBackend appBackend =
-                new ChangelogStateBackend(new ChangelogStateBackend(new 
MockStateBackend()));
-
-        StateBackendLoader.fromApplicationOrConfigOrDefault(
-                appBackend, config("rocksdb", true), config(), cl, null);
+    @Test
+    void testRecursiveDelegation() {
+        assertThatThrownBy(
+                        () -> {
+                            final StateBackend appBackend =
+                                    new ChangelogStateBackend(
+                                            new ChangelogStateBackend(new 
MockStateBackend()));
+                            
StateBackendLoader.fromApplicationOrConfigOrDefault(
+                                    appBackend, config("rocksdb", true), 
config(), cl, null);
+                        })
+                .isInstanceOf(IllegalArgumentException.class);
     }

Review Comment:
   nit: The IAE actually comes from the `ChangelogStateBackend` constructor, so 
the loader call never runs. Could we assert on the constructor and check the 
message?
   
   ```suggestion
       @Test
       void testRecursiveDelegation() {
           assertThatThrownBy(
                           () ->
                                   new ChangelogStateBackend(
                                           new ChangelogStateBackend(new 
MockStateBackend())))
                   .isInstanceOf(IllegalArgumentException.class)
                   .hasMessage("Recursive Delegation is not supported.");
       }
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogDelegateStateTest.java:
##########
@@ -32,74 +32,76 @@
 import org.apache.flink.runtime.state.VoidNamespaceSerializer;
 import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
 import org.apache.flink.state.rocksdb.EmbeddedRocksDBStateBackend;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameter;
+import 
org.apache.flink.testutils.junit.extensions.parameterized.ParameterizedTestExtension;
+import org.apache.flink.testutils.junit.extensions.parameterized.Parameters;
 import org.apache.flink.util.IOUtils;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.TestTemplate;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 import java.util.Arrays;
 import java.util.List;
 import java.util.function.Supplier;
 
 import static 
org.apache.flink.state.changelog.ChangelogStateBackendTestUtils.DummyCheckpointingStorageAccess;
 import static 
org.apache.flink.state.changelog.ChangelogStateBackendTestUtils.createKeyedBackend;
-import static org.junit.Assert.assertSame;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /** Tests for {@link ChangelogStateBackend} delegating state accesses. */
-@RunWith(Parameterized.class)
-public class ChangelogDelegateStateTest {
+@ExtendWith(ParameterizedTestExtension.class)
+class ChangelogDelegateStateTest {
     private MockEnvironment env;
 
-    @Parameterized.Parameters
+    @Parameters
     public static List<Supplier<AbstractStateBackend>> delegatedStateBackend() 
{
         return Arrays.asList(HashMapStateBackend::new, 
EmbeddedRocksDBStateBackend::new);
     }
 
-    @Parameterized.Parameter public Supplier<AbstractStateBackend> backend;
+    @Parameter public Supplier<AbstractStateBackend> backend;

Review Comment:
   nit: Could we use `List.of` here? The provider and the `@Parameter` field 
also don't need `public`, since `ParameterizedTestExtension` makes them 
accessible. Same for `parameters()` and the two fields in 
`ChangelogKeyedStateBackendTest`, and `List.of` in 
`ChangelogListStateTest#testAddAllRecorded`.
   
   ```suggestion
       @Parameters
       static List<Supplier<AbstractStateBackend>> delegatedStateBackend() {
           return List.of(HashMapStateBackend::new, 
EmbeddedRocksDBStateBackend::new);
       }
   
       @Parameter Supplier<AbstractStateBackend> backend;
   ```



##########
flink-state-backends/flink-statebackend-changelog/src/test/java/org/apache/flink/state/changelog/ChangelogStateBackendLoadingTest.java:
##########
@@ -49,37 +49,36 @@
 import org.apache.flink.util.Collector;
 import org.apache.flink.util.TernaryBoolean;
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
+import java.nio.file.Path;
 import java.util.Collections;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 /** Verify Changelog StateBackend is properly loaded. */
-public class ChangelogStateBackendLoadingTest {
-    @Rule public final TemporaryFolder tmp = new TemporaryFolder();
+class ChangelogStateBackendLoadingTest {
+    @TempDir Path tmp;

Review Comment:
   nit: `tmp` isn't used anywhere (the old rule wasn't either). Could you drop 
it together with the `TempDir` and `Path` imports?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to