ArnavBalyan commented on code in PR #9291:
URL: https://github.com/apache/paimon/pull/9291#discussion_r3802812102


##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/service/QueryFileMonitorTest.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.paimon.flink.service;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.flink.source.SimpleSourceSplit;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.Table;
+import org.apache.paimon.table.sink.BatchTableCommit;
+import org.apache.paimon.table.sink.BatchTableWrite;
+import org.apache.paimon.table.sink.BatchWriteBuilder;
+import org.apache.paimon.types.DataTypes;
+
+import org.apache.flink.api.common.eventtime.Watermark;
+import org.apache.flink.api.connector.source.ReaderOutput;
+import org.apache.flink.api.connector.source.SourceOutput;
+import org.apache.flink.api.connector.source.SourceReader;
+import org.apache.flink.core.io.InputStatus;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link QueryFileMonitor}. */
+public class QueryFileMonitorTest {
+
+    private static final long DISCOVERY_INTERVAL_MS = 3_000L;
+
+    @TempDir Path tempDir;
+
+    private Table table;
+
+    @BeforeEach
+    public void before() throws Exception {
+        Catalog catalog =
+                CatalogFactory.createCatalog(
+                        CatalogContext.create(new 
org.apache.paimon.fs.Path(tempDir.toUri())));
+        Schema schema =
+                Schema.newBuilder()
+                        .column("a", DataTypes.INT())
+                        .column("b", DataTypes.INT())
+                        .column("c", DataTypes.INT())
+                        .primaryKey("a")
+                        .option("bucket", "1")
+                        
.option(CoreOptions.CONTINUOUS_DISCOVERY_INTERVAL.key(), "3 s")
+                        .build();
+        Identifier identifier = Identifier.create("default", "t");
+        catalog.createDatabase("default", false);
+        catalog.createTable(identifier, schema, false);
+        this.table = catalog.getTable(identifier);
+    }
+
+    @Test
+    public void testPollWithoutNewFilesReportsNothingAvailable() throws 
Exception {
+        SourceReader<InternalRow, SimpleSourceSplit> reader =
+                new QueryFileMonitor(table).createReader(null);
+        try {
+            reader.start();
+            TestingReaderOutput<InternalRow> output = new 
TestingReaderOutput<>();
+
+            long start = System.currentTimeMillis();
+            InputStatus status = reader.pollNext(output);
+            long elapsed = System.currentTimeMillis() - start;
+
+            assertThat(status).isEqualTo(InputStatus.NOTHING_AVAILABLE);
+            assertThat(output.getEmittedRecords()).isEmpty();
+            // the poll must not block the mailbox thread for the discovery 
interval
+            assertThat(elapsed).isLessThan(DISCOVERY_INTERVAL_MS / 3);

Review Comment:
   nit: this sleep can introduce flakyness under heavy CI contention, we may 
want to manually control this



##########
paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/service/QueryFileMonitorTest.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * 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.paimon.flink.service;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.flink.source.SimpleSourceSplit;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.Table;
+import org.apache.paimon.table.sink.BatchTableCommit;
+import org.apache.paimon.table.sink.BatchTableWrite;
+import org.apache.paimon.table.sink.BatchWriteBuilder;
+import org.apache.paimon.types.DataTypes;
+
+import org.apache.flink.api.common.eventtime.Watermark;
+import org.apache.flink.api.connector.source.ReaderOutput;
+import org.apache.flink.api.connector.source.SourceOutput;
+import org.apache.flink.api.connector.source.SourceReader;
+import org.apache.flink.core.io.InputStatus;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link QueryFileMonitor}. */
+public class QueryFileMonitorTest {
+
+    private static final long DISCOVERY_INTERVAL_MS = 3_000L;
+
+    @TempDir Path tempDir;
+
+    private Table table;
+
+    @BeforeEach
+    public void before() throws Exception {
+        Catalog catalog =
+                CatalogFactory.createCatalog(
+                        CatalogContext.create(new 
org.apache.paimon.fs.Path(tempDir.toUri())));
+        Schema schema =
+                Schema.newBuilder()
+                        .column("a", DataTypes.INT())
+                        .column("b", DataTypes.INT())
+                        .column("c", DataTypes.INT())
+                        .primaryKey("a")
+                        .option("bucket", "1")
+                        
.option(CoreOptions.CONTINUOUS_DISCOVERY_INTERVAL.key(), "3 s")
+                        .build();
+        Identifier identifier = Identifier.create("default", "t");
+        catalog.createDatabase("default", false);
+        catalog.createTable(identifier, schema, false);
+        this.table = catalog.getTable(identifier);
+    }
+
+    @Test
+    public void testPollWithoutNewFilesReportsNothingAvailable() throws 
Exception {
+        SourceReader<InternalRow, SimpleSourceSplit> reader =
+                new QueryFileMonitor(table).createReader(null);
+        try {
+            reader.start();
+            TestingReaderOutput<InternalRow> output = new 
TestingReaderOutput<>();
+
+            long start = System.currentTimeMillis();
+            InputStatus status = reader.pollNext(output);
+            long elapsed = System.currentTimeMillis() - start;
+
+            assertThat(status).isEqualTo(InputStatus.NOTHING_AVAILABLE);
+            assertThat(output.getEmittedRecords()).isEmpty();
+            // the poll must not block the mailbox thread for the discovery 
interval
+            assertThat(elapsed).isLessThan(DISCOVERY_INTERVAL_MS / 3);

Review Comment:
   (non blocking)



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