ferenc-csaky commented on code in PR #8:
URL: 
https://github.com/apache/flink-connector-kudu/pull/8#discussion_r1980080222


##########
flink-connector-kudu/src/test/java/org/apache/flink/connector/kudu/source/KuduSourceITCase.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kudu.source;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.connector.source.Boundedness;
+import org.apache.flink.client.program.ClusterClient;
+import 
org.apache.flink.connector.kudu.connector.converter.RowResultRowConverter;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.test.junit5.InjectClusterClient;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+import org.apache.flink.types.Row;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.time.Duration;
+import java.util.Queue;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.function.Supplier;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+/** IT cases for using Kudu Source. */
+public class KuduSourceITCase extends KuduSourceTestBase {
+    @RegisterExtension
+    private static final MiniClusterExtension MINI_CLUSTER_RESOURCE =
+            new MiniClusterExtension(
+                    new MiniClusterResourceConfiguration.Builder()
+                            .setNumberTaskManagers(2)
+                            .build());
+
+    public static StreamExecutionEnvironment env;
+
+    private static Queue<Row> collectedRecords;
+
+    @BeforeEach
+    public void init() throws Exception {
+        super.init();
+        env = StreamExecutionEnvironment.getExecutionEnvironment();
+        collectedRecords = new ConcurrentLinkedDeque<>();
+    }
+
+    @Test
+    public void testRecordsFromSourceUnbounded(@InjectClusterClient 
ClusterClient<?> client)
+            throws Exception {
+
+        KuduSource<Row> kuduSource =
+                new KuduSourceBuilder<Row>()
+                        .setReaderConfig(getReaderConfig())
+                        .setTableInfo(getTableInfo())
+                        .setRowResultConverter(new RowResultRowConverter())
+                        .setBoundedness(Boundedness.CONTINUOUS_UNBOUNDED)
+                        .setDiscoveryPeriod(Duration.ofSeconds(1))
+                        .build();
+
+        env.fromSource(kuduSource, WatermarkStrategy.noWatermarks(), 
"KuduSource")
+                .returns(TypeInformation.of(Row.class))
+                .addSink(new TestingSinkFunction());
+
+        JobID jobID = env.executeAsync().getJobID();
+        waitExpectation(() -> collectedRecords.size() == 10);
+        assertThat(collectedRecords.size()).isEqualTo(10);
+        insertRows(10);
+        waitExpectation(() -> collectedRecords.size() == 20);
+        assertThat(collectedRecords.size()).isEqualTo(20);
+        client.cancel(jobID);
+    }
+
+    @Test
+    public void testRecordsFromSourceBounded() throws Exception {
+
+        KuduSource<Row> kuduSource =
+                new KuduSourceBuilder<Row>()
+                        .setReaderConfig(getReaderConfig())
+                        .setTableInfo(getTableInfo())
+                        .setRowResultConverter(new RowResultRowConverter())
+                        .build();
+
+        env.fromSource(kuduSource, WatermarkStrategy.noWatermarks(), 
"KuduSource")
+                .returns(TypeInformation.of(Row.class))
+                .addSink(new TestingSinkFunction());
+
+        env.execute();
+        assertThat(collectedRecords.size()).isEqualTo(10);
+    }
+
+    private static void sleep(long millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static void waitExpectation(Supplier<Boolean> condition) throws 
Exception {
+        CompletableFuture<Void> future =
+                CompletableFuture.runAsync(
+                        () -> {
+                            while (true) {
+                                if (condition.get()) {
+                                    break;
+                                }
+                                sleep(50);
+                            }

Review Comment:
   Since the `sleep` method is only used here IMO it makes sense to merge it 
into and also simplify the condition check, something like:
   ```java
   while (!condition.get()) {
       try {
           Thread.sleep(50);
       } catch (InterruptedException e) {
           throw new RuntimeException(e);
       }
   }
   ```



##########
flink-connector-kudu/src/test/java/org/apache/flink/connector/kudu/source/enumerator/KuduSourceEnumeratorStateSerializerTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kudu.source.enumerator;
+
+import org.apache.flink.connector.kudu.source.split.KuduSourceSplit;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+/** Tests for {@link KuduSourceEnumeratorStateSerializer}. */
+public class KuduSourceEnumeratorStateSerializerTest {
+    private final KuduSourceEnumeratorStateSerializer serializer =
+            new KuduSourceEnumeratorStateSerializer();
+
+    @Test
+    public void testSerializeDeserialize() throws IOException {
+        byte[] token1 = {1, 2, 3};
+        byte[] token2 = {4, 5, 6};
+        byte[] token3 = {7, 8, 9};
+        byte[] token4 = {10, 11, 12};
+
+        List<KuduSourceSplit> unassigned =
+                Arrays.asList(new KuduSourceSplit(token1), new 
KuduSourceSplit(token2));
+        List<KuduSourceSplit> pending =
+                Arrays.asList(new KuduSourceSplit(token3), new 
KuduSourceSplit(token4));
+        KuduSourceEnumeratorState state =
+                new KuduSourceEnumeratorState(12345L, unassigned, pending);
+
+        byte[] serialized = serializer.serialize(state);
+        KuduSourceEnumeratorState deserialized =
+                serializer.deserialize(serializer.getVersion(), serialized);
+
+        
assertThat(state.getLastEndTimestamp()).isEqualTo(deserialized.getLastEndTimestamp());
+        
assertThat(state.getUnassigned().size()).isEqualTo(deserialized.getUnassigned().size());
+        
assertThat(state.getPending().size()).isEqualTo(deserialized.getPending().size());
+
+        for (KuduSourceSplit split : unassigned) {
+            assertThat(split.getSerializedScanToken())
+                    .isEqualTo(
+                            deserialized.getUnassigned().stream()
+                                    .filter(
+                                            dSplit ->
+                                                    Arrays.equals(
+                                                            
dSplit.getSerializedScanToken(),
+                                                            
split.getSerializedScanToken()))
+                                    .findFirst()
+                                    .orElseThrow(() -> new 
AssertionError("Missing expected split"))
+                                    .getSerializedScanToken());
+        }
+
+        for (KuduSourceSplit split : pending) {
+            assertThat(split.getSerializedScanToken())
+                    .isEqualTo(
+                            deserialized.getPending().stream()
+                                    .filter(
+                                            dSplit ->
+                                                    Arrays.equals(
+                                                            
dSplit.getSerializedScanToken(),
+                                                            
split.getSerializedScanToken()))
+                                    .findFirst()
+                                    .orElseThrow(() -> new 
AssertionError("Missing expected split"))
+                                    .getSerializedScanToken());
+        }
+    }
+
+    @Test
+    public void testSerializeDeserializeEmptyLists() throws IOException {
+        KuduSourceEnumeratorState state =
+                new KuduSourceEnumeratorState(
+                        67890L, Collections.emptyList(), 
Collections.emptyList());
+
+        byte[] serialized = serializer.serialize(state);
+        KuduSourceEnumeratorState deserialized =
+                serializer.deserialize(serializer.getVersion(), serialized);
+
+        
assertThat(state.getLastEndTimestamp()).isEqualTo(deserialized.getLastEndTimestamp());
+        assertThat(deserialized.getUnassigned().size()).isEqualTo(0);
+        assertThat(deserialized.getPending().size()).isEqualTo(0);

Review Comment:
   After the correct import, size checks can be simplified:
   ```java
   assertThat(deserialized.getUnassigned()).isEmpty();
   assertThat(deserialized.getPending()).isEmpty();
   ```



##########
flink-connector-kudu/src/test/java/org/apache/flink/connector/kudu/source/enumerator/KuduSourceEnumeratorStateSerializerTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kudu.source.enumerator;
+
+import org.apache.flink.connector.kudu.source.split.KuduSourceSplit;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+/** Tests for {@link KuduSourceEnumeratorStateSerializer}. */
+public class KuduSourceEnumeratorStateSerializerTest {
+    private final KuduSourceEnumeratorStateSerializer serializer =
+            new KuduSourceEnumeratorStateSerializer();
+
+    @Test
+    public void testSerializeDeserialize() throws IOException {
+        byte[] token1 = {1, 2, 3};
+        byte[] token2 = {4, 5, 6};
+        byte[] token3 = {7, 8, 9};
+        byte[] token4 = {10, 11, 12};
+
+        List<KuduSourceSplit> unassigned =
+                Arrays.asList(new KuduSourceSplit(token1), new 
KuduSourceSplit(token2));
+        List<KuduSourceSplit> pending =
+                Arrays.asList(new KuduSourceSplit(token3), new 
KuduSourceSplit(token4));
+        KuduSourceEnumeratorState state =
+                new KuduSourceEnumeratorState(12345L, unassigned, pending);
+
+        byte[] serialized = serializer.serialize(state);
+        KuduSourceEnumeratorState deserialized =
+                serializer.deserialize(serializer.getVersion(), serialized);
+
+        
assertThat(state.getLastEndTimestamp()).isEqualTo(deserialized.getLastEndTimestamp());
+        
assertThat(state.getUnassigned().size()).isEqualTo(deserialized.getUnassigned().size());
+        
assertThat(state.getPending().size()).isEqualTo(deserialized.getPending().size());

Review Comment:
   Correct me if I'm wrong, but it seems to me that `deserialized` will be the 
actual test result and `state` contains the expected values. If so, these 
checks should be inserted, in AssertJ `assertThat(...)` should always contain 
the actual value, not the expected. Reagrdless of this, the size comparison can 
be simplified like:
   ```java
   
assertThat(deserialized.getLastEndTimestamp()).isEqualTo(state.getLastEndTimestamp());
   
assertThat(deserialized.getUnassigned()).hasSameSizeAs(state.getUnassigned());
   assertThat(deserialized.getPending()).hasSameSizeAs(state.getPending());
   ```



##########
flink-connector-kudu/src/test/java/org/apache/flink/connector/kudu/source/enumerator/KuduSourceEnumeratorStateSerializerTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kudu.source.enumerator;
+
+import org.apache.flink.connector.kudu.source.split.KuduSourceSplit;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+
+/** Tests for {@link KuduSourceEnumeratorStateSerializer}. */
+public class KuduSourceEnumeratorStateSerializerTest {
+    private final KuduSourceEnumeratorStateSerializer serializer =
+            new KuduSourceEnumeratorStateSerializer();
+
+    @Test
+    public void testSerializeDeserialize() throws IOException {
+        byte[] token1 = {1, 2, 3};
+        byte[] token2 = {4, 5, 6};
+        byte[] token3 = {7, 8, 9};
+        byte[] token4 = {10, 11, 12};
+
+        List<KuduSourceSplit> unassigned =
+                Arrays.asList(new KuduSourceSplit(token1), new 
KuduSourceSplit(token2));
+        List<KuduSourceSplit> pending =
+                Arrays.asList(new KuduSourceSplit(token3), new 
KuduSourceSplit(token4));
+        KuduSourceEnumeratorState state =
+                new KuduSourceEnumeratorState(12345L, unassigned, pending);
+
+        byte[] serialized = serializer.serialize(state);
+        KuduSourceEnumeratorState deserialized =
+                serializer.deserialize(serializer.getVersion(), serialized);
+
+        
assertThat(state.getLastEndTimestamp()).isEqualTo(deserialized.getLastEndTimestamp());
+        
assertThat(state.getUnassigned().size()).isEqualTo(deserialized.getUnassigned().size());
+        
assertThat(state.getPending().size()).isEqualTo(deserialized.getPending().size());
+
+        for (KuduSourceSplit split : unassigned) {
+            assertThat(split.getSerializedScanToken())
+                    .isEqualTo(
+                            deserialized.getUnassigned().stream()
+                                    .filter(
+                                            dSplit ->
+                                                    Arrays.equals(
+                                                            
dSplit.getSerializedScanToken(),
+                                                            
split.getSerializedScanToken()))
+                                    .findFirst()
+                                    .orElseThrow(() -> new 
AssertionError("Missing expected split"))
+                                    .getSerializedScanToken());
+        }
+
+        for (KuduSourceSplit split : pending) {
+            assertThat(split.getSerializedScanToken())
+                    .isEqualTo(
+                            deserialized.getPending().stream()
+                                    .filter(
+                                            dSplit ->
+                                                    Arrays.equals(
+                                                            
dSplit.getSerializedScanToken(),
+                                                            
split.getSerializedScanToken()))
+                                    .findFirst()
+                                    .orElseThrow(() -> new 
AssertionError("Missing expected split"))
+                                    .getSerializedScanToken());
+        }

Review Comment:
   This could be simplified if we use a traditional `for` loop:
   ```java
   for (int i = 0; i < unassigned.size(); i++) {
       byte[] expected = unassigned.get(i).getSerializedScanToken();
       assertThat(deserialized.getUnassigned().get(i).getSerializedScanToken())
               .isEqualTo(expected);
   }
   
   for (int i = 0; i < pending.size(); i++) {
       byte[] expected = pending.get(i).getSerializedScanToken();
       assertThat(deserialized.getPending().get(i).getSerializedScanToken())
               .isEqualTo(expected);
   }
   ```



##########
flink-connector-kudu/src/test/java/org/apache/flink/connector/kudu/source/enumerator/KuduSourceEnumeratorStateSerializerTest.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kudu.source.enumerator;
+
+import org.apache.flink.connector.kudu.source.split.KuduSourceSplit;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

Review Comment:
   Make sure to import from the `org.assertj.core.api.Assertions` class, cause 
it's not the same and has a lot more functions. Same for every test class.



-- 
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